diff options
author | Tobias Schwarz | 2013-03-01 08:19:26 +0000 |
---|---|---|
committer | Tobias Schwarz | 2013-03-01 08:19:26 +0000 |
commit | adbeba130ca3d73ea99fd41a9b3aa524d69d4d9b (patch) | |
tree | a61bb2cabed950a74253453a147553849f1c8b89 | |
parent | ead8cb523c1a6fd41628277b82dc7cad9ca76df2 (diff) | |
download | org.eclipse.tcf-adbeba130ca3d73ea99fd41a9b3aa524d69d4d9b.tar.gz org.eclipse.tcf-adbeba130ca3d73ea99fd41a9b3aa524d69d4d9b.tar.xz org.eclipse.tcf-adbeba130ca3d73ea99fd41a9b3aa524d69d4d9b.zip |
Target Explorer: improve dialog settigs
3 files changed, 681 insertions, 672 deletions
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui.controls/src/org/eclipse/tcf/te/ui/controls/BaseControl.java b/target_explorer/plugins/org.eclipse.tcf.te.ui.controls/src/org/eclipse/tcf/te/ui/controls/BaseControl.java index a3d799298..54128aae2 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.ui.controls/src/org/eclipse/tcf/te/ui/controls/BaseControl.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.ui.controls/src/org/eclipse/tcf/te/ui/controls/BaseControl.java @@ -1,308 +1,308 @@ -/******************************************************************************* - * Copyright (c) 2011, 2012 Wind River Systems, Inc. and others. All rights reserved. - * This program and the accompanying materials are made available under the terms - * of the Eclipse Public License v1.0 which accompanies this distribution, and is - * available at http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Wind River Systems - initial API and implementation - *******************************************************************************/ -package org.eclipse.tcf.te.ui.controls; - -import org.eclipse.core.runtime.Assert; -import org.eclipse.core.runtime.PlatformObject; -import org.eclipse.jface.dialogs.IDialogSettings; -import org.eclipse.jface.dialogs.IMessageProvider; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.tcf.te.ui.jface.interfaces.IValidatable; - -/** - * Base implementation of a common UI control. - * <p> - * The control can be embedded into any UI container like dialogs, - * wizard pages or preference pages. - */ -public class BaseControl extends PlatformObject implements IValidatable { - - /** - * Reference to the parent control. - */ - private Composite parentControl; - - /** - * A message associated with the control. - */ - private String message = null; - - /** - * The message type of the associated message. - * @see IMessageProvider - */ - private int messageType = IMessageProvider.NONE; - - /** - * Flag to remember the controls enabled state - */ - private boolean enabled = true; - - /** - * Constructor. - */ - public BaseControl() { - super(); - } - - /** - * Returns if the <code>setupPanel(...)</code> method has been called at least once with - * a non-null parent control. - * - * @return <code>true</code> if the associated parent control is not <code>null</code>, <code>false</code> otherwise. - */ - public final boolean isControlCreated() { - return (parentControl != null); - } - - /** - * Returns the parent control of the control. - * - * @return The parent control or <code>null</code>. - */ - public final Composite getParentControl() { - return parentControl; - } - - /** - * Cleanup all resources the control might have been created. - */ - public void dispose() { - parentControl = null; - } - - /** - * Creates the controls UI elements. - * - * @param parent The parent control. Must not be <code>null</code>! - */ - public void setupPanel(Composite parent) { - Assert.isNotNull(parent); - parentControl = parent; - } - - /** - * Enables or disables all UI elements belonging to this control. The - * control remembers the last set enabled state to allow easy enabled checks. - * - * @param enabled <code>True</code> to enable the UI elements, <code>false</code> otherwise. - */ - public void setEnabled(boolean enabled) { - this.enabled = enabled; - } - - /** - * Returns the control is enabled or not. - */ - public final boolean isEnabled() { - return enabled; - } - - /* (non-Javadoc) - * @see org.eclipse.tcf.te.ui.interfaces.validator.IValidatable#isValid() - */ - @Override - public boolean isValid() { - setMessage(null, IMessageProvider.NONE); - return true; - } - - /** - * Validates the given subcontrol and bitwise "AND" the subcontrols valid - * state to the passed in current valid state. If the subcontrol validation - * results into a message which has a higher message type than the currently - * set message, the message from the subcontrol is applied to the control itself. - * <p> - * <b>Note:</b> If the given subcontrol is <code>null</code>, the current validation - * state is returned unchanged. - * - * @param subControl The subcontrol instance or <code>null</code>. - * @param currentValidationState The current control validation state before the subcontrol is validated. - * - * @return The new controls validation state after the subcontrol has been validated. - */ - protected final boolean isSubControlValid(BaseControl subControl, boolean currentValidationState) { - if (subControl == null) return currentValidationState; - - // Validate the subcontrol and bitwise "AND" the result to the current validation state - currentValidationState &= subControl.isValid(); - // Check if the subcontrol has set a message which has a higher message - // type than the currently set message. - if (subControl.getMessageType() > getMessageType()) { - // Apply the message from the subcontrol to the control - setMessage(subControl.getMessage(), subControl.getMessageType()); - } - - // Returns the resulting validation state. - return currentValidationState; - } - - /* (non-Javadoc) - * @see org.eclipse.jface.dialogs.IMessageProvider#getMessage() - */ - @Override - public final String getMessage() { - return message; - } - - /* (non-Javadoc) - * @see org.eclipse.jface.dialogs.IMessageProvider#getMessageType() - */ - @Override - public final int getMessageType() { - return messageType; - } - - /** - * Set the message and the message type this control wants to display in - * the outer control or panel. - * - * @param message The message from this control. - * @param messageType The type o the message (NONE, INFORMATION, WARNING, ERROR). - */ - protected final void setMessage(String message, int messageType) { - // Check if we should apply the default message instead. - if (message == null && getDefaultMessage() != null) { - message = getDefaultMessage(); - messageType = getDefaultMessageType(); - } - // Set the message and message type - this.message = message; - this.messageType = messageType; - } - - /** - * Returns the controls default message or <code>null</code> if none. - * - * @return The controls default message or <code>null</code>. - */ - public String getDefaultMessage() { - return null; - } - - /** - * Returns the controls default message type or {@link IMessageProvider#NONE} if none. - * - * @return The controls default message type. - */ - public int getDefaultMessageType() { - return IMessageProvider.INFORMATION; - } - - /** - * Returns the correctly prefixed dialog settings slot id. In case the given id - * suffix is <code>null</code> or empty, <code>id</code> is returned as is. - * - * @param settingsSlotId The dialog settings slot id to prefix. - * @param prefix The prefix. - * @return The correctly prefixed dialog settings slot id. - */ - public final String prefixDialogSettingsSlotId(String settingsSlotId, String prefix) { - if (settingsSlotId != null && prefix != null && prefix.trim().length() > 0) { - settingsSlotId = prefix + "." + settingsSlotId; //$NON-NLS-1$ - } - return settingsSlotId; - } - - /** - * Returns the parent section for the control dialog settings. The default implementation - * returns the passed in dialog settings instance unmodified. Overwrite to create additional - * subsections within the given dialog settings instance. - * - * @param settings The dialog settings instance. Must not be <code>null</code>. - * - * @return The parent section for the control dialog settings. Must never be <code>null</code>. - */ - protected IDialogSettings doGetParentSection(IDialogSettings settings) { - Assert.isNotNull(settings); - return settings; - } - - /** - * Restore the widget values from the dialog settings store to recreate the control history. - * <p> - * <b>Note:</b> - * The control is saving the widget values into a section equal to the class name {@link Class#getName()}. - * After the sections has been created, the method calls <code>doRestoreWidgetValues</code> for restoring - * the single properties from the dialog settings. Subclasses may override <code>doRestoreWidgetValues</code> - * only to deal with the single properties only or <code>restoreWidgetValues</code> when to override the - * creation of the subsections. - * - * @param settings The dialog settings object instance to restore the widget values from. Must not be <code>null</code>! - * @param idPrefix The prefix to use for every dialog settings slot keys. If <code>null</code>, the dialog settings slot keys are not to prefix. - */ - public final void restoreWidgetValues(IDialogSettings settings, String idPrefix) { - Assert.isNotNull(settings); - - // Get the parent section for the control dialog settings. - IDialogSettings parentSection = doGetParentSection(settings); - Assert.isNotNull(parentSection); - - // Store the settings of the control within it's own section. - IDialogSettings section = parentSection.getSection(this.getClass().getName()); - if (section == null) { - section = parentSection.addNewSection(this.getClass().getName()); - } - - // now, call the hook for actually reading the single properties from the dialog settings. - doRestoreWidgetValues(section, idPrefix); - } - - /** - * Hook to restore the widget values finally plain from the given dialog settings. This method should - * not fragment the given dialog settings any further. - * - * @param settings The dialog settings to restore the widget values from. Must not be <code>null</code>! - * @param idPrefix The prefix to use for every dialog settings slot keys. If <code>null</code>, the dialog settings slot keys are not to prefix. - */ - public void doRestoreWidgetValues(IDialogSettings settings, String idPrefix) { - Assert.isNotNull(settings); - } - - /** - * Saves the widget values to the dialog settings store for remembering the history. The control might - * be embedded within multiple pages multiple times handling different properties. Because the single - * controls should not mix up the history, we create subsections within the given dialog settings if - * they do not already exist. After the sections has been created, the method calls <code>doSaveWidgetValues</code> - * for saving the single properties to the dialog settings. Subclasses may override <code>doSaveWidgetValues</code> - * only to deal with the single properties only or <code>saveWidgetValues</code> when to override the - * creation of the subsections. - * - * @param settings The dialog settings object instance to save the widget values to. Must not be <code>null</code>! - * @param idPrefix The prefix to use for every dialog settings slot keys. If <code>null</code>, the dialog settings slot keys are not to prefix. - */ - public final void saveWidgetValues(IDialogSettings settings, String idPrefix) { - Assert.isNotNull(settings); - - // Get the parent section for the control dialog settings. - IDialogSettings parentSection = doGetParentSection(settings); - Assert.isNotNull(parentSection); - - // Store the settings of the control within it's own section. - IDialogSettings section = parentSection.getSection(this.getClass().getName()); - if (section == null) { - section = parentSection.addNewSection(this.getClass().getName()); - } - - // now, call the hook for actually writing the single properties to the dialog settings. - doSaveWidgetValues(section, idPrefix); - } - - /** - * Hook to save the widget values finally plain to the given dialog settings. This method should - * not fragment the given dialog settings any further. - * - * @param settings The dialog settings to save the widget values to. Must not be <code>null</code>! - * @param idPrefix The prefix to use for every dialog settings slot keys. If <code>null</code>, the dialog settings slot keys are not to prefix. - */ - public void doSaveWidgetValues(IDialogSettings settings, String idPrefix) { - Assert.isNotNull(settings); - } -} +/*******************************************************************************
+ * Copyright (c) 2011, 2012 Wind River Systems, Inc. and others. All rights reserved.
+ * This program and the accompanying materials are made available under the terms
+ * of the Eclipse Public License v1.0 which accompanies this distribution, and is
+ * available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Wind River Systems - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.tcf.te.ui.controls;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.core.runtime.PlatformObject;
+import org.eclipse.jface.dialogs.IDialogSettings;
+import org.eclipse.jface.dialogs.IMessageProvider;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.tcf.te.ui.jface.interfaces.IValidatable;
+
+/**
+ * Base implementation of a common UI control.
+ * <p>
+ * The control can be embedded into any UI container like dialogs,
+ * wizard pages or preference pages.
+ */
+public class BaseControl extends PlatformObject implements IValidatable {
+
+ /**
+ * Reference to the parent control.
+ */
+ private Composite parentControl;
+
+ /**
+ * A message associated with the control.
+ */
+ private String message = null;
+
+ /**
+ * The message type of the associated message.
+ * @see IMessageProvider
+ */
+ private int messageType = IMessageProvider.NONE;
+
+ /**
+ * Flag to remember the controls enabled state
+ */
+ private boolean enabled = true;
+
+ /**
+ * Constructor.
+ */
+ public BaseControl() {
+ super();
+ }
+
+ /**
+ * Returns if the <code>setupPanel(...)</code> method has been called at least once with
+ * a non-null parent control.
+ *
+ * @return <code>true</code> if the associated parent control is not <code>null</code>, <code>false</code> otherwise.
+ */
+ public final boolean isControlCreated() {
+ return (parentControl != null);
+ }
+
+ /**
+ * Returns the parent control of the control.
+ *
+ * @return The parent control or <code>null</code>.
+ */
+ public final Composite getParentControl() {
+ return parentControl;
+ }
+
+ /**
+ * Cleanup all resources the control might have been created.
+ */
+ public void dispose() {
+ parentControl = null;
+ }
+
+ /**
+ * Creates the controls UI elements.
+ *
+ * @param parent The parent control. Must not be <code>null</code>!
+ */
+ public void setupPanel(Composite parent) {
+ Assert.isNotNull(parent);
+ parentControl = parent;
+ }
+
+ /**
+ * Enables or disables all UI elements belonging to this control. The
+ * control remembers the last set enabled state to allow easy enabled checks.
+ *
+ * @param enabled <code>True</code> to enable the UI elements, <code>false</code> otherwise.
+ */
+ public void setEnabled(boolean enabled) {
+ this.enabled = enabled;
+ }
+
+ /**
+ * Returns the control is enabled or not.
+ */
+ public final boolean isEnabled() {
+ return enabled;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.ui.interfaces.validator.IValidatable#isValid()
+ */
+ @Override
+ public boolean isValid() {
+ setMessage(null, IMessageProvider.NONE);
+ return true;
+ }
+
+ /**
+ * Validates the given subcontrol and bitwise "AND" the subcontrols valid
+ * state to the passed in current valid state. If the subcontrol validation
+ * results into a message which has a higher message type than the currently
+ * set message, the message from the subcontrol is applied to the control itself.
+ * <p>
+ * <b>Note:</b> If the given subcontrol is <code>null</code>, the current validation
+ * state is returned unchanged.
+ *
+ * @param subControl The subcontrol instance or <code>null</code>.
+ * @param currentValidationState The current control validation state before the subcontrol is validated.
+ *
+ * @return The new controls validation state after the subcontrol has been validated.
+ */
+ protected final boolean isSubControlValid(BaseControl subControl, boolean currentValidationState) {
+ if (subControl == null) return currentValidationState;
+
+ // Validate the subcontrol and bitwise "AND" the result to the current validation state
+ currentValidationState &= subControl.isValid();
+ // Check if the subcontrol has set a message which has a higher message
+ // type than the currently set message.
+ if (subControl.getMessageType() > getMessageType()) {
+ // Apply the message from the subcontrol to the control
+ setMessage(subControl.getMessage(), subControl.getMessageType());
+ }
+
+ // Returns the resulting validation state.
+ return currentValidationState;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.dialogs.IMessageProvider#getMessage()
+ */
+ @Override
+ public final String getMessage() {
+ return message;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.dialogs.IMessageProvider#getMessageType()
+ */
+ @Override
+ public final int getMessageType() {
+ return messageType;
+ }
+
+ /**
+ * Set the message and the message type this control wants to display in
+ * the outer control or panel.
+ *
+ * @param message The message from this control.
+ * @param messageType The type o the message (NONE, INFORMATION, WARNING, ERROR).
+ */
+ protected final void setMessage(String message, int messageType) {
+ // Check if we should apply the default message instead.
+ if (message == null && getDefaultMessage() != null) {
+ message = getDefaultMessage();
+ messageType = getDefaultMessageType();
+ }
+ // Set the message and message type
+ this.message = message;
+ this.messageType = messageType;
+ }
+
+ /**
+ * Returns the controls default message or <code>null</code> if none.
+ *
+ * @return The controls default message or <code>null</code>.
+ */
+ public String getDefaultMessage() {
+ return null;
+ }
+
+ /**
+ * Returns the controls default message type or {@link IMessageProvider#NONE} if none.
+ *
+ * @return The controls default message type.
+ */
+ public int getDefaultMessageType() {
+ return IMessageProvider.INFORMATION;
+ }
+
+ /**
+ * Returns the correctly prefixed dialog settings slot id. In case the given id
+ * suffix is <code>null</code> or empty, <code>id</code> is returned as is.
+ *
+ * @param settingsSlotId The dialog settings slot id to prefix.
+ * @param prefix The prefix.
+ * @return The correctly prefixed dialog settings slot id.
+ */
+ public final String prefixDialogSettingsSlotId(String settingsSlotId, String prefix) {
+ if (settingsSlotId != null && prefix != null && prefix.trim().length() > 0) {
+ settingsSlotId = prefix + "." + settingsSlotId; //$NON-NLS-1$
+ }
+ return settingsSlotId;
+ }
+
+ /**
+ * Returns the parent section for the control dialog settings. The default implementation
+ * returns the passed in dialog settings instance unmodified. Overwrite to create additional
+ * subsections within the given dialog settings instance.
+ *
+ * @param settings The dialog settings instance. Must not be <code>null</code>.
+ *
+ * @return The parent section for the control dialog settings. Must never be <code>null</code>.
+ */
+ protected IDialogSettings doGetParentSection(IDialogSettings settings) {
+ Assert.isNotNull(settings);
+ return settings;
+ }
+
+ /**
+ * Restore the widget values from the dialog settings store to recreate the control history.
+ * <p>
+ * <b>Note:</b>
+ * The control is saving the widget values into a section equal to the class name {@link Class#getName()}.
+ * After the sections has been created, the method calls <code>doRestoreWidgetValues</code> for restoring
+ * the single properties from the dialog settings. Subclasses may override <code>doRestoreWidgetValues</code>
+ * only to deal with the single properties only or <code>restoreWidgetValues</code> when to override the
+ * creation of the subsections.
+ *
+ * @param settings The dialog settings object instance to restore the widget values from. Must not be <code>null</code>!
+ * @param idPrefix The prefix to use for every dialog settings slot keys. If <code>null</code>, the dialog settings slot keys are not to prefix.
+ */
+ public final void restoreWidgetValues(IDialogSettings settings, String idPrefix) {
+ Assert.isNotNull(settings);
+
+ // Get the parent section for the control dialog settings.
+ IDialogSettings parentSection = doGetParentSection(settings);
+ Assert.isNotNull(parentSection);
+
+ // Store the settings of the control within it's own section.
+ IDialogSettings section = parentSection.getSection(this.getClass().getSimpleName());
+ if (section == null) {
+ section = parentSection.addNewSection(this.getClass().getSimpleName());
+ }
+
+ // now, call the hook for actually reading the single properties from the dialog settings.
+ doRestoreWidgetValues(section, idPrefix);
+ }
+
+ /**
+ * Hook to restore the widget values finally plain from the given dialog settings. This method should
+ * not fragment the given dialog settings any further.
+ *
+ * @param settings The dialog settings to restore the widget values from. Must not be <code>null</code>!
+ * @param idPrefix The prefix to use for every dialog settings slot keys. If <code>null</code>, the dialog settings slot keys are not to prefix.
+ */
+ public void doRestoreWidgetValues(IDialogSettings settings, String idPrefix) {
+ Assert.isNotNull(settings);
+ }
+
+ /**
+ * Saves the widget values to the dialog settings store for remembering the history. The control might
+ * be embedded within multiple pages multiple times handling different properties. Because the single
+ * controls should not mix up the history, we create subsections within the given dialog settings if
+ * they do not already exist. After the sections has been created, the method calls <code>doSaveWidgetValues</code>
+ * for saving the single properties to the dialog settings. Subclasses may override <code>doSaveWidgetValues</code>
+ * only to deal with the single properties only or <code>saveWidgetValues</code> when to override the
+ * creation of the subsections.
+ *
+ * @param settings The dialog settings object instance to save the widget values to. Must not be <code>null</code>!
+ * @param idPrefix The prefix to use for every dialog settings slot keys. If <code>null</code>, the dialog settings slot keys are not to prefix.
+ */
+ public final void saveWidgetValues(IDialogSettings settings, String idPrefix) {
+ Assert.isNotNull(settings);
+
+ // Get the parent section for the control dialog settings.
+ IDialogSettings parentSection = doGetParentSection(settings);
+ Assert.isNotNull(parentSection);
+
+ // Store the settings of the control within it's own section.
+ IDialogSettings section = parentSection.getSection(this.getClass().getSimpleName());
+ if (section == null) {
+ section = parentSection.addNewSection(this.getClass().getSimpleName());
+ }
+
+ // now, call the hook for actually writing the single properties to the dialog settings.
+ doSaveWidgetValues(section, idPrefix);
+ }
+
+ /**
+ * Hook to save the widget values finally plain to the given dialog settings. This method should
+ * not fragment the given dialog settings any further.
+ *
+ * @param settings The dialog settings to save the widget values to. Must not be <code>null</code>!
+ * @param idPrefix The prefix to use for every dialog settings slot keys. If <code>null</code>, the dialog settings slot keys are not to prefix.
+ */
+ public void doSaveWidgetValues(IDialogSettings settings, String idPrefix) {
+ Assert.isNotNull(settings);
+ }
+}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui.controls/src/org/eclipse/tcf/te/ui/controls/BaseWizardConfigurationPanelControl.java b/target_explorer/plugins/org.eclipse.tcf.te.ui.controls/src/org/eclipse/tcf/te/ui/controls/BaseWizardConfigurationPanelControl.java index c1e5310fc..943db816a 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.ui.controls/src/org/eclipse/tcf/te/ui/controls/BaseWizardConfigurationPanelControl.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.ui.controls/src/org/eclipse/tcf/te/ui/controls/BaseWizardConfigurationPanelControl.java @@ -1,244 +1,253 @@ -/******************************************************************************* - * Copyright (c) 2011 Wind River Systems, Inc. and others. All rights reserved. - * This program and the accompanying materials are made available under the terms - * of the Eclipse Public License v1.0 which accompanies this distribution, and is - * available at http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Wind River Systems - initial API and implementation - *******************************************************************************/ -package org.eclipse.tcf.te.ui.controls; - -import java.util.Hashtable; -import java.util.Map; - -import org.eclipse.core.runtime.Assert; -import org.eclipse.jface.dialogs.IDialogPage; -import org.eclipse.jface.dialogs.IDialogSettings; -import org.eclipse.swt.SWT; -import org.eclipse.swt.custom.StackLayout; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Group; -import org.eclipse.tcf.te.ui.controls.interfaces.IWizardConfigurationPanel; -import org.eclipse.ui.forms.widgets.FormToolkit; - -/** - * Base control to deal with wizard or property page controls - * which should share the same UI space. - */ -public class BaseWizardConfigurationPanelControl extends BaseDialogPageControl { - private final Map<String, IWizardConfigurationPanel> configurationPanels = new Hashtable<String, IWizardConfigurationPanel>(); - - private boolean isGroup; - - private Composite panel; - private StackLayout panelLayout; - - private IWizardConfigurationPanel activeConfigurationPanel = null; - - /** - * Constructor. - * - * @param parentPage The parent dialog page this control is embedded in. - * Might be <code>null</code> if the control is not associated with a page. - */ - public BaseWizardConfigurationPanelControl(IDialogPage parentPage) { - super(parentPage); - clear(); - setPanelIsGroup(false); - } - - /** - * Sets if or if not the controls panel is a <code>Group</code>. - * - * @param isGroup <code>True</code> if the controls panel is a group, <code>false</code> otherwise. - */ - public void setPanelIsGroup(boolean isGroup) { - this.isGroup = isGroup; - } - - /** - * Returns if or if not the controls panel is a <code>Group</code>. - * - * @return <code>True</code> if the controls panel is a group, <code>false</code> otherwise. - */ - public boolean isPanelIsGroup() { - return isGroup; - } - - /** - * Returns the controls panel. - * - * @return The controls panel or <code>null</code>. - */ - public Composite getPanel() { - return panel; - } - - /** - * Returns the label text to set for the group (if the panel is a group). - * - * @return The label text to apply or <code>null</code>. - */ - public String getGroupLabel() { - return null; - } - - /** - * To be called from the embedding control to setup the controls UI elements. - * - * @param parent The parent control. Must not be <code>null</code>! - * @param toolkit The form toolkit. Must not be <code>null</code>. - */ - public void setupPanel(Composite parent, String[] configurationPanelKeys, FormToolkit toolkit) { - Assert.isNotNull(parent); - Assert.isNotNull(toolkit); - - setFormToolkit(toolkit); - - if (isPanelIsGroup()) { - panel = new Group(parent, SWT.NONE); - if (getGroupLabel() != null) ((Group)panel).setText(getGroupLabel()); - } else { - panel = new Composite(parent, SWT.NONE); - } - Assert.isNotNull(panel); - panel.setFont(parent.getFont()); - panel.setBackground(parent.getBackground()); - - panelLayout = new StackLayout(); - panel.setLayout(panelLayout); - - setupConfigurationPanels(panel, configurationPanelKeys, toolkit); - } - - /** - * Removes all configuration panels. - */ - public void clear() { - configurationPanels.clear(); - } - - /** - * Returns a unsorted list of all registered wizard configuration - * panel id's. - * - * @return A list of registered wizard configuration panel id's. - */ - public String[] getConfigurationPanelIds() { - return configurationPanels.keySet().toArray(new String[configurationPanels.keySet().size()]); - } - - /** - * Returns the wizard configuration panel instance registered for the given configuration panel key. - * - * @param key The key to get the wizard configuration panel for. Must not be <code>null</code>! - * @return The wizard configuration panel instance or <code>null</code> if the key is unknown. - */ - public IWizardConfigurationPanel getConfigurationPanel(String key) { - if (key == null) return null; - return configurationPanels.get(key); - } - - /** - * Adds the given wizard configuration panel under the given configuration panel key to the - * list of known panels. If the given configuration panel is <code>null</code>, any configuration - * panel stored under the given key is removed from the list of known panels. - * - * @param key The key to get the wizard configuration panel for. Must not be <code>null</code>! - * @param panel The wizard configuration panel instance or <code>null</code>. - */ - public void addConfigurationPanel(String key, IWizardConfigurationPanel panel) { - if (key == null) return; - if (panel != null) { - configurationPanels.put(key, panel); - } else { - configurationPanels.remove(key); - } - } - - /** - * Setup the wizard configuration panels for being presented to the user. This method is called by the - * controls <code>doSetupPanel(...)</code> and initialize all possible wizard configuration panels to show. - * The default implementation iterates over the given list of configuration panel keys and calls - * <code>setupPanel(...)</code> for each of them. - * - * @param parent The parent composite to use for the wizard configuration panels. Must not be <code>null</code>! - * @param configurationPanelKeys The list of configuration panels to initialize. Might be <code>null</code> or empty! - * @param toolkit The form toolkit. Must not be <code>null</code>. - */ - public void setupConfigurationPanels(Composite parent, String[] configurationPanelKeys, FormToolkit toolkit) { - Assert.isNotNull(parent); - Assert.isNotNull(toolkit); - - if (configurationPanelKeys != null) { - for (int i = 0; i < configurationPanelKeys.length; i++) { - IWizardConfigurationPanel configPanel = getConfigurationPanel(configurationPanelKeys[i]); - if (configPanel != null) configPanel.setupPanel(parent, toolkit); - } - } - } - - /** - * Make the wizard configuration panel registered under the given configuration panel key the - * most top configuration panel. If no configuration panel is registered under the given key, - * nothing will happen. - * - * @param key The key to get the wizard configuration panel for. Must not be <code>null</code>! - */ - public void showConfigurationPanel(String key) { - if (key == null) return; - - IWizardConfigurationPanel configPanel = getConfigurationPanel(key); - if (configPanel != null && configPanel.getControl() != null) { - activeConfigurationPanel = configPanel; - panelLayout.topControl = configPanel.getControl(); - panel.layout(); - } - } - - /** - * Returns the currently active configuration panel. - * - * @return The active configuration panel or <code>null</code>. - */ - public IWizardConfigurationPanel getActiveConfigurationPanel() { - return activeConfigurationPanel; - } - - /* (non-Javadoc) - * @see org.eclipse.tcf.te.ui.controls.BaseControl#doSaveWidgetValues(org.eclipse.jface.dialogs.IDialogSettings, java.lang.String) - */ - @Override - public void doSaveWidgetValues(IDialogSettings settings, String idPrefix) { - super.doSaveWidgetValues(settings, idPrefix); - if (settings != null) { - for (String key : configurationPanels.keySet()) { - IWizardConfigurationPanel configPanel = getConfigurationPanel(key); - if (configPanel != null) { - IDialogSettings configPanelSettings = settings.getSection(key); - if (configPanelSettings == null) configPanelSettings = settings.addNewSection(key); - configPanel.doSaveWidgetValues(configPanelSettings, idPrefix); - } - } - } - } - - /* (non-Javadoc) - * @see org.eclipse.tcf.te.ui.controls.BaseControl#doRestoreWidgetValues(org.eclipse.jface.dialogs.IDialogSettings, java.lang.String) - */ - @Override - public void doRestoreWidgetValues(IDialogSettings settings, String idPrefix) { - super.doRestoreWidgetValues(settings, idPrefix); - if (settings != null) { - for (String key : configurationPanels.keySet()) { - IWizardConfigurationPanel configPanel = getConfigurationPanel(key); - if (configPanel != null) { - IDialogSettings configPanelSettings = settings.getSection(key); - if (configPanelSettings == null) configPanelSettings = settings.addNewSection(key); - configPanel.doRestoreWidgetValues(configPanelSettings, idPrefix); - } - } - } - } -} +/*******************************************************************************
+ * Copyright (c) 2011 Wind River Systems, Inc. and others. All rights reserved.
+ * This program and the accompanying materials are made available under the terms
+ * of the Eclipse Public License v1.0 which accompanies this distribution, and is
+ * available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Wind River Systems - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.tcf.te.ui.controls;
+
+import java.util.Hashtable;
+import java.util.Map;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.jface.dialogs.IDialogPage;
+import org.eclipse.jface.dialogs.IDialogSettings;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.StackLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.tcf.te.ui.controls.interfaces.IWizardConfigurationPanel;
+import org.eclipse.ui.forms.widgets.FormToolkit;
+
+/**
+ * Base control to deal with wizard or property page controls
+ * which should share the same UI space.
+ */
+public class BaseWizardConfigurationPanelControl extends BaseDialogPageControl {
+ private final Map<String, IWizardConfigurationPanel> configurationPanels = new Hashtable<String, IWizardConfigurationPanel>();
+
+ private boolean isGroup;
+
+ private Composite panel;
+ private StackLayout panelLayout;
+
+ private String activeConfigurationPanelKey = null;
+ private IWizardConfigurationPanel activeConfigurationPanel = null;
+
+ /**
+ * Constructor.
+ *
+ * @param parentPage The parent dialog page this control is embedded in.
+ * Might be <code>null</code> if the control is not associated with a page.
+ */
+ public BaseWizardConfigurationPanelControl(IDialogPage parentPage) {
+ super(parentPage);
+ clear();
+ setPanelIsGroup(false);
+ }
+
+ /**
+ * Sets if or if not the controls panel is a <code>Group</code>.
+ *
+ * @param isGroup <code>True</code> if the controls panel is a group, <code>false</code> otherwise.
+ */
+ public void setPanelIsGroup(boolean isGroup) {
+ this.isGroup = isGroup;
+ }
+
+ /**
+ * Returns if or if not the controls panel is a <code>Group</code>.
+ *
+ * @return <code>True</code> if the controls panel is a group, <code>false</code> otherwise.
+ */
+ public boolean isPanelIsGroup() {
+ return isGroup;
+ }
+
+ /**
+ * Returns the controls panel.
+ *
+ * @return The controls panel or <code>null</code>.
+ */
+ public Composite getPanel() {
+ return panel;
+ }
+
+ /**
+ * Returns the label text to set for the group (if the panel is a group).
+ *
+ * @return The label text to apply or <code>null</code>.
+ */
+ public String getGroupLabel() {
+ return null;
+ }
+
+ /**
+ * To be called from the embedding control to setup the controls UI elements.
+ *
+ * @param parent The parent control. Must not be <code>null</code>!
+ * @param toolkit The form toolkit. Must not be <code>null</code>.
+ */
+ public void setupPanel(Composite parent, String[] configurationPanelKeys, FormToolkit toolkit) {
+ Assert.isNotNull(parent);
+ Assert.isNotNull(toolkit);
+
+ setFormToolkit(toolkit);
+
+ if (isPanelIsGroup()) {
+ panel = new Group(parent, SWT.NONE);
+ if (getGroupLabel() != null) ((Group)panel).setText(getGroupLabel());
+ } else {
+ panel = new Composite(parent, SWT.NONE);
+ }
+ Assert.isNotNull(panel);
+ panel.setFont(parent.getFont());
+ panel.setBackground(parent.getBackground());
+
+ panelLayout = new StackLayout();
+ panel.setLayout(panelLayout);
+
+ setupConfigurationPanels(panel, configurationPanelKeys, toolkit);
+ }
+
+ /**
+ * Removes all configuration panels.
+ */
+ public void clear() {
+ configurationPanels.clear();
+ }
+
+ /**
+ * Returns a unsorted list of all registered wizard configuration
+ * panel id's.
+ *
+ * @return A list of registered wizard configuration panel id's.
+ */
+ public String[] getConfigurationPanelIds() {
+ return configurationPanels.keySet().toArray(new String[configurationPanels.keySet().size()]);
+ }
+
+ /**
+ * Returns the wizard configuration panel instance registered for the given configuration panel key.
+ *
+ * @param key The key to get the wizard configuration panel for. Must not be <code>null</code>!
+ * @return The wizard configuration panel instance or <code>null</code> if the key is unknown.
+ */
+ public IWizardConfigurationPanel getConfigurationPanel(String key) {
+ if (key == null) return null;
+ return configurationPanels.get(key);
+ }
+
+ /**
+ * Adds the given wizard configuration panel under the given configuration panel key to the
+ * list of known panels. If the given configuration panel is <code>null</code>, any configuration
+ * panel stored under the given key is removed from the list of known panels.
+ *
+ * @param key The key to get the wizard configuration panel for. Must not be <code>null</code>!
+ * @param panel The wizard configuration panel instance or <code>null</code>.
+ */
+ public void addConfigurationPanel(String key, IWizardConfigurationPanel panel) {
+ if (key == null) return;
+ if (panel != null) {
+ configurationPanels.put(key, panel);
+ } else {
+ configurationPanels.remove(key);
+ }
+ }
+
+ /**
+ * Setup the wizard configuration panels for being presented to the user. This method is called by the
+ * controls <code>doSetupPanel(...)</code> and initialize all possible wizard configuration panels to show.
+ * The default implementation iterates over the given list of configuration panel keys and calls
+ * <code>setupPanel(...)</code> for each of them.
+ *
+ * @param parent The parent composite to use for the wizard configuration panels. Must not be <code>null</code>!
+ * @param configurationPanelKeys The list of configuration panels to initialize. Might be <code>null</code> or empty!
+ * @param toolkit The form toolkit. Must not be <code>null</code>.
+ */
+ public void setupConfigurationPanels(Composite parent, String[] configurationPanelKeys, FormToolkit toolkit) {
+ Assert.isNotNull(parent);
+ Assert.isNotNull(toolkit);
+
+ if (configurationPanelKeys != null) {
+ for (int i = 0; i < configurationPanelKeys.length; i++) {
+ IWizardConfigurationPanel configPanel = getConfigurationPanel(configurationPanelKeys[i]);
+ if (configPanel != null) configPanel.setupPanel(parent, toolkit);
+ }
+ }
+ }
+
+ /**
+ * Make the wizard configuration panel registered under the given configuration panel key the
+ * most top configuration panel. If no configuration panel is registered under the given key,
+ * nothing will happen.
+ *
+ * @param key The key to get the wizard configuration panel for. Must not be <code>null</code>!
+ */
+ public void showConfigurationPanel(String key) {
+ if (key == null) return;
+
+ IWizardConfigurationPanel configPanel = getConfigurationPanel(key);
+ if (configPanel != null && configPanel.getControl() != null) {
+ activeConfigurationPanel = configPanel;
+ activeConfigurationPanelKey = key;
+ panelLayout.topControl = configPanel.getControl();
+ panel.layout();
+ }
+ }
+
+ /**
+ * Returns the currently active configuration panel.
+ *
+ * @return The active configuration panel or <code>null</code>.
+ */
+ public IWizardConfigurationPanel getActiveConfigurationPanel() {
+ return activeConfigurationPanel;
+ }
+
+ /**
+ * Returns the currently active configuration panel key.
+ *
+ * @return The active configuration panel key or <code>null</code>.
+ */
+ public String getActiveConfigurationPanelKey() {
+ return activeConfigurationPanelKey;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.ui.controls.BaseControl#doSaveWidgetValues(org.eclipse.jface.dialogs.IDialogSettings, java.lang.String)
+ */
+ @Override
+ public void doSaveWidgetValues(IDialogSettings settings, String idPrefix) {
+ super.doSaveWidgetValues(settings, idPrefix);
+ if (settings != null) {
+ IWizardConfigurationPanel configPanel = getActiveConfigurationPanel();
+ if (configPanel != null) {
+ IDialogSettings configPanelSettings = settings.getSection(activeConfigurationPanelKey);
+ if (configPanelSettings == null) configPanelSettings = settings.addNewSection(activeConfigurationPanelKey);
+ configPanel.doSaveWidgetValues(configPanelSettings, idPrefix);
+ }
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.ui.controls.BaseControl#doRestoreWidgetValues(org.eclipse.jface.dialogs.IDialogSettings, java.lang.String)
+ */
+ @Override
+ public void doRestoreWidgetValues(IDialogSettings settings, String idPrefix) {
+ super.doRestoreWidgetValues(settings, idPrefix);
+ if (settings != null) {
+ for (String key : configurationPanels.keySet()) {
+ IWizardConfigurationPanel configPanel = getConfigurationPanel(key);
+ if (configPanel != null) {
+ IDialogSettings configPanelSettings = settings.getSection(key);
+ if (configPanelSettings == null) configPanelSettings = settings.addNewSection(key);
+ configPanel.doRestoreWidgetValues(configPanelSettings, idPrefix);
+ }
+ }
+ }
+ }
+}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/wizards/AbstractWizard.java b/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/wizards/AbstractWizard.java index 404eb9289..07add9061 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/wizards/AbstractWizard.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/wizards/AbstractWizard.java @@ -1,120 +1,120 @@ -/******************************************************************************* - * Copyright (c) 2011 Wind River Systems, Inc. and others. All rights reserved. - * This program and the accompanying materials are made available under the terms - * of the Eclipse Public License v1.0 which accompanies this distribution, and is - * available at http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Wind River Systems - initial API and implementation - *******************************************************************************/ -package org.eclipse.tcf.te.ui.wizards; - -import org.eclipse.jface.dialogs.IDialogSettings; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.wizard.Wizard; -import org.eclipse.tcf.te.ui.activator.UIPlugin; -import org.eclipse.ui.IWorkbench; -import org.eclipse.ui.IWorkbenchWizard; - -/** - * An abstract wizard implementation. - * <p> - * This wizard implementation is adding dialog settings management. - */ -public abstract class AbstractWizard extends Wizard implements IWorkbenchWizard { - // A marker to remember if the dialog settings got - // initialized for this wizard - private boolean dialogSettingsInitialized = false; - - // The workbench instance passed to the wizard via IWorkbenchWizard#init. - private IWorkbench workbench = null; - // The selection passed to the wizard via IWorkbenchWizard#init. - private IStructuredSelection selection = null; - - /** - * Initialize the dialog settings and associate them with the wizard. - */ - private final void initializeDialogSettings() { - // Get the root dialog settings - IDialogSettings rootSettings = getRootDialogSettings(); - // Get the wizards dialog settings section - IDialogSettings section = rootSettings.getSection(getWizardSectionName()); - if (section == null) { - // The section does not exist -> create it - section = rootSettings.addNewSection(getWizardSectionName()); - } - // Push the section to the wizard - setDialogSettings(section); - // Mark the dialog settings initialized - dialogSettingsInitialized = true; - } - - /** - * Returns the root dialog settings. - * <p> - * Typically, this are the dialog settings of the parent bundle. The - * default implementation returns the dialog settings of the bundle - * "<code>org.eclipse.tcf.te.ui</code>". Overwrite to return - * different root dialog settings. - * - * @return The root dialog settings. - */ - protected IDialogSettings getRootDialogSettings() { - return UIPlugin.getDefault().getDialogSettings(); - } - - /** - * Returns the name of the wizards associated dialog settings - * section. - * <p> - * The default implementation returns the simple name of the - * implementation class. - * - * @return The name of the wizards dialog settings section. - */ - protected String getWizardSectionName() { - return getClass().getSimpleName(); - } - - /* (non-Javadoc) - * @see org.eclipse.jface.wizard.Wizard#getDialogSettings() - */ - @Override - public IDialogSettings getDialogSettings() { - if (!dialogSettingsInitialized) { - initializeDialogSettings(); - } - return super.getDialogSettings(); - } - - /* (non-Javadoc) - * @see org.eclipse.ui.IWorkbenchWizard#init(org.eclipse.ui.IWorkbench, org.eclipse.jface.viewers.IStructuredSelection) - */ - @Override - public void init(IWorkbench workbench, IStructuredSelection selection) { - this.workbench = workbench; - this.selection = selection; - } - - /** - * Returns the workbench instance. - * <p> - * <b>Note:</b> The workbench instance is set via {@link IWorkbenchWizard#init(IWorkbench, IStructuredSelection)}. - * - * @return The workbench instance or <code>null</code>. - */ - public final IWorkbench getWorkbench() { - return workbench; - } - - /** - * Returns the selection. - * <p> - * <b>Note:</b> The selection is set via {@link IWorkbenchWizard#init(IWorkbench, IStructuredSelection)}. - * - * @return The selection or <code>null</code>. - */ - public final IStructuredSelection getSelection() { - return selection; - } -} +/*******************************************************************************
+ * Copyright (c) 2011 Wind River Systems, Inc. and others. All rights reserved.
+ * This program and the accompanying materials are made available under the terms
+ * of the Eclipse Public License v1.0 which accompanies this distribution, and is
+ * available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Wind River Systems - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.tcf.te.ui.wizards;
+
+import org.eclipse.jface.dialogs.IDialogSettings;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.wizard.Wizard;
+import org.eclipse.tcf.te.ui.activator.UIPlugin;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchWizard;
+
+/**
+ * An abstract wizard implementation.
+ * <p>
+ * This wizard implementation is adding dialog settings management.
+ */
+public abstract class AbstractWizard extends Wizard implements IWorkbenchWizard {
+ // A marker to remember if the dialog settings got
+ // initialized for this wizard
+ private boolean dialogSettingsInitialized = false;
+
+ // The workbench instance passed to the wizard via IWorkbenchWizard#init.
+ private IWorkbench workbench = null;
+ // The selection passed to the wizard via IWorkbenchWizard#init.
+ private IStructuredSelection selection = null;
+
+ /**
+ * Initialize the dialog settings and associate them with the wizard.
+ */
+ private final void initializeDialogSettings() {
+ // Get the root dialog settings
+ IDialogSettings rootSettings = getRootDialogSettings();
+ // Get the wizards dialog settings section
+ IDialogSettings section = rootSettings.getSection(getWizardSectionName());
+ if (section == null) {
+ // The section does not exist -> create it
+ section = rootSettings.addNewSection(getWizardSectionName());
+ }
+ // Push the section to the wizard
+ setDialogSettings(section);
+ // Mark the dialog settings initialized
+ dialogSettingsInitialized = true;
+ }
+
+ /**
+ * Returns the root dialog settings.
+ * <p>
+ * Typically, this are the dialog settings of the parent bundle. The
+ * default implementation returns the dialog settings of the bundle
+ * "<code>org.eclipse.tcf.te.ui</code>". Overwrite to return
+ * different root dialog settings.
+ *
+ * @return The root dialog settings.
+ */
+ protected IDialogSettings getRootDialogSettings() {
+ return UIPlugin.getDefault().getDialogSettings();
+ }
+
+ /**
+ * Returns the name of the wizards associated dialog settings
+ * section.
+ * <p>
+ * The default implementation returns the simple name of the
+ * implementation class.
+ *
+ * @return The name of the wizards dialog settings section.
+ */
+ protected String getWizardSectionName() {
+ return getClass().getName();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.wizard.Wizard#getDialogSettings()
+ */
+ @Override
+ public IDialogSettings getDialogSettings() {
+ if (!dialogSettingsInitialized) {
+ initializeDialogSettings();
+ }
+ return super.getDialogSettings();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.IWorkbenchWizard#init(org.eclipse.ui.IWorkbench, org.eclipse.jface.viewers.IStructuredSelection)
+ */
+ @Override
+ public void init(IWorkbench workbench, IStructuredSelection selection) {
+ this.workbench = workbench;
+ this.selection = selection;
+ }
+
+ /**
+ * Returns the workbench instance.
+ * <p>
+ * <b>Note:</b> The workbench instance is set via {@link IWorkbenchWizard#init(IWorkbench, IStructuredSelection)}.
+ *
+ * @return The workbench instance or <code>null</code>.
+ */
+ public final IWorkbench getWorkbench() {
+ return workbench;
+ }
+
+ /**
+ * Returns the selection.
+ * <p>
+ * <b>Note:</b> The selection is set via {@link IWorkbenchWizard#init(IWorkbench, IStructuredSelection)}.
+ *
+ * @return The selection or <code>null</code>.
+ */
+ public final IStructuredSelection getSelection() {
+ return selection;
+ }
+}
|