| | |
| | | * information: "Portions Copyright [year] [name of copyright owner]". |
| | | * |
| | | * Copyright 2008-2010 Sun Microsystems, Inc. |
| | | * Portions Copyright 2015 ForgeRock AS. |
| | | * Portions Copyright 2015-2016 ForgeRock AS. |
| | | */ |
| | | package org.opends.guitools.controlpanel.ui; |
| | | |
| | |
| | | import org.opends.guitools.controlpanel.util.Utilities; |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | | |
| | | /** |
| | | * The dialog that is used to display progress in a task. |
| | | */ |
| | | /** The dialog that is used to display progress in a task. */ |
| | | public class ProgressDialog extends GenericDialog |
| | | { |
| | | private static final long serialVersionUID = -6462866257463062629L; |
| | |
| | | { |
| | | errorPrintStream.addListener(new PrintStreamListener() |
| | | { |
| | | @Override |
| | | public void newLine(final String msg) |
| | | { |
| | | SwingUtilities.invokeLater(new Runnable() |
| | | { |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public void run() |
| | | { |
| | | progressPanel.appendErrorLine(msg); |
| | |
| | | }); |
| | | outPrintStream.addListener(new PrintStreamListener() |
| | | { |
| | | @Override |
| | | public void newLine(final String msg) |
| | | { |
| | | /** {@inheritDoc} */ |
| | | SwingUtilities.invokeLater(new Runnable() |
| | | { |
| | | @Override |
| | | public void run() |
| | | { |
| | | progressPanel.appendOutputLine(msg); |
| | |
| | | progressPanel.appendHtml(text); |
| | | } |
| | | |
| | | /** |
| | | * Resets the contents of the 'Details' section of the dialog. |
| | | * |
| | | */ |
| | | /** Resets the contents of the 'Details' section of the dialog. */ |
| | | public void resetProgressLogs() |
| | | { |
| | | progressPanel.resetLogs(); |
| | |
| | | progressPanel.setSummary(text); |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public void setEnabledClose(boolean enable) |
| | | { |
| | | progressPanel.closeButton.setEnabled(enable); |
| | |
| | | progressPanel.closeWhenOverClicked(); |
| | | } |
| | | |
| | | /** |
| | | * The panel contained in the progress dialog. |
| | | * |
| | | */ |
| | | /** The panel contained in the progress dialog. */ |
| | | static class ProgressPanel extends StatusGenericPanel |
| | | { |
| | | private static final long serialVersionUID = -364496083928260306L; |
| | |
| | | |
| | | private boolean taskIsOver; |
| | | |
| | | /** |
| | | * Default constructor. |
| | | * |
| | | */ |
| | | /** Default constructor. */ |
| | | public ProgressPanel() |
| | | { |
| | | super(); |
| | | createLayout(); |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public LocalizableMessage getTitle() |
| | | { |
| | | return null; |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public boolean requiresScroll() |
| | | { |
| | | return false; |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public boolean requiresBorder() |
| | | { |
| | | return false; |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public boolean isDisposeOnClose() |
| | | { |
| | | return true; |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * Resets the contents of the logs (Details) section. |
| | | * |
| | | */ |
| | | /** Resets the contents of the logs (Details) section. */ |
| | | public void resetLogs() |
| | | { |
| | | logs.setText(INIT_TEXT); |
| | | } |
| | | |
| | | /** |
| | | * Creates the layout of the panel (but the contents are not populated |
| | | * here). |
| | | * |
| | | */ |
| | | /** Creates the layout of the panel (but the contents are not populated here). */ |
| | | private void createLayout() |
| | | { |
| | | GridBagConstraints gbc = new GridBagConstraints(); |
| | |
| | | updateVisibility(lastShowDetails); |
| | | details.addActionListener(new ActionListener() |
| | | { |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public void actionPerformed(ActionEvent ev) |
| | | { |
| | | lastShowDetails = details.isSelected(); |
| | |
| | | closeWhenOver.setOpaque(false); |
| | | closeWhenOver.addActionListener(new ActionListener() |
| | | { |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public void actionPerformed(ActionEvent ev) |
| | | { |
| | | closeWhenOverClicked(); |
| | |
| | | buttonsPanel.add(closeButton, gbc); |
| | | closeButton.addActionListener(new ActionListener() |
| | | { |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public void actionPerformed(ActionEvent ev) |
| | | { |
| | | closeClicked(); |
| | |
| | | { |
| | | final Runnable repaint = new Runnable() |
| | | { |
| | | @Override |
| | | public void run() |
| | | { |
| | | invalidate(); |
| | |
| | | } |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public GenericDialog.ButtonType getButtonType() |
| | | { |
| | | return GenericDialog.ButtonType.NO_BUTTON; |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public void configurationChanged(ConfigurationChangeEvent ev) |
| | | { |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public Component getPreferredFocusComponent() |
| | | { |
| | | return details; |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public void okClicked() |
| | | { |
| | | Utilities.getParentDialog(this).setVisible(false); |
| | |
| | | * Checks if the 'Close when over' check box is selected and if it is the |
| | | * case, closes the dialog after waiting for 2 seconds (so that the user |
| | | * can see the result, or cancel the automatic closing of the dialog). |
| | | * |
| | | */ |
| | | private void closeWhenOverClicked() |
| | | { |
| | |
| | | { |
| | | Thread t = new Thread(new Runnable() |
| | | { |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public void run() |
| | | { |
| | | try |
| | |
| | | Thread.sleep(2000); |
| | | SwingUtilities.invokeLater(new Runnable() |
| | | { |
| | | @Override |
| | | public void run() |
| | | { |
| | | if (closeWhenOver.isSelected() && taskIsOver) |