diff options
author | Uwe Stieber | 2012-02-16 16:23:59 +0000 |
---|---|---|
committer | Uwe Stieber | 2012-02-16 16:23:59 +0000 |
commit | 0809f72580fd3293e949f9454cf0ab21343d2cd3 (patch) | |
tree | da7d8f8e589db4c8230773292c9d782a632780b8 /target_explorer | |
parent | 8daa2b2006de61d0be9af0fe0be8f03cda501d7e (diff) | |
download | org.eclipse.tcf-0809f72580fd3293e949f9454cf0ab21343d2cd3.tar.gz org.eclipse.tcf-0809f72580fd3293e949f9454cf0ab21343d2cd3.tar.xz org.eclipse.tcf-0809f72580fd3293e949f9454cf0ab21343d2cd3.zip |
Target Explorer: Continue launch context selector work
Diffstat (limited to 'target_explorer')
8 files changed, 379 insertions, 398 deletions
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.launch.ui/src/org/eclipse/tcf/te/launch/ui/nls/Messages.java b/target_explorer/plugins/org.eclipse.tcf.te.launch.ui/src/org/eclipse/tcf/te/launch/ui/nls/Messages.java index 5b4bb79aa..26d42ff5b 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.launch.ui/src/org/eclipse/tcf/te/launch/ui/nls/Messages.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.launch.ui/src/org/eclipse/tcf/te/launch/ui/nls/Messages.java @@ -9,6 +9,8 @@ *******************************************************************************/ package org.eclipse.tcf.te.launch.ui.nls; +import java.lang.reflect.Field; + import org.eclipse.osgi.util.NLS; /** @@ -27,14 +29,54 @@ public class Messages extends NLS { NLS.initializeMessages(BUNDLE_NAME, Messages.class); } + /** + * Returns if or if not this NLS manager contains a constant for + * the given externalized strings key. + * + * @param key The externalized strings key or <code>null</code>. + * @return <code>True</code> if a constant for the given key exists, <code>false</code> otherwise. + */ + public static boolean hasString(String key) { + if (key != null) { + try { + Field field = Messages.class.getDeclaredField(key); + return field != null; + } catch (NoSuchFieldException e) { /* ignored on purpose */ } + } + + return false; + } + + /** + * Returns the corresponding string for the given externalized strings + * key or <code>null</code> if the key does not exist. + * + * @param key The externalized strings key or <code>null</code>. + * @return The corresponding string or <code>null</code>. + */ + public static String getString(String key) { + if (key != null) { + try { + Field field = Messages.class.getDeclaredField(key); + if (field != null) { + return (String)field.get(null); + } + } catch (Exception e) { /* ignored on purpose */ } + } + + return null; + } + // **** Declare externalized string id's down here ***** public static String LaunchSelectionManager_error_failedToDetermineElfType; - public static String ModelContextSelectorControl_toolbar_refresh_tooltip; + public static String ContextSelectorControl_toolbar_refresh_tooltip; public static String LaunchContextSelectorTab_name; public static String ContextSelectorSection_title; - public static String ContextSelectorSection_description; + + public static String RemoteContextSelectorControl_error_noContextSelected_single; + public static String RemoteContextSelectorControl_error_noContextSelected_multi; } diff --git a/target_explorer/plugins/org.eclipse.tcf.te.launch.ui/src/org/eclipse/tcf/te/launch/ui/nls/Messages.properties b/target_explorer/plugins/org.eclipse.tcf.te.launch.ui/src/org/eclipse/tcf/te/launch/ui/nls/Messages.properties index b44de507e..47b8837bc 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.launch.ui/src/org/eclipse/tcf/te/launch/ui/nls/Messages.properties +++ b/target_explorer/plugins/org.eclipse.tcf.te.launch.ui/src/org/eclipse/tcf/te/launch/ui/nls/Messages.properties @@ -5,9 +5,11 @@ LaunchSelectionManager_error_failedToDetermineElfType=Failed to determine ELF type of file ''{0}''. -ModelContextSelectorControl_toolbar_refresh_tooltip=Refresh - LaunchContextSelectorTab_name=Main +ContextSelectorControl_toolbar_refresh_tooltip=Refresh + ContextSelectorSection_title=Remote Context -ContextSelectorSection_description=Select the remote context. + +RemoteContextSelectorControl_error_noContextSelected_single=Please select a remote context. +RemoteContextSelectorControl_error_noContextSelected_multi=Please select one or more remote contexts. diff --git a/target_explorer/plugins/org.eclipse.tcf.te.launch.ui/src/org/eclipse/tcf/te/launch/ui/tabs/selector/ActionToolItemProxy.java b/target_explorer/plugins/org.eclipse.tcf.te.launch.ui/src/org/eclipse/tcf/te/launch/ui/tabs/selector/ActionToolItemProxy.java deleted file mode 100644 index da243a780..000000000 --- a/target_explorer/plugins/org.eclipse.tcf.te.launch.ui/src/org/eclipse/tcf/te/launch/ui/tabs/selector/ActionToolItemProxy.java +++ /dev/null @@ -1,202 +0,0 @@ -/******************************************************************************* - * Copyright (c) 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.launch.ui.tabs.selector; - -import org.eclipse.core.runtime.Assert; -import org.eclipse.jface.action.IAction; -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.jface.viewers.ISelectionChangedListener; -import org.eclipse.jface.viewers.SelectionChangedEvent; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.events.SelectionListener; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.widgets.Event; -import org.eclipse.swt.widgets.ToolItem; -import org.eclipse.tcf.te.launch.ui.activator.UIPlugin; -import org.eclipse.ui.IActionDelegate; - -/** - * Standard implementation of a proxy between a toolbar item widget and a JFace action. - */ -public class ActionToolItemProxy implements ISelectionChangedListener { - private final ToolItem item; - private final IAction action; - - // Local selection listener invoking the associated action. - private final SelectionListener listener = new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - doRun(e); - } - }; - - /** - * Constructor. - * - * @param item The toolbar item widget. Must not be <code>null</code>. - * @param action The JFace action. Must not be <code>null</code>. - */ - public ActionToolItemProxy(ToolItem item, IAction action) { - Assert.isNotNull(item); - Assert.isNotNull(action); - - this.item = item; - this.action = action; - - initialize(); - } - - /** - * Dispose this proxy instance. - */ - public void dispose() { - item.removeSelectionListener(listener); - } - - /** - * Initialize the connection between the toolbar item widget and the associated JFace action. - */ - public void initialize() { - item.setData(this); - if (getText(action) != null) item.setText(getText(action)); - if (getToolTipText(action) != null) item.setToolTipText(getToolTipText(action)); - if (getImage(action) != null) item.setImage(getImage(action)); - if (getDisabledImage(action) != null) item.setDisabledImage(getDisabledImage(action)); - item.addSelectionListener(listener); - } - - /** - * Returns the associated action. - * - * @return The action. - */ - public final IAction getAction() { - return action; - } - - /** - * Returns the text to apply to the toolbar item widget. - * - * @param action The JFace action. Must not be <code>null</code>. - * @return The text to apply to the toolbar item widget or <code>null</code>. - */ - protected String getText(IAction action) { - Assert.isNotNull(action); - return action.getText(); - } - - /** - * Returns the tooltip text to apply to the toolbar item widget. - * - * @param action The JFace action. Must not be <code>null</code>. - * @return The tooltip text to apply to the toolbar item widget or <code>null</code>. - */ - protected String getToolTipText(IAction action) { - Assert.isNotNull(action); - return action.getToolTipText(); - } - - /** - * Lookup the corresponding image for the given image descriptor. - * - * @param descriptor The image descriptor. - * @return The corresponding image or <code>null</code>. - */ - protected final Image getImageFromDescriptor(ImageDescriptor descriptor) { - if (descriptor == null) return null; - - String key = descriptor.toString(); - Image image = UIPlugin.getImage(key); - if (image == null) { - image = descriptor.createImage(); - UIPlugin.getDefault().getImageRegistry().put(key, image); - } - return image; - } - - /** - * Returns the image to apply to the toolbar item widget. - * - * @param action The JFace action. Must not be <code>null</code>. - * @return The image to apply to the toolbar item widget or <code>null</code>. - */ - protected Image getImage(IAction action) { - Assert.isNotNull(action); - return getImageFromDescriptor(action.getImageDescriptor()); - } - - /** - * Returns the disabled image to apply to the toolbar item widget. - * - * @param action The JFace action. Must not be <code>null</code>. - * @return The disabled image to apply to the toolbar item widget or <code>null</code>. - */ - protected Image getDisabledImage(IAction action) { - Assert.isNotNull(action); - return getImageFromDescriptor(action.getDisabledImageDescriptor()); - } - - /* (non-Javadoc) - * @see org.eclipse.jface.viewers.ISelectionChangedListener#selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent) - */ - @Override - public final void selectionChanged(SelectionChangedEvent event) { - Assert.isNotNull(action); - if (action instanceof IActionDelegate) { - ((IActionDelegate) action).selectionChanged(action, event.getSelection()); - } - item.setEnabled(action.isEnabled()); - } - - /** - * Executes the operation once the user clicked on the toolbar item. - * - * @param e The selection event that triggered the invocation. - */ - protected void doRun(SelectionEvent e) { - Assert.isNotNull(action); - - // Use a SWT event to signal the source of the invocation - Event event = new Event(); - // Fill in the event data based on the passed in selection event - event.display = e.display; - event.widget = e.widget; - event.detail = e.detail; - event.doit = e.doit; - event.item = e.item; - event.text = e.text; - event.time = e.time; - event.stateMask = e.stateMask; - event.height = e.height; - event.width = e.width; - event.x = e.x; - event.y = e.y; - // The event data field is reserved for application use. Fill in - // here our custom data to pass to the associated action. - event.data = getCustomEventDataObject(); - - // And execute the associated action with the created event - action.runWithEvent(event); - } - - /** - * Returns the custom data object to associated with the event passed on to the associated - * action to execute. The interpretation of the custom data object is up to the associated - * action. Check the action documentation! - * <p> - * The default implementation does return always <code>null</code>. - * - * @return The custom data object or <code>null</code>. - */ - protected Object getCustomEventDataObject() { - return null; - } -} diff --git a/target_explorer/plugins/org.eclipse.tcf.te.launch.ui/src/org/eclipse/tcf/te/launch/ui/tabs/selector/ContextSelectorControl.java b/target_explorer/plugins/org.eclipse.tcf.te.launch.ui/src/org/eclipse/tcf/te/launch/ui/tabs/selector/ContextSelectorControl.java index 1c893061c..2bb37b79b 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.launch.ui/src/org/eclipse/tcf/te/launch/ui/tabs/selector/ContextSelectorControl.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.launch.ui/src/org/eclipse/tcf/te/launch/ui/tabs/selector/ContextSelectorControl.java @@ -30,24 +30,13 @@ import org.eclipse.jface.viewers.Viewer; import org.eclipse.jface.viewers.ViewerFilter; import org.eclipse.jface.viewers.ViewerSorter; import org.eclipse.swt.SWT; -import org.eclipse.swt.events.DisposeEvent; -import org.eclipse.swt.events.DisposeListener; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.graphics.Cursor; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Item; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.ToolBar; -import org.eclipse.swt.widgets.ToolItem; import org.eclipse.swt.widgets.Tree; import org.eclipse.swt.widgets.TreeItem; import org.eclipse.swt.widgets.Widget; -import org.eclipse.tcf.te.launch.ui.activator.UIPlugin; -import org.eclipse.tcf.te.launch.ui.internal.ImageConsts; -import org.eclipse.tcf.te.launch.ui.nls.Messages; import org.eclipse.tcf.te.runtime.interfaces.properties.IPropertiesContainer; import org.eclipse.tcf.te.runtime.model.interfaces.IModelNode; import org.eclipse.tcf.te.runtime.properties.PropertiesContainer; @@ -59,12 +48,11 @@ import org.eclipse.tcf.te.ui.swt.SWTControlUtil; import org.eclipse.tcf.te.ui.views.interfaces.IUIConstants; import org.eclipse.tcf.te.ui.views.internal.ViewRoot; import org.eclipse.ui.dialogs.ContainerCheckedTreeViewer; -import org.eclipse.ui.forms.widgets.Section; import org.eclipse.ui.internal.navigator.NavigatorContentService; import org.eclipse.ui.navigator.CommonViewerSorter; /** - * Model context selector control. + * Context selector control. * <p> * Allows to present a configurable set of elements from the data model from which the user can * select one or more elements. @@ -72,7 +60,6 @@ import org.eclipse.ui.navigator.CommonViewerSorter; * Default properties: * <ul> * <li>PROPERTY_SHOW_GHOST_MODEL_NODES = false</li> - * <li>PROPERTY_HAS_TOOLBAR = false</li> * </ul> */ @SuppressWarnings("restriction") @@ -84,11 +71,6 @@ public class ContextSelectorControl extends BaseDialogPageControl implements ISe public static final String PROPERTY_SHOW_GHOST_MODEL_NODES = "showGhostModelNodes"; //$NON-NLS-1$ /** - * Property: If set to <code>true</code>, a toolbar will be added to the control. - */ - public static final String PROPERTY_HAS_TOOLBAR = "hasToolbar"; //$NON-NLS-1$ - - /** * List of selection changed listeners. */ private final List<ISelectionChangedListener> selectionListeners = new ArrayList<ISelectionChangedListener>(); @@ -103,8 +85,6 @@ public class ContextSelectorControl extends BaseDialogPageControl implements ISe private TreeViewer viewer; // The current selection within the tree viewer. /* default */ ISelection selection; - // Reference to the tree viewers toolbar control if any. - private ToolBar toolbar; // Reference to the navigator content service used private NavigatorContentService contentService; @@ -125,9 +105,9 @@ public class ContextSelectorControl extends BaseDialogPageControl implements ISe private ICheckStateListener listener; /** - * Default implementation of the model context selector controls tree viewer. + * Default implementation of the context selector controls tree viewer. */ - protected class ModelContextSelectorTreeViewer extends ContainerCheckedTreeViewer { + protected class ContextSelectorTreeViewer extends ContainerCheckedTreeViewer { /** * Constructor. @@ -135,7 +115,7 @@ public class ContextSelectorControl extends BaseDialogPageControl implements ISe * @param parent The parent control. * @param style The SWT style bits used to create the tree. */ - public ModelContextSelectorTreeViewer(Composite parent, int style) { + public ContextSelectorTreeViewer(Composite parent, int style) { // make sure that the passed in style bits are not contaminated // by the CheckboxTreeViewer. this(new Tree(parent, style)); @@ -146,7 +126,7 @@ public class ContextSelectorControl extends BaseDialogPageControl implements ISe * * @param parent The parent control. */ - public ModelContextSelectorTreeViewer(Composite parent) { + public ContextSelectorTreeViewer(Composite parent) { super(parent); } @@ -155,12 +135,11 @@ public class ContextSelectorControl extends BaseDialogPageControl implements ISe * * @param tree The tree control. */ - public ModelContextSelectorTreeViewer(Tree tree) { + public ContextSelectorTreeViewer(Tree tree) { super(tree); } - /* - * (non-Javadoc) + /* (non-Javadoc) * @see org.eclipse.jface.viewers.TreeViewer#isExpandable(java.lang.Object) */ @Override @@ -183,10 +162,8 @@ public class ContextSelectorControl extends BaseDialogPageControl implements ISe return getChildren(item); } - /* - * (non-Javadoc) - * @see - * org.eclipse.ui.dialogs.ContainerCheckedTreeViewer#doCheckStateChanged(java.lang.Object) + /* (non-Javadoc) + * @see org.eclipse.ui.dialogs.ContainerCheckedTreeViewer#doCheckStateChanged(java.lang.Object) */ @Override protected void doCheckStateChanged(Object element) { @@ -270,24 +247,25 @@ public class ContextSelectorControl extends BaseDialogPageControl implements ISe } /** - * Default implementation of the model context selector controls check state listener. + * Default implementation of the context selector controls check state listener. */ - protected class ModelContextSelectedCheckStateListener implements ICheckStateListener { + protected class ContextSelectedCheckStateListener implements ICheckStateListener { /* (non-Javadoc) * @see org.eclipse.jface.viewers.ICheckStateListener#checkStateChanged(org.eclipse.jface.viewers.CheckStateChangedEvent) */ @Override public void checkStateChanged(CheckStateChangedEvent event) { Object element = event.getElement(); - if (element instanceof IModelNode) onModelNodeCheckStateChanged((IModelNode) element, event - .getChecked()); + if (element instanceof IModelNode) { + onModelNodeCheckStateChanged((IModelNode) element, event.getChecked()); + } } } /** - * Default implementation of the model context selector controls viewer filter. + * Default implementation of the context selector controls viewer filter. */ - protected class ModelContextSelectorViewerFilter extends ViewerFilter { + protected class ContextSelectorViewerFilter extends ViewerFilter { /** * Returns if or if not ghost model elements should be visible within the model context @@ -344,7 +322,6 @@ public class ContextSelectorControl extends BaseDialogPageControl implements ISe protected void initializeProperties(IPropertiesContainer properties) { Assert.isNotNull(properties); properties.setProperty(PROPERTY_SHOW_GHOST_MODEL_NODES, false); - properties.setProperty(PROPERTY_HAS_TOOLBAR, false); } /** @@ -364,17 +341,6 @@ public class ContextSelectorControl extends BaseDialogPageControl implements ISe */ @Override public void dispose() { - // Remove the action proxy items from the viewer - if (toolbar != null) { - ToolItem[] items = toolbar.getItems(); - for (ToolItem item : items) { - if (item.getData() instanceof ActionToolItemProxy) { - viewer.removeSelectionChangedListener((ActionToolItemProxy) item.getData()); - } - } - toolbar = null; - } - // Dispose the navigator content service if (contentService != null) { contentService.dispose(); @@ -470,12 +436,8 @@ public class ContextSelectorControl extends BaseDialogPageControl implements ISe Composite composite = doCreateTopContainerComposite(parent); Assert.isNotNull(composite); - // Create the toolbar control (but not the items) - if (getPropertiesContainer().getBooleanProperty(PROPERTY_HAS_TOOLBAR)) toolbar = createToolBarControl(doCreateToolBarComposite(composite)); // Create the viewer viewer = createTreeViewerControl(composite); - // and than create the toolbar items (as they may need the viewer) - if (getPropertiesContainer().getBooleanProperty(PROPERTY_HAS_TOOLBAR)) createToolBarItems(toolbar); // And now configure the listeners configureControlListener(); @@ -540,7 +502,7 @@ public class ContextSelectorControl extends BaseDialogPageControl implements ISe * @return The tree viewer instance. Must not be <code>null</code>. */ protected CheckboxTreeViewer doCreateNewTreeViewerControl(Composite parent, int style) { - return new ModelContextSelectorTreeViewer(parent, style); + return new ContextSelectorTreeViewer(parent, style); } /** @@ -633,7 +595,7 @@ public class ContextSelectorControl extends BaseDialogPageControl implements ISe * @return The viewer filters to associate or <code>null</code> if none. */ protected ViewerFilter[] doCreateViewerFilters() { - return new ViewerFilter[] { new ModelContextSelectorViewerFilter() }; + return new ViewerFilter[] { new ContextSelectorViewerFilter() }; } /** @@ -658,7 +620,7 @@ public class ContextSelectorControl extends BaseDialogPageControl implements ISe */ protected ICheckStateListener doCreateViewerCheckStateListener(CheckboxTreeViewer viewer) { Assert.isNotNull(viewer); - return new ModelContextSelectedCheckStateListener(); + return new ContextSelectedCheckStateListener(); } /** @@ -706,7 +668,7 @@ public class ContextSelectorControl extends BaseDialogPageControl implements ISe */ protected void doEnableControl(TreeViewer viewer) { Assert.isNotNull(viewer); - SWTControlUtil.setEnabled(viewer.getTree(), viewer.getTree().getItemCount() > 1); + SWTControlUtil.setEnabled(viewer.getTree(), viewer.getTree().getItemCount() > 0); } /** @@ -721,133 +683,6 @@ public class ContextSelectorControl extends BaseDialogPageControl implements ISe } /** - * Returns the toolbar control (if enabled). - * - * @return The toolbar control or <code>null</code>. - */ - protected ToolBar getToolBar() { - return toolbar; - } - - /** - * Creates the toolbar control (if enabled). Override to return a custom toolbar control or - * composite layout. - * - * @param parent The parent composite to create the toolbar control in. Must not be - * <code>null</code>. - * @return The toolbar control. Must be never <code>null</code>. - */ - protected ToolBar createToolBarControl(Composite parent) { - // Create the toolbar control - ToolBar toolbar = new ToolBar(parent, SWT.FLAT | SWT.HORIZONTAL | SWT.RIGHT); - - // The cursor within the toolbar shall change to an hand - final Cursor handCursor = new Cursor(parent.getDisplay(), SWT.CURSOR_HAND); - toolbar.setCursor(handCursor); - // Cursor needs to be explicitly disposed - toolbar.addDisposeListener(new DisposeListener() { - @Override - public void widgetDisposed(DisposeEvent e) { - if (handCursor.isDisposed() == false) { - handCursor.dispose(); - } - } - }); - - // If the parent composite is a forms section, set the toolbar - // as text client to the section header - if (parent instanceof Section) { - Section section = (Section) parent; - // Set the toolbar as text client - section.setTextClient(toolbar); - } - else { - // If not embedded within a forms section, attach standard - // grid layout and grid layout data to the toolbar control. - GridLayout layout = new GridLayout(); - layout.marginHeight = 0; - layout.marginWidth = 0; - toolbar.setLayout(layout); - toolbar.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.HORIZONTAL_ALIGN_END | GridData.VERTICAL_ALIGN_CENTER)); - } - - // Return the toolbar control. - return toolbar; - } - - /** - * Create the composite container for the toolbar control. This method is called from - * {@link #createToolBarControl(Composite)}. - * <p> - * The default implementation creates a composite which is shared between the control title and - * the toolbar, if a default title is set and the control is not created within a form. - * - * @param parent The parent composite. Must not be <code>null</code>. - * @return The composite to create the toolbar control in. Must not be <code>null</code>. - */ - protected Composite doCreateToolBarComposite(Composite parent) { - Composite composite = parent; - - // In case a default title is set, the control title and the - // toolbar should share the same composite for align them on the - // same horizontal level. - if (getDefaultTitle() != null && getDefaultTitle().trim().length() > 0) { - composite = new Composite(parent, SWT.NONE); - GridLayout layout = new GridLayout(2, false); - layout.marginHeight = 0; - layout.marginWidth = 0; - composite.setLayout(layout); - composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - - Label label = new Label(composite, SWT.HORIZONTAL); - label.setText(getDefaultTitle() + ":"); //$NON-NLS-1$ - } - - return composite; - } - - /** - * Create the toolbar items to be added to the toolbar. Override to add the wanted toolbar - * items. The default implementation adds a refresh toolbar item only. - * - * @param toolbar The toolbar to add the toolbar items too. Must not be <code>null</code>. - */ - protected void createToolBarItems(ToolBar toolbar) { - Assert.isNotNull(toolbar); - createRefreshItem(toolbar); - } - - /** - * Creates the default refresh toolbar item. Override to customize the default behavior. - * - * @param toolbar The toolbar to create the refresh toolbar item within. Must not be <code>null</code>. - */ - protected void createRefreshItem(ToolBar toolbar) { - Assert.isNotNull(toolbar); - - ToolItem item = new ToolItem(toolbar, SWT.PUSH); - item.setToolTipText(Messages.ModelContextSelectorControl_toolbar_refresh_tooltip); - item.setImage(UIPlugin.getImage(ImageConsts.ACTION_Refresh_Enabled)); - item.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - refresh(); - } - }); - } - - /** - * Creates a separator toolbar item. - * - * @param toolbar The toolbar. Must not be <code>null</code>. - */ - @SuppressWarnings("unused") - protected void createSeparatorItem(ToolBar toolbar) { - Assert.isNotNull(toolbar); - new ToolItem(toolbar, SWT.SEPARATOR); - } - - /** * Called from {@link #setupPanel(Composite)} before returning the control to the caller. * Override to plug-in and configure any custom listener the subclassed control might need. */ diff --git a/target_explorer/plugins/org.eclipse.tcf.te.launch.ui/src/org/eclipse/tcf/te/launch/ui/tabs/selector/ContextSelectorSection.java b/target_explorer/plugins/org.eclipse.tcf.te.launch.ui/src/org/eclipse/tcf/te/launch/ui/tabs/selector/ContextSelectorSection.java index 503263dda..ca464631c 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.launch.ui/src/org/eclipse/tcf/te/launch/ui/tabs/selector/ContextSelectorSection.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.launch.ui/src/org/eclipse/tcf/te/launch/ui/tabs/selector/ContextSelectorSection.java @@ -10,9 +10,14 @@ package org.eclipse.tcf.te.launch.ui.tabs.selector;
import org.eclipse.core.runtime.Assert;
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.action.ToolBarManager;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Composite;
+import org.eclipse.tcf.te.launch.ui.activator.UIPlugin;
+import org.eclipse.tcf.te.launch.ui.internal.ImageConsts;
import org.eclipse.tcf.te.launch.ui.nls.Messages;
import org.eclipse.tcf.te.ui.forms.parts.AbstractSection;
import org.eclipse.ui.forms.IManagedForm;
@@ -25,7 +30,32 @@ import org.eclipse.ui.forms.widgets.Section; */
public class ContextSelectorSection extends AbstractSection {
// Reference to the section sub controls
- private ContextSelectorControl selector;
+ /* default */ RemoteContextSelectorControl selector;
+
+ /**
+ * Context selector control refresh action implementation.
+ */
+ protected class RefreshAction extends Action {
+
+ /**
+ * Constructor.
+ */
+ public RefreshAction() {
+ super(null, IAction.AS_PUSH_BUTTON);
+ setImageDescriptor(UIPlugin.getImageDescriptor(ImageConsts.ACTION_Refresh_Enabled));
+ setToolTipText(Messages.ContextSelectorControl_toolbar_refresh_tooltip);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.action.Action#run()
+ */
+ @Override
+ public void run() {
+ if (selector != null && selector.getViewer() != null) {
+ selector.getViewer().refresh();
+ }
+ }
+ }
/**
* Constructor.
@@ -34,7 +64,7 @@ public class ContextSelectorSection extends AbstractSection { * @param parent The parent composite. Must not be <code>null</code>.
*/
public ContextSelectorSection(IManagedForm form, Composite parent) {
- super(form, parent, Section.DESCRIPTION | ExpandableComposite.CLIENT_INDENT);
+ super(form, parent, ExpandableComposite.TWISTIE | ExpandableComposite.EXPANDED);
createClient(getSection(), form.getToolkit());
}
@@ -48,8 +78,6 @@ public class ContextSelectorSection extends AbstractSection { // Configure the section
section.setText(Messages.ContextSelectorSection_title);
- section.setDescription(Messages.ContextSelectorSection_description);
-
section.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
// Create the section client
@@ -57,7 +85,11 @@ public class ContextSelectorSection extends AbstractSection { Assert.isNotNull(client);
section.setClient(client);
- selector = new ContextSelectorControl(null);
+ // Create a toolbar for the section
+ createSectionToolbar(section, toolkit);
+
+ // Create the section sub controls
+ selector = new RemoteContextSelectorControl(null);
selector.setFormToolkit(toolkit);
selector.setupPanel(client);
}
@@ -70,4 +102,13 @@ public class ContextSelectorSection extends AbstractSection { if (selector != null) { selector.dispose(); selector = null; }
super.dispose();
}
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.ui.forms.parts.AbstractSection#createSectionToolbarItems(org.eclipse.ui.forms.widgets.Section, org.eclipse.ui.forms.widgets.FormToolkit, org.eclipse.jface.action.ToolBarManager)
+ */
+ @Override
+ protected void createSectionToolbarItems(Section section, FormToolkit toolkit, ToolBarManager tlbMgr) {
+ super.createSectionToolbarItems(section, toolkit, tlbMgr);
+ tlbMgr.add(new RefreshAction());
+ }
}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.launch.ui/src/org/eclipse/tcf/te/launch/ui/tabs/selector/LaunchContextSelectorTab.java b/target_explorer/plugins/org.eclipse.tcf.te.launch.ui/src/org/eclipse/tcf/te/launch/ui/tabs/selector/LaunchContextSelectorTab.java index 94ae9f76b..40b228413 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.launch.ui/src/org/eclipse/tcf/te/launch/ui/tabs/selector/LaunchContextSelectorTab.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.launch.ui/src/org/eclipse/tcf/te/launch/ui/tabs/selector/LaunchContextSelectorTab.java @@ -48,7 +48,7 @@ public class LaunchContextSelectorTab extends AbstractFormsLaunchConfigurationTa Composite panel = toolkit.getFormToolkit().createComposite(parent);
TableWrapLayout layout = new TableWrapLayout();
layout.makeColumnsEqualWidth = true;
- layout.numColumns = 2;
+ layout.numColumns = 1;
panel.setLayout(layout);
panel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.launch.ui/src/org/eclipse/tcf/te/launch/ui/tabs/selector/RemoteContextSelectorControl.java b/target_explorer/plugins/org.eclipse.tcf.te.launch.ui/src/org/eclipse/tcf/te/launch/ui/tabs/selector/RemoteContextSelectorControl.java new file mode 100644 index 000000000..c8cffbdd2 --- /dev/null +++ b/target_explorer/plugins/org.eclipse.tcf.te.launch.ui/src/org/eclipse/tcf/te/launch/ui/tabs/selector/RemoteContextSelectorControl.java @@ -0,0 +1,207 @@ +/*******************************************************************************
+ * Copyright (c) 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.launch.ui.tabs.selector;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.jface.dialogs.IDialogPage;
+import org.eclipse.jface.dialogs.IMessageProvider;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Item;
+import org.eclipse.tcf.te.launch.ui.nls.Messages;
+import org.eclipse.tcf.te.runtime.interfaces.properties.IPropertiesContainer;
+import org.eclipse.tcf.te.runtime.model.interfaces.IModelNode;
+import org.eclipse.tcf.te.ui.jface.interfaces.IValidatingContainer;
+
+/**
+ * Remote context selector control implementation.
+ * <p>
+ * Default properties:
+ * <ul>
+ * <li>PROPERTY_SHOW_GHOST_MODEL_NODES = false</li>
+ * <li>PROPERTY_MULTI_CONTEXT_SELECTOR = true</li>
+ * </ul>
+ */
+public class RemoteContextSelectorControl extends ContextSelectorControl {
+ /**
+ * Property: If set to <code>true</code>, the control will be created as multi
+ * context control. That means that more than one tree item will be
+ * checkmarkable. In single context selector mode, only one tree item
+ * can be checkmarked at the same time.
+ */
+ public static final String PROPERTY_MULTI_CONTEXT_SELECTOR = "multiContextSelector"; //$NON-NLS-1$
+
+ // The last failure cause
+ private Throwable lastFailureCause;
+ // Flag for controlling if at least one element has to be selected
+ private boolean requireSelection = true;
+
+ /**
+ * Constructor.
+ *
+ * @param parentPage The parent target connection page this control is embedded in. Might be
+ * <code>null</code> if the control is not associated with a page.
+ */
+ public RemoteContextSelectorControl(IDialogPage parentPage) {
+ super(parentPage);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.launch.ui.tabs.selector.ContextSelectorControl#initializeProperties(org.eclipse.tcf.te.runtime.interfaces.properties.IPropertiesContainer)
+ */
+ @Override
+ protected void initializeProperties(IPropertiesContainer properties) {
+ super.initializeProperties(properties);
+ properties.setProperty(PROPERTY_MULTI_CONTEXT_SELECTOR, true);
+ }
+
+ /**
+ * Set the last failure cause to display.
+ *
+ * @param cause The last failure case or <code>null</code>.
+ */
+ public final void setLastFailureCause(Throwable cause) {
+ lastFailureCause = cause;
+ if (getParentPage() instanceof IValidatingContainer) {
+ ((IValidatingContainer)getParentPage()).validate();
+ }
+ }
+
+ /**
+ * Returns the last failure cause to display.
+ *
+ * @return The last failure cause or <code>null</code>.
+ */
+ public final Throwable getLastFailureCause() {
+ return lastFailureCause;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.launch.ui.tabs.selector.ContextSelectorControl#createTreeViewerControl(org.eclipse.swt.widgets.Composite)
+ */
+ @Override
+ protected TreeViewer createTreeViewerControl(Composite parent) {
+ TreeViewer viewer = super.createTreeViewerControl(parent);
+ if (viewer != null) {
+ viewer.expandAll();
+ }
+ return viewer;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.launch.ui.tabs.selector.ContextSelectorControl#getTreeViewerStyle()
+ */
+ @Override
+ protected int getTreeViewerStyle() {
+ // For the remote context selector we do want to have checkboxes in front
+ // of the tree items and allow for multi-selection.
+ return super.getTreeViewerStyle() & ~SWT.SINGLE | SWT.CHECK | SWT.MULTI;
+ }
+
+ /* (non-Javadoc)
+ * @see com.windriver.ide.target.ui.wizard.controls.elementselector.WRModelContextSelectorControl#onModelNodeCheckStateChanged(com.windriver.ide.target.api.model.IModelNode, boolean)
+ */
+ @Override
+ protected void onModelNodeCheckStateChanged(IModelNode node, boolean checked) {
+ // In case the control is operating in single context selector mode,
+ // we have to uncheck any other element than the given checked one.
+ if (checked && getPropertiesContainer().isProperty(PROPERTY_MULTI_CONTEXT_SELECTOR, false)) {
+ if (getViewer() instanceof ContextSelectorTreeViewer) {
+ // Node: Within here, only methods which do not fire the check state listeners
+ // again must be used!
+ ContextSelectorTreeViewer viewer = (ContextSelectorTreeViewer)getViewer();
+
+ // If the checked node is a container node and has children, select
+ // the first children of the container.
+ Item[] childItems = viewer.getChildren(node);
+ if (childItems != null && childItems.length > 1) {
+ // Take the first item as element to be checked
+ viewer.setCheckedElements(new Object[] { childItems[0].getData() });
+ } else {
+ // Set the passed in element node checked
+ viewer.setCheckedElements(new Object[] { node });
+ }
+ }
+ }
+
+ // Trigger page validation after adjusting the checked state.
+ super.onModelNodeCheckStateChanged(node, checked);
+ }
+
+ /* (non-Javadoc)
+ * @see com.windriver.ide.target.ui.wizard.controls.WRBaseTargetConnectionPageControl#isValid()
+ */
+ @Override
+ public boolean isValid() {
+ boolean valid = super.isValid();
+
+ // If there is a last failure cause set, show that failure cause
+ valid = getLastFailureCause() == null;
+ if (!valid) {
+ setMessage(getLastFailureCause().getLocalizedMessage(), IMessageProvider.ERROR);
+ }
+
+ // The remote context selector control is only valid, if at least one
+ // element has been checked (if operating with CHECK style set)
+ if (valid && (getTreeViewerStyle() & SWT.CHECK) != 0 && requireSelection) {
+ valid = getCheckedModelContexts().length > 0;
+
+ // if we are not valid here, it can only mean, that there is
+ // no connectable checked.
+ if (!valid) {
+ String messageId = "RemoteContextSelectorControl_error_noContextSelected"; //$NON-NLS-1$
+ if (getPropertiesContainer().isProperty(PROPERTY_MULTI_CONTEXT_SELECTOR, true)) {
+ messageId += "_multi"; //$NON-NLS-1$
+ }
+ else {
+ messageId += "_single"; //$NON-NLS-1$
+ }
+
+ setMessage(getMessageForId(messageId), getMessageTypeForId(messageId, IMessageProvider.ERROR));
+ }
+ }
+
+ return valid;
+ }
+
+ /**
+ * Returns the message text for the given message id. Subclass in case different
+ * message text should be used for standard messages.
+ *
+ * @param messageId The message id. Must be not <code>null</code>.
+ * @return The message text.
+ */
+ protected String getMessageForId(String messageId) {
+ Assert.isNotNull(messageId);
+ return Messages.getString(messageId);
+ }
+
+ /**
+ * Returns the message type for the given message id. Subclass in case different
+ * message types should by used for standard messages. The default implementation
+ * returns the proposed message type unchanged.
+ *
+ * @param messageId The message id. Must be not <code>null</code>.
+ * @param proposed The proposed message type.
+ * @return The message type for the given message id.
+ */
+ protected int getMessageTypeForId(String messageId, int proposed) {
+ Assert.isNotNull(messageId);
+ return proposed;
+ }
+
+ /**
+ * Configures whether a selection is required or not.
+ */
+ public void setRequireSelection(boolean value) {
+ requireSelection = value;
+ }
+}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui.forms/src/org/eclipse/tcf/te/ui/forms/parts/AbstractSection.java b/target_explorer/plugins/org.eclipse.tcf.te.ui.forms/src/org/eclipse/tcf/te/ui/forms/parts/AbstractSection.java index 375e1453e..24263c38d 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.ui.forms/src/org/eclipse/tcf/te/ui/forms/parts/AbstractSection.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.ui.forms/src/org/eclipse/tcf/te/ui/forms/parts/AbstractSection.java @@ -14,11 +14,17 @@ import java.lang.reflect.Field; import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.Platform;
+import org.eclipse.jface.action.ToolBarManager;
import org.eclipse.jface.dialogs.IMessageProvider;
import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.DisposeEvent;
+import org.eclipse.swt.events.DisposeListener;
+import org.eclipse.swt.graphics.Cursor;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.tcf.te.ui.forms.FormLayoutFactory;
import org.eclipse.tcf.te.ui.jface.interfaces.IValidatable;
import org.eclipse.tcf.te.ui.swt.SWTControlUtil;
@@ -111,6 +117,56 @@ public abstract class AbstractSection extends SectionPart implements IAdaptable, return emptySpace;
}
+ /**
+ * Convenience method to create a section toolbar.
+ *
+ * @param section The section. Must not be <code>null</code>.
+ * @param toolkit The form toolkit or <code>null</code>.
+ */
+ protected void createSectionToolbar(Section section, FormToolkit toolkit) {
+ Assert.isNotNull(section);
+
+ // Create the toolbar manager and the toolbar control
+ ToolBarManager tlbMgr = new ToolBarManager(SWT.FLAT);
+ ToolBar tlb = tlbMgr.createControl(section);
+
+ // If the user moves over the toolbar area, change the cursor to become a hand
+ final Cursor cursor = new Cursor(Display.getCurrent(), SWT.CURSOR_HAND);
+ tlb.setCursor(cursor);
+
+ // Cursor needs to be explicitly disposed
+ tlb.addDisposeListener(new DisposeListener() {
+ @Override
+ public void widgetDisposed(DisposeEvent e) {
+ if (cursor.isDisposed() == false) {
+ cursor.dispose();
+ }
+ }
+ });
+
+ // Create the toolbar items
+ createSectionToolbarItems(section, toolkit, tlbMgr);
+
+ // Update the toolbar manager
+ tlbMgr.update(true);
+ // Associate the toolbar control with the section
+ section.setTextClient(tlb);
+ }
+
+ /**
+ * Convenience method to create section toolbar items.
+ * <p>
+ * This method is called from {@link #createSectionToolbar(Section, FormToolkit)}.
+ *
+ * @param section The section. Must not be <code>null</code>.
+ * @param toolkit The form toolkit or <code>null</code>.
+ * @param tlbMgr The toolbar manager. Must not be <code>null</code>.
+ */
+ protected void createSectionToolbarItems(Section section, FormToolkit toolkit, ToolBarManager tlbMgr) {
+ Assert.isNotNull(section);
+ Assert.isNotNull(tlbMgr);
+ }
+
/* (non-Javadoc)
* @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
*/
|