Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUwe Stieber2012-08-08 04:29:05 -0400
committerUwe Stieber2012-08-08 04:29:05 -0400
commita19c1e543fa9fd9020336115828e4a85e78906e3 (patch)
tree69a0f1851e8f6b90fb3a6b656c46db7c65efdb24 /target_explorer
parent0561f950fe6033e1244d06b0410f95ee5b8f717c (diff)
downloadorg.eclipse.tcf-a19c1e543fa9fd9020336115828e4a85e78906e3.tar.gz
org.eclipse.tcf-a19c1e543fa9fd9020336115828e4a85e78906e3.tar.xz
org.eclipse.tcf-a19c1e543fa9fd9020336115828e4a85e78906e3.zip
Target Explorer: Fix FindBugs warnings
Diffstat (limited to 'target_explorer')
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.core/src/org/eclipse/tcf/te/core/async/AsyncCallbackHandler.java2
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.launch.ui/src/org/eclipse/tcf/te/launch/ui/handler/LaunchShortcutHandler.java5
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.launch.ui/src/org/eclipse/tcf/te/launch/ui/nls/Messages.java256
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.launch.ui/src/org/eclipse/tcf/te/launch/ui/tabs/AbstractLaunchConfigurationTabGroup.java3
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.launch.ui/src/org/eclipse/tcf/te/launch/ui/tabs/launchcontext/AbstractContextSelectorControl.java1792
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.runtime.services/src/org/eclipse/tcf/te/runtime/services/AbstractServiceManager.java6
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.runtime/src/org/eclipse/tcf/te/runtime/processes/ProcessOutputReaderThread.java11
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.runtime/src/org/eclipse/tcf/te/runtime/tracing/TraceHandler.java566
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.core.scripting/src/org/eclipse/tcf/te/tcf/core/scripting/parser/Parser.java2
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/nls/Messages.java4
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/compare/MergeTypedElement.java198
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/nls/Messages.java4
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.core/src/org/eclipse/tcf/te/tcf/launch/core/internal/EventListenerDelegate.java5
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.core/src/org/eclipse/tcf/te/tcf/launch/core/lm/delegates/AttachLaunchManagerDelegate.java9
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.core/src/org/eclipse/tcf/te/tcf/launch/core/lm/delegates/RemoteAppLaunchManagerDelegate.java624
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.ui/src/org/eclipse/tcf/te/tcf/launch/ui/editor/AbstractTcfLaunchTabContainerEditorPage.java4
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/internal/nls/Messages.java4
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/nodes/LocatorModel.java11
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.processes.core/src/org/eclipse/tcf/te/tcf/processes/core/launcher/ProcessStreamsListener.java4
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.terminals.core/src/org/eclipse/tcf/te/tcf/terminals/core/launcher/TerminalsStreamsListener.java8
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/navigator/DelegatingLabelProvider.java4
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/nls/Messages.java4
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.ui.controls/src/org/eclipse/tcf/te/ui/controls/nls/Messages.java4
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.ui.swt/src/org/eclipse/tcf/te/ui/swt/SWTControlUtil.java2
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.ui.swt/src/org/eclipse/tcf/te/ui/swt/nls/Messages.java4
25 files changed, 1763 insertions, 1773 deletions
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.core/src/org/eclipse/tcf/te/core/async/AsyncCallbackHandler.java b/target_explorer/plugins/org.eclipse.tcf.te.core/src/org/eclipse/tcf/te/core/async/AsyncCallbackHandler.java
index 6b1ea5195..5e8524175 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.core/src/org/eclipse/tcf/te/core/async/AsyncCallbackHandler.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.core/src/org/eclipse/tcf/te/core/async/AsyncCallbackHandler.java
@@ -98,7 +98,7 @@ public class AsyncCallbackHandler {
Iterator<?> iterator = callbacks.iterator();
System.err.println("Remaining adders: "); //$NON-NLS-1$
while (iterator.hasNext()) {
- Exception adder = (Exception) callbackAdders.get(iterator.next());
+ Throwable adder = callbackAdders.get(iterator.next());
adder.printStackTrace();
System.err.println("*****"); //$NON-NLS-1$
}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.launch.ui/src/org/eclipse/tcf/te/launch/ui/handler/LaunchShortcutHandler.java b/target_explorer/plugins/org.eclipse.tcf.te.launch.ui/src/org/eclipse/tcf/te/launch/ui/handler/LaunchShortcutHandler.java
index 9d8ffd428..2c3583a12 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.launch.ui/src/org/eclipse/tcf/te/launch/ui/handler/LaunchShortcutHandler.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.launch.ui/src/org/eclipse/tcf/te/launch/ui/handler/LaunchShortcutHandler.java
@@ -54,10 +54,11 @@ public class LaunchShortcutHandler extends AbstractHandler implements ILaunchSho
try {
ILaunchSelection launchSelection = LaunchSelectionManager.getInstance().getLaunchSelection(launchConfigType, mode, null);
ILaunchManagerDelegate delegate = LaunchManager.getInstance().getLaunchManagerDelegate(launchConfigType, mode);
- if (delegate != null && launchSelection != null) {
+ Assert.isNotNull(delegate);
+ if (launchSelection != null) {
// create an empty launch configuration specification to initialize all attributes with their default defaults.
ILaunchSpecification launchSpec = delegate.getLaunchSpecification(launchConfigType.getIdentifier(), launchSelection);
- // initialize the new launch config.
+ // initialize the new launch configuration.
// ignore validation result of launch spec - init as much attributes as possible
if (launchSpec != null) {
ILaunchConfiguration[] launchConfigs = DebugPlugin.getDefault().getLaunchManager().getLaunchConfigurations(launchConfigType);
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 1b72558de..d5d799e38 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
@@ -1,129 +1,127 @@
-/*******************************************************************************
- * 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.launch.ui.nls;
-
-import java.lang.reflect.Field;
-
-import org.eclipse.osgi.util.NLS;
-
-/**
- * Launch UI Plug-in externalized strings management.
- */
-public class Messages extends NLS {
-
- // The plug-in resource bundle name
- private static final String BUNDLE_NAME = "org.eclipse.tcf.te.launch.ui.nls.Messages"; //$NON-NLS-1$
-
- /**
- * Static constructor.
- */
- static {
- // Load message values from bundle file
- 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 ContextSelectorControl_toolbar_refresh_tooltip;
-
- public static String LaunchConfigType_title;
- public static String LaunchConfigType_label;
-
- public static String LaunchContextSelectorTab_name;
-
- public static String ContextSelectorSection_title;
- public static String ContextSelectorSection_label;
-
- public static String RemoteContextSelectorControl_error_noContextSelected_single;
- public static String RemoteContextSelectorControl_error_noContextSelected_multi;
-
- public static String ReferencedProjectsTab_name;
-
- public static String ReferencedProjectsSection_title;
- public static String ReferencedProjectsSection_description;
- public static String ReferencedProjectsSection_name_column;
- public static String ReferencedProjectsSection_add_button;
- public static String ReferencedProjectsSection_delete_button;
- public static String ReferencedProjectsSection_up_button;
- public static String ReferencedProjectsSection_down_button;
- public static String ReferencedProjectsSection_addDialog_message;
-
- public static String FileTransferTab_name;
-
- public static String FileTransferSection_title;
- public static String FileTransferSection_description;
- public static String FileTransferSection_host_column;
- public static String FileTransferSection_target_column;
- public static String FileTransferSection_options_column;
- public static String FileTransferSection_add_button;
- public static String FileTransferSection_edit_button;
- public static String FileTransferSection_delete_button;
- public static String FileTransferSection_up_button;
- public static String FileTransferSection_down_button;
- public static String FileTransferSection_toHost_text;
- public static String FileTransferSection_toTarget_text;
- public static String FileTransferSection_toHost_tooltip;
- public static String FileTransferSection_toTarget_tooltip;
-
- public static String LaunchEditorPage_title;
-
- public static String LaunchExplorerEditorPage_PageTitle;
-
- public static String DeleteHandlerDelegate_question_title;
- public static String DeleteHandlerDelegate_question_message;
-
- public static String LaunchDialogHandler_dialog_title;
- public static String LaunchDialogHandler_dialog_message;
-
- public static String CommonDnD_launchMode_dialog_title;
- public static String CommonDnD_launchMode_dialog_message;
- public static String CommonDnD_launchType_dialog_title;
- public static String CommonDnD_launchType_dialog_message;
-}
+/*******************************************************************************
+ * 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.launch.ui.nls;
+
+import java.lang.reflect.Field;
+
+import org.eclipse.osgi.util.NLS;
+
+/**
+ * Launch UI Plug-in externalized strings management.
+ */
+public class Messages extends NLS {
+
+ // The plug-in resource bundle name
+ private static final String BUNDLE_NAME = "org.eclipse.tcf.te.launch.ui.nls.Messages"; //$NON-NLS-1$
+
+ /**
+ * Static constructor.
+ */
+ static {
+ // Load message values from bundle file
+ 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);
+ 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 ContextSelectorControl_toolbar_refresh_tooltip;
+
+ public static String LaunchConfigType_title;
+ public static String LaunchConfigType_label;
+
+ public static String LaunchContextSelectorTab_name;
+
+ public static String ContextSelectorSection_title;
+ public static String ContextSelectorSection_label;
+
+ public static String RemoteContextSelectorControl_error_noContextSelected_single;
+ public static String RemoteContextSelectorControl_error_noContextSelected_multi;
+
+ public static String ReferencedProjectsTab_name;
+
+ public static String ReferencedProjectsSection_title;
+ public static String ReferencedProjectsSection_description;
+ public static String ReferencedProjectsSection_name_column;
+ public static String ReferencedProjectsSection_add_button;
+ public static String ReferencedProjectsSection_delete_button;
+ public static String ReferencedProjectsSection_up_button;
+ public static String ReferencedProjectsSection_down_button;
+ public static String ReferencedProjectsSection_addDialog_message;
+
+ public static String FileTransferTab_name;
+
+ public static String FileTransferSection_title;
+ public static String FileTransferSection_description;
+ public static String FileTransferSection_host_column;
+ public static String FileTransferSection_target_column;
+ public static String FileTransferSection_options_column;
+ public static String FileTransferSection_add_button;
+ public static String FileTransferSection_edit_button;
+ public static String FileTransferSection_delete_button;
+ public static String FileTransferSection_up_button;
+ public static String FileTransferSection_down_button;
+ public static String FileTransferSection_toHost_text;
+ public static String FileTransferSection_toTarget_text;
+ public static String FileTransferSection_toHost_tooltip;
+ public static String FileTransferSection_toTarget_tooltip;
+
+ public static String LaunchEditorPage_title;
+
+ public static String LaunchExplorerEditorPage_PageTitle;
+
+ public static String DeleteHandlerDelegate_question_title;
+ public static String DeleteHandlerDelegate_question_message;
+
+ public static String LaunchDialogHandler_dialog_title;
+ public static String LaunchDialogHandler_dialog_message;
+
+ public static String CommonDnD_launchMode_dialog_title;
+ public static String CommonDnD_launchMode_dialog_message;
+ public static String CommonDnD_launchType_dialog_title;
+ public static String CommonDnD_launchType_dialog_message;
+}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.launch.ui/src/org/eclipse/tcf/te/launch/ui/tabs/AbstractLaunchConfigurationTabGroup.java b/target_explorer/plugins/org.eclipse.tcf.te.launch.ui/src/org/eclipse/tcf/te/launch/ui/tabs/AbstractLaunchConfigurationTabGroup.java
index 80c9308c3..a6f1da8b4 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.launch.ui/src/org/eclipse/tcf/te/launch/ui/tabs/AbstractLaunchConfigurationTabGroup.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.launch.ui/src/org/eclipse/tcf/te/launch/ui/tabs/AbstractLaunchConfigurationTabGroup.java
@@ -138,7 +138,8 @@ public abstract class AbstractLaunchConfigurationTabGroup extends org.eclipse.de
String launchMode = getLaunchConfigurationDialog().getMode();
ILaunchSelection launchSelection = LaunchSelectionManager.getInstance().getLaunchSelection(launchConfigType, launchMode, null);
ILaunchManagerDelegate delegate = LaunchManager.getInstance().getLaunchManagerDelegate(launchConfigType, launchMode);
- if (delegate != null && launchSelection != null) {
+ Assert.isNotNull(delegate);
+ if (launchSelection != null) {
// create an empty launch configuration specification to initialize all
// attributes with their default defaults.
ILaunchSpecification launchSpec = delegate.getLaunchSpecification(launchConfigTypeId, launchSelection);
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.launch.ui/src/org/eclipse/tcf/te/launch/ui/tabs/launchcontext/AbstractContextSelectorControl.java b/target_explorer/plugins/org.eclipse.tcf.te.launch.ui/src/org/eclipse/tcf/te/launch/ui/tabs/launchcontext/AbstractContextSelectorControl.java
index ac8e664ac..815520bc5 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.launch.ui/src/org/eclipse/tcf/te/launch/ui/tabs/launchcontext/AbstractContextSelectorControl.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.launch.ui/src/org/eclipse/tcf/te/launch/ui/tabs/launchcontext/AbstractContextSelectorControl.java
@@ -1,896 +1,896 @@
-/*******************************************************************************
- * 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.launchcontext;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
-
-import org.eclipse.core.runtime.Assert;
-import org.eclipse.core.runtime.AssertionFailedException;
-import org.eclipse.jface.dialogs.IDialogPage;
-import org.eclipse.jface.dialogs.IMessageProvider;
-import org.eclipse.jface.viewers.CheckStateChangedEvent;
-import org.eclipse.jface.viewers.CheckboxTreeViewer;
-import org.eclipse.jface.viewers.ICheckStateListener;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.ISelectionChangedListener;
-import org.eclipse.jface.viewers.ISelectionProvider;
-import org.eclipse.jface.viewers.SelectionChangedEvent;
-import org.eclipse.jface.viewers.StructuredSelection;
-import org.eclipse.jface.viewers.TreeViewer;
-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.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.Tree;
-import org.eclipse.swt.widgets.TreeItem;
-import org.eclipse.swt.widgets.Widget;
-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;
-import org.eclipse.tcf.te.runtime.services.ServiceManager;
-import org.eclipse.tcf.te.runtime.services.interfaces.IPropertiesAccessService;
-import org.eclipse.tcf.te.ui.controls.AbstractDecoratedDialogPageControl;
-import org.eclipse.tcf.te.ui.jface.interfaces.IValidatingContainer;
-import org.eclipse.tcf.te.ui.swt.SWTControlUtil;
-import org.eclipse.tcf.te.ui.views.interfaces.ICategory;
-import org.eclipse.ui.dialogs.ContainerCheckedTreeViewer;
-import org.eclipse.ui.navigator.CommonViewerSorter;
-
-/**
- * Abstract 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.
- * <p>
- * Default properties:
- * <ul>
- * <li>PROPERTY_SHOW_GHOST_MODEL_NODES = false</li>
- * <li>PROPERTY_MULTI_CONTEXT_SELECTOR = false</li>
- * </ul>
- */
-public abstract class AbstractContextSelectorControl extends AbstractDecoratedDialogPageControl implements ISelectionProvider {
-
- /**
- * Property: If set to <code>true</code>, ghost model nodes will be shown within the tree.
- */
- public static final String PROPERTY_SHOW_GHOST_MODEL_NODES = "showGhostModelNodes"; //$NON-NLS-1$
-
- /**
- * 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;
-
- /**
- * List of selection changed listeners.
- */
- private final List<ISelectionChangedListener> selectionListeners = new ArrayList<ISelectionChangedListener>();
-
- /**
- * Control properties. See predefined property constants within the class and subclass
- * implementations. Property changes are not notified.
- */
- private final IPropertiesContainer properties = new PropertiesContainer();
-
- // Reference to the tree viewer control used.
- private TreeViewer viewer;
- // The current selection within the tree viewer.
- /* default */ ISelection selection;
-
- /**
- * Constant to return an empty viewer filter array.
- */
- protected final static ViewerFilter[] NO_FILTERS = new ViewerFilter[0];
-
- /**
- * Constant to return an empty selected model context array.
- */
- protected final static IModelNode[] NO_CONTEXTS = new IModelNode[0];
-
- // Currently active set of viewer filters.
- private ViewerFilter[] filters;
- // Currently active checkbox tree viewer check state listener
- private ICheckStateListener listener;
-
- /**
- * Default implementation of the context selector controls tree viewer.
- */
- protected class ContextSelectorTreeViewer extends ContainerCheckedTreeViewer {
-
- /**
- * Constructor.
- *
- * @param parent The parent control.
- * @param style The SWT style bits used to create the tree.
- */
- 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));
- }
-
- /**
- * Constructor.
- *
- * @param parent The parent control.
- */
- public ContextSelectorTreeViewer(Composite parent) {
- super(parent);
- }
-
- /**
- * Constructor.
- *
- * @param tree The tree control.
- */
- public ContextSelectorTreeViewer(Tree tree) {
- super(tree);
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.jface.viewers.TreeViewer#isExpandable(java.lang.Object)
- */
- @Override
- public boolean isExpandable(Object element) {
- boolean expandable = super.isExpandable(element);
- // adjust the expandable state if the element does not have
- // children after the filtering.
- if (expandable) {
- expandable = getFilteredChildren(element).length > 0;
- }
- return expandable;
- }
-
- /**
- * Returns the child items for the given element if any.
- *
- * @param element The element.
- * @return The child items of the element or <code>null</code> if none.
- */
- public Item[] getChildren(Object element) {
- Widget item = findItem(element);
- return getChildren(item);
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.ui.dialogs.ContainerCheckedTreeViewer#doCheckStateChanged(java.lang.Object)
- */
- @Override
- protected void doCheckStateChanged(Object element) {
- // Our ghost model elements requires some special handling, as
- // these elements should be never checked fully. Try to determine
- // if we have to double check on the parents state.
- boolean skipDoubleCheckParentState = false;
-
- // If the element isn't one of our model elements, pass on to
- // to super implementation
- skipDoubleCheckParentState |= !(element instanceof IModelNode);
-
- // If the element is one of our model elements and it is not
- // a ghost node, the parent can't be a ghost node either.
- if (!skipDoubleCheckParentState) {
- skipDoubleCheckParentState |= !isGhost((IModelNode) element);
- }
-
- // If the element is a ghost model element, then we have to check
- // on the parent as well.
- if (!skipDoubleCheckParentState) {
- IPropertiesAccessService service = ServiceManager.getInstance().getService(IPropertiesAccessService.class);
- IModelNode parent = service != null ? (IModelNode)service.getParent(element) : null;
- skipDoubleCheckParentState |= parent == null || !isGhost(parent);
- }
-
- // Call the super implementation to check the item and
- // updating parents and children the first time
- super.doCheckStateChanged(element);
-
- if (!skipDoubleCheckParentState) {
- // Get the tree item for the element and check the parent items
- // for being associated with ghost model elements.
- Widget item = findItem(element);
- if (item instanceof TreeItem) {
- TreeItem treeItem = ((TreeItem) item).getParentItem();
- while (treeItem != null) {
- Object data = treeItem.getData();
-
- // If a child item is checked, otherwise we wouldn't come here, and this
- // parent item isn't expanded, we must(!) expand the item now here by force,
- // otherwise we will loose the checked states of the children elements!
- if (!treeItem.getExpanded()) {
- treeItem.setExpanded(true);
- }
-
- // Decide if we shall gray the checked state.
- // --> The checked state is grayed if the item is a ghost.
- boolean isGhost = data instanceof IModelNode && isGhost((IModelNode) data);
- if (!treeItem.getGrayed() && isGhost) {
- treeItem.setGrayed(true);
- }
-
- // go one level up in the hierarchy
- treeItem = treeItem.getParentItem();
- }
- }
- }
- }
- }
-
- /**
- * Returns if or if not the given model node is a ghost node.
- *
- * @param node The model node. Must not be <code>null</code>.
- * @return <code>True</code> if the node is a ghost node, <code>false</code> otherwise.
- */
- /* default */ boolean isGhost(IModelNode node) {
- Assert.isNotNull(node);
-
- IPropertiesAccessService service = ServiceManager.getInstance().getService(node, IPropertiesAccessService.class);
- if (service != null) {
- Object value = service.getProperty(node, IModelNode.PROPERTY_IS_GHOST);
- if (value instanceof Boolean) {
- return ((Boolean)value).booleanValue();
- } else if (value instanceof String) {
- return Boolean.valueOf((String)value).booleanValue();
- }
- return false;
- }
-
- try {
- return node.isProperty(IModelNode.PROPERTY_IS_GHOST, true);
- } catch (AssertionFailedException e) { /* ignored on purpose */ }
-
- return false;
- }
-
- /**
- * Default implementation of the context selector controls check state listener.
- */
- 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();
- boolean checked = event.getChecked();
-
- onCheckStateChanged(element, checked);
-
- // validate the parent page if there is one set
- if (getParentPage() instanceof IValidatingContainer) {
- ((IValidatingContainer) getParentPage()).validate();
- }
- }
- }
-
- /**
- * Default implementation of the context selector controls viewer filter.
- */
- protected class ContextSelectorViewerFilter extends ViewerFilter {
-
- /**
- * Returns if or if not ghost model elements should be visible within the model context
- * selector controls tree viewer. Default is not to show the ghost model elements.
- *
- * @return <code>True</code> to show the ghost model elements, <code>false</code> otherwise.
- */
- protected boolean doShowGhostModelElements() {
- return getPropertiesContainer().getBooleanProperty(PROPERTY_SHOW_GHOST_MODEL_NODES);
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.jface.viewers.ViewerFilter#select(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
- */
- @Override
- public boolean select(Viewer viewer, Object parentElement, Object element) {
- if (element instanceof ICategory) {
- return true;
- }
- else if (element instanceof IModelNode) {
- if (isGhost((IModelNode) element)) {
- return doShowGhostModelElements();
- }
- return true;
- }
-
- return false;
- }
- }
-
- /**
- * 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 AbstractContextSelectorControl(IDialogPage parentPage) {
- super(parentPage);
- selectionListeners.clear();
- // initialize the properties
- initializeProperties(getPropertiesContainer());
- }
-
- /**
- * Returns the properties container associated with this control.
- *
- * @return The properties container.
- */
- public final IPropertiesContainer getPropertiesContainer() {
- return properties;
- }
-
- /**
- * Initialize the properties associated with this control.
- *
- * @param properties The properties container. Must not be <code>null</code>.
- */
- protected void initializeProperties(IPropertiesContainer properties) {
- Assert.isNotNull(properties);
- properties.setProperty(PROPERTY_SHOW_GHOST_MODEL_NODES, false);
- properties.setProperty(PROPERTY_MULTI_CONTEXT_SELECTOR, false);
- }
-
- /**
- * 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;
- }
-
- /**
- * Returns the default title text which should be used by the enclosing controls or windows if
- * these controls do need to set a title.
- * <p>
- * The default implementation returns <code>null</code>.
- *
- * @return The default title text or <code>null</code> if none.
- */
- public String getDefaultTitle() {
- return null;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.tcf.te.ui.controls.BaseControl#dispose()
- */
- @Override
- public void dispose() {
-
- viewer = null;
-
- super.dispose();
- }
-
- /**
- * Returns the list of checked model node contexts. The elements are in the order they appear
- * within the tree from top to bottom. The client of the control is in charge detecting any type
- * of hierarchy or other relationships between the elements.
- *
- * @return The list of checked model node contexts or an empty list of none.
- */
- public IModelNode[] getCheckedModelContexts() {
- // This method does return something useful only if it is a checkable
- // tree viewer and the check style is set for the tree.
- if (getViewer() instanceof ContainerCheckedTreeViewer && (getTreeViewerStyle() & SWT.CHECK) != 0) {
- ContainerCheckedTreeViewer viewer = (ContainerCheckedTreeViewer) getViewer();
- // Get the list of checked elements. Checked elements includes the grayed elements
- List<?> checked = viewer.getCheckedElements() != null ? Arrays.asList(viewer.getCheckedElements()) : Collections.emptyList();
- // Get the list of grayed elements.
- List<?> grayed = viewer.getGrayedElements() != null ? Arrays.asList(viewer.getGrayedElements()) : Collections.emptyList();
-
- // There must be at least one element checked
- if (!checked.isEmpty()) {
- List<IModelNode> contexts = new ArrayList<IModelNode>();
- for (Object element : checked) {
- // If the context is a model node and the parent container node is fully
- // checked, drop the model node and the use the container node only.
- if (element instanceof IModelNode) {
- IModelNode node = (IModelNode) element;
-
- // Determine the parent node
- IPropertiesAccessService service = ServiceManager.getInstance().getService(node, IPropertiesAccessService.class);
- IModelNode parent = service != null ? (IModelNode)service.getParent(node) : node.getParent();
-
- if (parent != null && checked.contains(parent) && !grayed.contains(parent)) {
- continue;
- }
- }
-
- // If the element is a model node and not grayed,
- // add the element to the list of checked contexts.
- if (element instanceof IModelNode && !grayed.contains(element)) {
- contexts.add((IModelNode) element);
- }
- }
- return contexts.toArray(new IModelNode[contexts.size()]);
- }
- }
- return NO_CONTEXTS;
- }
-
-
- /**
- * Called from the default check state listener implementation if the checked state of an element has changed.
- *
- * @param element The element checked or unchecked. Must not be <code>null</code>.
- * @param checked <code>True</code> if the model node has been checked, <code>false</code> if
- * unchecked.
- */
- protected void onCheckStateChanged(Object element, 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(element);
- 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[] { element });
- }
- }
- }
- }
-
- /**
- * Sets the list of checked model node contexts.
- *
- * @param contexts The list of model node contexts. Must not be <code>null</code>.
- */
- public void setCheckedModelContexts(IModelNode[] contexts) {
- Assert.isNotNull(contexts);
-
- // This method does nothing if the tree viewer isn't a checkable tree viewer.
- if (getViewer() instanceof ContainerCheckedTreeViewer && (getTreeViewerStyle() & SWT.CHECK) != 0) {
- ContainerCheckedTreeViewer viewer = (ContainerCheckedTreeViewer) getViewer();
- // Set the checked elements. This will trigger the validation of the
- // checked state of all the parent and children elements.
- viewer.setCheckedElements(contexts);
- // Make sure that at least the first checked element is visible to the user
- if (contexts.length > 0) {
- viewer.setSelection(new StructuredSelection(contexts[0]), true);
- }
- }
- }
-
- /**
- * Returns the controls associated tree viewer.
- *
- * @return The tree viewer instance or <code>null</code> if not created yet.
- */
- public final TreeViewer getViewer() {
- return viewer;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.tcf.te.ui.controls.BaseControl#setupPanel(org.eclipse.swt.widgets.Composite)
- */
- @Override
- public void setupPanel(Composite parent) {
- super.setupPanel(parent);
-
- // Create the container composite for the tree control.
- Composite composite = doCreateTopContainerComposite(parent);
- Assert.isNotNull(composite);
-
- // Create the viewer
- viewer = createTreeViewerControl(composite);
-
- // And now configure the listeners
- configureControlListener();
-
- // Trigger a selection changed event to give listeners
- // a chance to initialize their enabled state correctly
- viewer.setSelection(viewer.getSelection());
- }
-
- /**
- * Create the top container composite.
- *
- * @param parent The parent composite. Must not be <code>null</code>.
- * @return The top container composite. Must not be <code>null</code>.
- */
- protected Composite doCreateTopContainerComposite(Composite parent) {
- Assert.isNotNull(parent);
-
- // Set the default layout data attributes for the composite
- int style = GridData.FILL_BOTH;
- int heightHint = SWT.DEFAULT;
-
- // Fallback to standard non-form controls and create a composite which extends
- // in both directions and has no margins
- Composite composite = new Composite(parent, SWT.NONE);
- GridLayout layout = new GridLayout();
- layout.marginHeight = 0;
- layout.marginWidth = 0;
- composite.setLayout(layout);
- GridData layoutData = new GridData(style);
- layoutData.heightHint = heightHint;
- composite.setLayoutData(layoutData);
-
- return composite;
- }
-
- /**
- * Creates the tree viewer control. Override to return a custom tree viewer implementation.
- *
- * @param parent The parent composite of the tree viewer. Must not be <code>null</code>.
- * @return The tree viewer control. Must be never <code>null</code>.
- */
- protected TreeViewer createTreeViewerControl(Composite parent) {
- Assert.isNotNull(parent);
-
- CheckboxTreeViewer viewer = doCreateNewTreeViewerControl(parent, getTreeViewerStyle());
- doConfigureTreeViewerControl(viewer);
-
- viewer.setInput(getInitialViewerInput());
- doEnableControl(viewer);
-
- return viewer;
- }
-
- /**
- * Creates a new instance of the tree viewer control to use. This method will be called from
- * {@link #createTreeViewerControl(Composite)} if creating the tree viewer instance.
- *
- * @param parent The parent composite of the tree viewer. Must not be <code>null</code>.
- * @param style The SWT style bits.
- *
- * @return The tree viewer instance. Must not be <code>null</code>.
- */
- protected CheckboxTreeViewer doCreateNewTreeViewerControl(Composite parent, int style) {
- return new ContextSelectorTreeViewer(parent, style);
- }
-
- /**
- * Configure the tree viewer control.
- *
- * @param viewer The tree viewer instance. Must not be <code>null</code>.
- */
- protected void doConfigureTreeViewerControl(CheckboxTreeViewer viewer) {
- Assert.isNotNull(viewer);
-
- viewer.setUseHashlookup(true);
-
- doConfigureTreeLayoutData(viewer.getTree());
- doConfigureTreeContentAndLabelProvider(viewer);
- viewer.setSorter(doCreateViewerSorter());
-
- if ((getTreeViewerStyle() & SWT.CHECK) != 0 && getViewerCheckStateListener(viewer) != null) {
- viewer.addCheckStateListener(getViewerCheckStateListener(viewer));
- }
-
- if (hasViewerFilters()) {
- viewer.setFilters(getViewerFilters());
- }
- viewer.addSelectionChangedListener(new ISelectionChangedListener() {
- @Override
- public void selectionChanged(SelectionChangedEvent event) {
- selection = event.getSelection();
- fireSelectionChanged();
- }
- });
- doCreateControlDecoration(viewer.getTree());
- }
-
- /**
- * Configure the tree's layout data. The layout data set to the tree must be of type
- * <code>GridData</code>.
- *
- * @param tree The tree to configure. Must not be <code>null</code>.
- */
- protected void doConfigureTreeLayoutData(Tree tree) {
- GridData layoutData = new GridData(GridData.FILL_HORIZONTAL);
- layoutData.heightHint = 150;
- tree.setLayoutData(layoutData);
- }
-
- /**
- * Returns the style bits to apply to the tree viewer.
- * <p>
- * The default set tree viewer style bits are:
- * <ul>
- * <li>SWT.SINGLE</li>
- * <li>SWT.H_SCROLL</li>
- * <li>SWT.V_SCROLL</li>
- * <li>SWT.BORDER</li>
- *
- * @return The style bits to apply to the tree viewer.
- */
- protected int getTreeViewerStyle() {
- return SWT.CHECK | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER | SWT.MULTI;
- }
-
- /**
- * Creates the viewer sorter instance to associated to the controls tree viewer.
- *
- * @return The viewer sorter to associate or <code>null</code> if none.
- */
- protected ViewerSorter doCreateViewerSorter() {
- return new CommonViewerSorter();
- }
-
- /**
- * Returns if or if not to associate viewer filters to the controls tree viewer. If this method
- * returns <code>true</code>, {@link #doCreateViewerFilters()} must return not null!
- *
- * @return <code>True</code> if to associate viewer filters, <code>false</code> otherwise.
- */
- protected boolean hasViewerFilters() {
- return true;
- }
-
- /**
- * Creates a returns a new set of the viewer filters to associated to the controls tree viewer.
- * This method will be called from {@link #getViewerFilters()} in case the method
- * {@link #hasViewerFilters()} returns <code>true</code> and no viewer filters got created
- * before.
- *
- * @return The viewer filters to associate or <code>null</code> if none.
- */
- protected ViewerFilter[] doCreateViewerFilters() {
- return new ViewerFilter[] { new ContextSelectorViewerFilter() };
- }
-
- /**
- * Returns the associated viewer filters of the controls tree viewer. If the control does have
- * viewer filters ({@link #hasViewerFilters()} returns <code>true</code>) and the viewer filters
- * had not yet been created, the method calls {@link #doCreateViewerFilters()}.
- *
- * @return The associated viewer filters of the controls tree viewer or the constant
- * {@link #NO_FILTERS}.
- */
- protected ViewerFilter[] getViewerFilters() {
- if (filters == null && hasViewerFilters()) {
- filters = doCreateViewerFilters();
- }
- return filters != null ? filters : NO_FILTERS;
- }
-
- /**
- * Creates a new checkbox tree viewer check state listener. This method will be called from
- * {@link #getViewerCheckStateListener()} in case the listener did not got created before.
- *
- * @param viewer The checkbox tree viewer. Must not be <code>null</code>.
- * @return The checkbox tree viewer check state listener or <code>null</code> if none.
- */
- protected ICheckStateListener doCreateViewerCheckStateListener(CheckboxTreeViewer viewer) {
- Assert.isNotNull(viewer);
- return new ContextSelectedCheckStateListener();
- }
-
- /**
- * Returns the associated checkbox tree viewer check state listener. If the listener had not yet
- * been created, the method calls {@link #doCreateLabelProvider()}.
- *
- * @param viewer The checkbox tree viewer. Must not be <code>null</code>.
- * @return The associated checkbox tree viewer check state listener or <code>null</code> if
- * none.
- */
- protected ICheckStateListener getViewerCheckStateListener(CheckboxTreeViewer viewer) {
- Assert.isNotNull(viewer);
- if (listener == null) {
- listener = doCreateViewerCheckStateListener(viewer);
- }
- return listener;
- }
-
- /**
- * Returns the initial input object to set to the controls tree viewer.
- *
- * @return The initial viewer input to set or <code>null</code> if none.
- */
- protected abstract Object getInitialViewerInput();
-
- /**
- * Configure content and label provider.
- * @param viewer The tree viewer.
- */
- protected abstract void doConfigureTreeContentAndLabelProvider(TreeViewer viewer);
-
- /**
- * Enables the tree control.
- *
- * @param viewer The tree viewer object. Must not be <code>null</code>.
- */
- protected void doEnableControl(TreeViewer viewer) {
- Assert.isNotNull(viewer);
- SWTControlUtil.setEnabled(viewer.getTree(), viewer.getTree().getItemCount() > 0);
- }
-
- /**
- * Refresh the controls viewer and check the viewers enablement. This method is called by the
- * standard refresh toolbar item, if the control has a toolbar.
- */
- public void refresh() {
- if (viewer != null && viewer.getControl() != null && !viewer.getControl().isDisposed()) {
- viewer.refresh(true);
- doEnableControl(viewer);
- }
- }
-
- /**
- * 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.
- */
- protected void configureControlListener() {
- }
-
- /**
- * Sets the given selection to the viewer.
- *
- * @param selection The selection to set. Must not be <code>null</code>.
- */
- @Override
- public void setSelection(ISelection selection) {
- Assert.isNotNull(selection);
- this.selection = selection;
- if (viewer != null) {
- viewer.setSelection(selection, true);
- }
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.jface.viewers.ISelectionProvider#getSelection()
- */
- @Override
- public ISelection getSelection() {
- return selection;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.jface.viewers.ISelectionProvider#addSelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener)
- */
- @Override
- public void addSelectionChangedListener(ISelectionChangedListener listener) {
- if (listener != null && !selectionListeners.contains(listener)) {
- selectionListeners.add(listener);
- }
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.jface.viewers.ISelectionProvider#removeSelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener)
- */
- @Override
- public void removeSelectionChangedListener(ISelectionChangedListener listener) {
- if (listener != null) {
- selectionListeners.remove(listener);
- }
- }
-
- /**
- * Fire the selection changed event to the registered listeners.
- */
- /* default */ void fireSelectionChanged() {
- if (selection != null) {
- SelectionChangedEvent event = new SelectionChangedEvent(this, selection);
- for (ISelectionChangedListener listener : selectionListeners) {
- listener.selectionChanged(event);
- }
- }
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.tcf.te.ui.controls.BaseControl#isValid()
- */
- @Override
- public boolean isValid() {
- boolean valid = super.isValid();
- if (!valid) return valid;
-
- // 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) {
- int count = getCheckedModelContexts().length;
- valid = count == 1 || (count > 1 && getPropertiesContainer().isProperty(PROPERTY_MULTI_CONTEXT_SELECTOR, true));
-
- // 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));
- }
- }
-
- if (getControlDecoration() != null) {
- // Setup and show the control decoration if necessary
- if (isEnabled() && (!valid || (getMessage() != null && getMessageType() != IMessageProvider.NONE))) {
- // Update the control decorator
- updateControlDecoration(getMessage(), getMessageType());
- } else {
- updateControlDecoration(null, IMessageProvider.NONE);
- }
- }
-
-
- 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 not be <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 not be <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;
- }
-}
+/*******************************************************************************
+ * 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.launchcontext;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.core.runtime.AssertionFailedException;
+import org.eclipse.jface.dialogs.IDialogPage;
+import org.eclipse.jface.dialogs.IMessageProvider;
+import org.eclipse.jface.viewers.CheckStateChangedEvent;
+import org.eclipse.jface.viewers.CheckboxTreeViewer;
+import org.eclipse.jface.viewers.ICheckStateListener;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.ISelectionProvider;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.viewers.TreeViewer;
+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.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.Tree;
+import org.eclipse.swt.widgets.TreeItem;
+import org.eclipse.swt.widgets.Widget;
+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;
+import org.eclipse.tcf.te.runtime.services.ServiceManager;
+import org.eclipse.tcf.te.runtime.services.interfaces.IPropertiesAccessService;
+import org.eclipse.tcf.te.ui.controls.AbstractDecoratedDialogPageControl;
+import org.eclipse.tcf.te.ui.jface.interfaces.IValidatingContainer;
+import org.eclipse.tcf.te.ui.swt.SWTControlUtil;
+import org.eclipse.tcf.te.ui.views.interfaces.ICategory;
+import org.eclipse.ui.dialogs.ContainerCheckedTreeViewer;
+import org.eclipse.ui.navigator.CommonViewerSorter;
+
+/**
+ * Abstract 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.
+ * <p>
+ * Default properties:
+ * <ul>
+ * <li>PROPERTY_SHOW_GHOST_MODEL_NODES = false</li>
+ * <li>PROPERTY_MULTI_CONTEXT_SELECTOR = false</li>
+ * </ul>
+ */
+public abstract class AbstractContextSelectorControl extends AbstractDecoratedDialogPageControl implements ISelectionProvider {
+
+ /**
+ * Property: If set to <code>true</code>, ghost model nodes will be shown within the tree.
+ */
+ public static final String PROPERTY_SHOW_GHOST_MODEL_NODES = "showGhostModelNodes"; //$NON-NLS-1$
+
+ /**
+ * 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;
+
+ /**
+ * List of selection changed listeners.
+ */
+ private final List<ISelectionChangedListener> selectionListeners = new ArrayList<ISelectionChangedListener>();
+
+ /**
+ * Control properties. See predefined property constants within the class and subclass
+ * implementations. Property changes are not notified.
+ */
+ private final IPropertiesContainer properties = new PropertiesContainer();
+
+ // Reference to the tree viewer control used.
+ private TreeViewer viewer;
+ // The current selection within the tree viewer.
+ /* default */ ISelection selection;
+
+ /**
+ * Constant to return an empty viewer filter array.
+ */
+ protected final static ViewerFilter[] NO_FILTERS = new ViewerFilter[0];
+
+ /**
+ * Constant to return an empty selected model context array.
+ */
+ protected final static IModelNode[] NO_CONTEXTS = new IModelNode[0];
+
+ // Currently active set of viewer filters.
+ private ViewerFilter[] filters;
+ // Currently active checkbox tree viewer check state listener
+ private ICheckStateListener listener;
+
+ /**
+ * Default implementation of the context selector controls tree viewer.
+ */
+ protected class ContextSelectorTreeViewer extends ContainerCheckedTreeViewer {
+
+ /**
+ * Constructor.
+ *
+ * @param parent The parent control.
+ * @param style The SWT style bits used to create the tree.
+ */
+ 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));
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param parent The parent control.
+ */
+ public ContextSelectorTreeViewer(Composite parent) {
+ super(parent);
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param tree The tree control.
+ */
+ public ContextSelectorTreeViewer(Tree tree) {
+ super(tree);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.viewers.TreeViewer#isExpandable(java.lang.Object)
+ */
+ @Override
+ public boolean isExpandable(Object element) {
+ boolean expandable = super.isExpandable(element);
+ // adjust the expandable state if the element does not have
+ // children after the filtering.
+ if (expandable) {
+ expandable = getFilteredChildren(element).length > 0;
+ }
+ return expandable;
+ }
+
+ /**
+ * Returns the child items for the given element if any.
+ *
+ * @param element The element.
+ * @return The child items of the element or <code>null</code> if none.
+ */
+ public Item[] getChildren(Object element) {
+ Widget item = findItem(element);
+ return getChildren(item);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.dialogs.ContainerCheckedTreeViewer#doCheckStateChanged(java.lang.Object)
+ */
+ @Override
+ protected void doCheckStateChanged(Object element) {
+ // Our ghost model elements requires some special handling, as
+ // these elements should be never checked fully. Try to determine
+ // if we have to double check on the parents state.
+ boolean skipDoubleCheckParentState = false;
+
+ // If the element isn't one of our model elements, pass on to
+ // to super implementation
+ skipDoubleCheckParentState |= !(element instanceof IModelNode);
+
+ // If the element is one of our model elements and it is not
+ // a ghost node, the parent can't be a ghost node either.
+ if (!skipDoubleCheckParentState) {
+ skipDoubleCheckParentState |= !isGhost((IModelNode) element);
+ }
+
+ // If the element is a ghost model element, then we have to check
+ // on the parent as well.
+ if (!skipDoubleCheckParentState) {
+ IPropertiesAccessService service = ServiceManager.getInstance().getService(IPropertiesAccessService.class);
+ IModelNode parent = service != null ? (IModelNode)service.getParent(element) : null;
+ skipDoubleCheckParentState |= parent == null || !isGhost(parent);
+ }
+
+ // Call the super implementation to check the item and
+ // updating parents and children the first time
+ super.doCheckStateChanged(element);
+
+ if (!skipDoubleCheckParentState) {
+ // Get the tree item for the element and check the parent items
+ // for being associated with ghost model elements.
+ Widget item = findItem(element);
+ if (item instanceof TreeItem) {
+ TreeItem treeItem = ((TreeItem) item).getParentItem();
+ while (treeItem != null) {
+ Object data = treeItem.getData();
+
+ // If a child item is checked, otherwise we wouldn't come here, and this
+ // parent item isn't expanded, we must(!) expand the item now here by force,
+ // otherwise we will loose the checked states of the children elements!
+ if (!treeItem.getExpanded()) {
+ treeItem.setExpanded(true);
+ }
+
+ // Decide if we shall gray the checked state.
+ // --> The checked state is grayed if the item is a ghost.
+ boolean isGhost = data instanceof IModelNode && isGhost((IModelNode) data);
+ if (!treeItem.getGrayed() && isGhost) {
+ treeItem.setGrayed(true);
+ }
+
+ // go one level up in the hierarchy
+ treeItem = treeItem.getParentItem();
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * Returns if or if not the given model node is a ghost node.
+ *
+ * @param node The model node. Must not be <code>null</code>.
+ * @return <code>True</code> if the node is a ghost node, <code>false</code> otherwise.
+ */
+ /* default */ boolean isGhost(IModelNode node) {
+ Assert.isNotNull(node);
+
+ IPropertiesAccessService service = ServiceManager.getInstance().getService(node, IPropertiesAccessService.class);
+ if (service != null) {
+ Object value = service.getProperty(node, IModelNode.PROPERTY_IS_GHOST);
+ if (value instanceof Boolean) {
+ return ((Boolean)value).booleanValue();
+ } else if (value instanceof String) {
+ return Boolean.valueOf((String)value).booleanValue();
+ }
+ return false;
+ }
+
+ try {
+ return node.isProperty(IModelNode.PROPERTY_IS_GHOST, true);
+ } catch (AssertionFailedException e) { /* ignored on purpose */ }
+
+ return false;
+ }
+
+ /**
+ * Default implementation of the context selector controls check state listener.
+ */
+ 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();
+ boolean checked = event.getChecked();
+
+ onCheckStateChanged(element, checked);
+
+ // validate the parent page if there is one set
+ if (getParentPage() instanceof IValidatingContainer) {
+ ((IValidatingContainer) getParentPage()).validate();
+ }
+ }
+ }
+
+ /**
+ * Default implementation of the context selector controls viewer filter.
+ */
+ protected class ContextSelectorViewerFilter extends ViewerFilter {
+
+ /**
+ * Returns if or if not ghost model elements should be visible within the model context
+ * selector controls tree viewer. Default is not to show the ghost model elements.
+ *
+ * @return <code>True</code> to show the ghost model elements, <code>false</code> otherwise.
+ */
+ protected boolean doShowGhostModelElements() {
+ return getPropertiesContainer().getBooleanProperty(PROPERTY_SHOW_GHOST_MODEL_NODES);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.viewers.ViewerFilter#select(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
+ */
+ @Override
+ public boolean select(Viewer viewer, Object parentElement, Object element) {
+ if (element instanceof ICategory) {
+ return true;
+ }
+ else if (element instanceof IModelNode) {
+ if (isGhost((IModelNode) element)) {
+ return doShowGhostModelElements();
+ }
+ return true;
+ }
+
+ return false;
+ }
+ }
+
+ /**
+ * 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 AbstractContextSelectorControl(IDialogPage parentPage) {
+ super(parentPage);
+ selectionListeners.clear();
+ // initialize the properties
+ initializeProperties(getPropertiesContainer());
+ }
+
+ /**
+ * Returns the properties container associated with this control.
+ *
+ * @return The properties container.
+ */
+ public final IPropertiesContainer getPropertiesContainer() {
+ return properties;
+ }
+
+ /**
+ * Initialize the properties associated with this control.
+ *
+ * @param properties The properties container. Must not be <code>null</code>.
+ */
+ protected void initializeProperties(IPropertiesContainer properties) {
+ Assert.isNotNull(properties);
+ properties.setProperty(PROPERTY_SHOW_GHOST_MODEL_NODES, false);
+ properties.setProperty(PROPERTY_MULTI_CONTEXT_SELECTOR, false);
+ }
+
+ /**
+ * 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;
+ }
+
+ /**
+ * Returns the default title text which should be used by the enclosing controls or windows if
+ * these controls do need to set a title.
+ * <p>
+ * The default implementation returns <code>null</code>.
+ *
+ * @return The default title text or <code>null</code> if none.
+ */
+ public String getDefaultTitle() {
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.ui.controls.BaseControl#dispose()
+ */
+ @Override
+ public void dispose() {
+
+ viewer = null;
+
+ super.dispose();
+ }
+
+ /**
+ * Returns the list of checked model node contexts. The elements are in the order they appear
+ * within the tree from top to bottom. The client of the control is in charge detecting any type
+ * of hierarchy or other relationships between the elements.
+ *
+ * @return The list of checked model node contexts or an empty list of none.
+ */
+ public IModelNode[] getCheckedModelContexts() {
+ // This method does return something useful only if it is a checkable
+ // tree viewer and the check style is set for the tree.
+ if (getViewer() instanceof ContainerCheckedTreeViewer && (getTreeViewerStyle() & SWT.CHECK) != 0) {
+ ContainerCheckedTreeViewer viewer = (ContainerCheckedTreeViewer) getViewer();
+ // Get the list of checked elements. Checked elements includes the grayed elements
+ List<?> checked = viewer.getCheckedElements() != null ? Arrays.asList(viewer.getCheckedElements()) : Collections.emptyList();
+ // Get the list of grayed elements.
+ List<?> grayed = viewer.getGrayedElements() != null ? Arrays.asList(viewer.getGrayedElements()) : Collections.emptyList();
+
+ // There must be at least one element checked
+ if (!checked.isEmpty()) {
+ List<IModelNode> contexts = new ArrayList<IModelNode>();
+ for (Object element : checked) {
+ // If the context is a model node and the parent container node is fully
+ // checked, drop the model node and the use the container node only.
+ if (element instanceof IModelNode) {
+ IModelNode node = (IModelNode) element;
+
+ // Determine the parent node
+ IPropertiesAccessService service = ServiceManager.getInstance().getService(node, IPropertiesAccessService.class);
+ IModelNode parent = service != null ? (IModelNode)service.getParent(node) : node.getParent();
+
+ if (parent != null && checked.contains(parent) && !grayed.contains(parent)) {
+ continue;
+ }
+ }
+
+ // If the element is a model node and not grayed,
+ // add the element to the list of checked contexts.
+ if (element instanceof IModelNode && !grayed.contains(element)) {
+ contexts.add((IModelNode) element);
+ }
+ }
+ return contexts.toArray(new IModelNode[contexts.size()]);
+ }
+ }
+ return NO_CONTEXTS;
+ }
+
+
+ /**
+ * Called from the default check state listener implementation if the checked state of an element has changed.
+ *
+ * @param element The element checked or unchecked. Must not be <code>null</code>.
+ * @param checked <code>True</code> if the model node has been checked, <code>false</code> if
+ * unchecked.
+ */
+ protected void onCheckStateChanged(Object element, 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(element);
+ 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[] { element });
+ }
+ }
+ }
+ }
+
+ /**
+ * Sets the list of checked model node contexts.
+ *
+ * @param contexts The list of model node contexts. Must not be <code>null</code>.
+ */
+ public void setCheckedModelContexts(IModelNode[] contexts) {
+ Assert.isNotNull(contexts);
+
+ // This method does nothing if the tree viewer isn't a checkable tree viewer.
+ if (getViewer() instanceof ContainerCheckedTreeViewer && (getTreeViewerStyle() & SWT.CHECK) != 0) {
+ ContainerCheckedTreeViewer viewer = (ContainerCheckedTreeViewer) getViewer();
+ // Set the checked elements. This will trigger the validation of the
+ // checked state of all the parent and children elements.
+ viewer.setCheckedElements(contexts);
+ // Make sure that at least the first checked element is visible to the user
+ if (contexts.length > 0) {
+ viewer.setSelection(new StructuredSelection(contexts[0]), true);
+ }
+ }
+ }
+
+ /**
+ * Returns the controls associated tree viewer.
+ *
+ * @return The tree viewer instance or <code>null</code> if not created yet.
+ */
+ public final TreeViewer getViewer() {
+ return viewer;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.ui.controls.BaseControl#setupPanel(org.eclipse.swt.widgets.Composite)
+ */
+ @Override
+ public void setupPanel(Composite parent) {
+ super.setupPanel(parent);
+
+ // Create the container composite for the tree control.
+ Composite composite = doCreateTopContainerComposite(parent);
+ Assert.isNotNull(composite);
+
+ // Create the viewer
+ viewer = createTreeViewerControl(composite);
+
+ // And now configure the listeners
+ configureControlListener();
+
+ // Trigger a selection changed event to give listeners
+ // a chance to initialize their enabled state correctly
+ viewer.setSelection(viewer.getSelection());
+ }
+
+ /**
+ * Create the top container composite.
+ *
+ * @param parent The parent composite. Must not be <code>null</code>.
+ * @return The top container composite. Must not be <code>null</code>.
+ */
+ protected Composite doCreateTopContainerComposite(Composite parent) {
+ Assert.isNotNull(parent);
+
+ // Set the default layout data attributes for the composite
+ int style = GridData.FILL_BOTH;
+ int heightHint = SWT.DEFAULT;
+
+ // Fallback to standard non-form controls and create a composite which extends
+ // in both directions and has no margins
+ Composite composite = new Composite(parent, SWT.NONE);
+ GridLayout layout = new GridLayout();
+ layout.marginHeight = 0;
+ layout.marginWidth = 0;
+ composite.setLayout(layout);
+ GridData layoutData = new GridData(style);
+ layoutData.heightHint = heightHint;
+ composite.setLayoutData(layoutData);
+
+ return composite;
+ }
+
+ /**
+ * Creates the tree viewer control. Override to return a custom tree viewer implementation.
+ *
+ * @param parent The parent composite of the tree viewer. Must not be <code>null</code>.
+ * @return The tree viewer control. Must be never <code>null</code>.
+ */
+ protected TreeViewer createTreeViewerControl(Composite parent) {
+ Assert.isNotNull(parent);
+
+ CheckboxTreeViewer viewer = doCreateNewTreeViewerControl(parent, getTreeViewerStyle());
+ doConfigureTreeViewerControl(viewer);
+
+ viewer.setInput(getInitialViewerInput());
+ doEnableControl(viewer);
+
+ return viewer;
+ }
+
+ /**
+ * Creates a new instance of the tree viewer control to use. This method will be called from
+ * {@link #createTreeViewerControl(Composite)} if creating the tree viewer instance.
+ *
+ * @param parent The parent composite of the tree viewer. Must not be <code>null</code>.
+ * @param style The SWT style bits.
+ *
+ * @return The tree viewer instance. Must not be <code>null</code>.
+ */
+ protected CheckboxTreeViewer doCreateNewTreeViewerControl(Composite parent, int style) {
+ return new ContextSelectorTreeViewer(parent, style);
+ }
+
+ /**
+ * Configure the tree viewer control.
+ *
+ * @param viewer The tree viewer instance. Must not be <code>null</code>.
+ */
+ protected void doConfigureTreeViewerControl(CheckboxTreeViewer viewer) {
+ Assert.isNotNull(viewer);
+
+ viewer.setUseHashlookup(true);
+
+ doConfigureTreeLayoutData(viewer.getTree());
+ doConfigureTreeContentAndLabelProvider(viewer);
+ viewer.setSorter(doCreateViewerSorter());
+
+ if ((getTreeViewerStyle() & SWT.CHECK) != 0 && getViewerCheckStateListener(viewer) != null) {
+ viewer.addCheckStateListener(getViewerCheckStateListener(viewer));
+ }
+
+ if (hasViewerFilters()) {
+ viewer.setFilters(getViewerFilters());
+ }
+ viewer.addSelectionChangedListener(new ISelectionChangedListener() {
+ @Override
+ public void selectionChanged(SelectionChangedEvent event) {
+ selection = event.getSelection();
+ fireSelectionChanged();
+ }
+ });
+ doCreateControlDecoration(viewer.getTree());
+ }
+
+ /**
+ * Configure the tree's layout data. The layout data set to the tree must be of type
+ * <code>GridData</code>.
+ *
+ * @param tree The tree to configure. Must not be <code>null</code>.
+ */
+ protected void doConfigureTreeLayoutData(Tree tree) {
+ GridData layoutData = new GridData(GridData.FILL_HORIZONTAL);
+ layoutData.heightHint = 150;
+ tree.setLayoutData(layoutData);
+ }
+
+ /**
+ * Returns the style bits to apply to the tree viewer.
+ * <p>
+ * The default set tree viewer style bits are:
+ * <ul>
+ * <li>SWT.SINGLE</li>
+ * <li>SWT.H_SCROLL</li>
+ * <li>SWT.V_SCROLL</li>
+ * <li>SWT.BORDER</li>
+ *
+ * @return The style bits to apply to the tree viewer.
+ */
+ protected int getTreeViewerStyle() {
+ return SWT.CHECK | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER | SWT.MULTI;
+ }
+
+ /**
+ * Creates the viewer sorter instance to associated to the controls tree viewer.
+ *
+ * @return The viewer sorter to associate or <code>null</code> if none.
+ */
+ protected ViewerSorter doCreateViewerSorter() {
+ return new CommonViewerSorter();
+ }
+
+ /**
+ * Returns if or if not to associate viewer filters to the controls tree viewer. If this method
+ * returns <code>true</code>, {@link #doCreateViewerFilters()} must return not null!
+ *
+ * @return <code>True</code> if to associate viewer filters, <code>false</code> otherwise.
+ */
+ protected boolean hasViewerFilters() {
+ return true;
+ }
+
+ /**
+ * Creates a returns a new set of the viewer filters to associated to the controls tree viewer.
+ * This method will be called from {@link #getViewerFilters()} in case the method
+ * {@link #hasViewerFilters()} returns <code>true</code> and no viewer filters got created
+ * before.
+ *
+ * @return The viewer filters to associate or <code>null</code> if none.
+ */
+ protected ViewerFilter[] doCreateViewerFilters() {
+ return new ViewerFilter[] { new ContextSelectorViewerFilter() };
+ }
+
+ /**
+ * Returns the associated viewer filters of the controls tree viewer. If the control does have
+ * viewer filters ({@link #hasViewerFilters()} returns <code>true</code>) and the viewer filters
+ * had not yet been created, the method calls {@link #doCreateViewerFilters()}.
+ *
+ * @return The associated viewer filters of the controls tree viewer or the constant
+ * {@link #NO_FILTERS}.
+ */
+ protected ViewerFilter[] getViewerFilters() {
+ if (filters == null && hasViewerFilters()) {
+ filters = doCreateViewerFilters();
+ }
+ return filters != null ? filters : NO_FILTERS;
+ }
+
+ /**
+ * Creates a new checkbox tree viewer check state listener. This method will be called from
+ * {@link #getViewerCheckStateListener()} in case the listener did not got created before.
+ *
+ * @param viewer The checkbox tree viewer. Must not be <code>null</code>.
+ * @return The checkbox tree viewer check state listener or <code>null</code> if none.
+ */
+ protected ICheckStateListener doCreateViewerCheckStateListener(CheckboxTreeViewer viewer) {
+ Assert.isNotNull(viewer);
+ return new ContextSelectedCheckStateListener();
+ }
+
+ /**
+ * Returns the associated checkbox tree viewer check state listener. If the listener had not yet
+ * been created, the method calls {@link #doCreateLabelProvider()}.
+ *
+ * @param viewer The checkbox tree viewer. Must not be <code>null</code>.
+ * @return The associated checkbox tree viewer check state listener or <code>null</code> if
+ * none.
+ */
+ protected ICheckStateListener getViewerCheckStateListener(CheckboxTreeViewer viewer) {
+ Assert.isNotNull(viewer);
+ if (listener == null) {
+ listener = doCreateViewerCheckStateListener(viewer);
+ }
+ return listener;
+ }
+
+ /**
+ * Returns the initial input object to set to the controls tree viewer.
+ *
+ * @return The initial viewer input to set or <code>null</code> if none.
+ */
+ protected abstract Object getInitialViewerInput();
+
+ /**
+ * Configure content and label provider.
+ * @param viewer The tree viewer.
+ */
+ protected abstract void doConfigureTreeContentAndLabelProvider(TreeViewer viewer);
+
+ /**
+ * Enables the tree control.
+ *
+ * @param viewer The tree viewer object. Must not be <code>null</code>.
+ */
+ protected void doEnableControl(TreeViewer viewer) {
+ Assert.isNotNull(viewer);
+ SWTControlUtil.setEnabled(viewer.getTree(), viewer.getTree().getItemCount() > 0);
+ }
+
+ /**
+ * Refresh the controls viewer and check the viewers enablement. This method is called by the
+ * standard refresh toolbar item, if the control has a toolbar.
+ */
+ public void refresh() {
+ if (viewer != null && viewer.getControl() != null && !viewer.getControl().isDisposed()) {
+ viewer.refresh(true);
+ doEnableControl(viewer);
+ }
+ }
+
+ /**
+ * 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.
+ */
+ protected void configureControlListener() {
+ }
+
+ /**
+ * Sets the given selection to the viewer.
+ *
+ * @param selection The selection to set. Must not be <code>null</code>.
+ */
+ @Override
+ public void setSelection(ISelection selection) {
+ Assert.isNotNull(selection);
+ this.selection = selection;
+ if (viewer != null) {
+ viewer.setSelection(selection, true);
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.viewers.ISelectionProvider#getSelection()
+ */
+ @Override
+ public ISelection getSelection() {
+ return selection;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.viewers.ISelectionProvider#addSelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener)
+ */
+ @Override
+ public void addSelectionChangedListener(ISelectionChangedListener listener) {
+ if (listener != null && !selectionListeners.contains(listener)) {
+ selectionListeners.add(listener);
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.viewers.ISelectionProvider#removeSelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener)
+ */
+ @Override
+ public void removeSelectionChangedListener(ISelectionChangedListener listener) {
+ if (listener != null) {
+ selectionListeners.remove(listener);
+ }
+ }
+
+ /**
+ * Fire the selection changed event to the registered listeners.
+ */
+ /* default */ void fireSelectionChanged() {
+ if (selection != null) {
+ SelectionChangedEvent event = new SelectionChangedEvent(this, selection);
+ for (ISelectionChangedListener listener : selectionListeners) {
+ listener.selectionChanged(event);
+ }
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.ui.controls.BaseControl#isValid()
+ */
+ @Override
+ public boolean isValid() {
+ boolean valid = super.isValid();
+ if (!valid) return valid;
+
+ // 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) {
+ int count = getCheckedModelContexts().length;
+ valid = count == 1 || (count > 1 && getPropertiesContainer().isProperty(PROPERTY_MULTI_CONTEXT_SELECTOR, true));
+
+ // 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));
+ }
+ }
+
+ if (getControlDecoration() != null) {
+ // Setup and show the control decoration if necessary
+ if (isEnabled() && (!valid || (getMessage() != null && getMessageType() != IMessageProvider.NONE))) {
+ // Update the control decorator
+ updateControlDecoration(getMessage(), getMessageType());
+ } else {
+ updateControlDecoration(null, IMessageProvider.NONE);
+ }
+ }
+
+
+ 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 not be <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 not be <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.runtime.services/src/org/eclipse/tcf/te/runtime/services/AbstractServiceManager.java b/target_explorer/plugins/org.eclipse.tcf.te.runtime.services/src/org/eclipse/tcf/te/runtime/services/AbstractServiceManager.java
index 8cdf00fd9..1de409e6e 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.runtime.services/src/org/eclipse/tcf/te/runtime/services/AbstractServiceManager.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.runtime.services/src/org/eclipse/tcf/te/runtime/services/AbstractServiceManager.java
@@ -351,7 +351,7 @@ public abstract class AbstractServiceManager {
Assert.isNotNull(serviceType);
Collection<ServiceProxy> proxies = services.values();
- if (proxies != null && !proxies.isEmpty()) {
+ if (!proxies.isEmpty()) {
List<ServiceProxy> candidates = new ArrayList<ServiceProxy>();
boolean isInterface = serviceType.isInterface();
for (ServiceProxy proxy : proxies) {
@@ -391,7 +391,7 @@ public abstract class AbstractServiceManager {
Collection<ServiceProxy> proxies = services.values();
List<IService> services = new ArrayList<IService>();
- if (proxies != null && !proxies.isEmpty()) {
+ if (!proxies.isEmpty()) {
List<ServiceProxy> candidates = new ArrayList<ServiceProxy>();
for (ServiceProxy proxy : proxies) {
if (proxy.isMatching(serviceType) && proxy.isEnabled(context)) {
@@ -433,7 +433,7 @@ public abstract class AbstractServiceManager {
// Get all service contributions
Collection<ServiceProxy> proxies = services.values();
- if (proxies != null && !proxies.isEmpty()) {
+ if (!proxies.isEmpty()) {
for (ServiceProxy proxy : proxies) {
if (proxy.isMatching(serviceTypeName) && proxy.isEnabled(context)) {
return true;
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.runtime/src/org/eclipse/tcf/te/runtime/processes/ProcessOutputReaderThread.java b/target_explorer/plugins/org.eclipse.tcf.te.runtime/src/org/eclipse/tcf/te/runtime/processes/ProcessOutputReaderThread.java
index e9f7ecb5f..e41f69cc3 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.runtime/src/org/eclipse/tcf/te/runtime/processes/ProcessOutputReaderThread.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.runtime/src/org/eclipse/tcf/te/runtime/processes/ProcessOutputReaderThread.java
@@ -73,7 +73,7 @@ public class ProcessOutputReaderThread extends Thread {
*
* @return <code>true</code> if the thread is finished, <code>false</code> otherwise.
*/
- public synchronized boolean isFinished() {
+ public boolean isFinished() {
return finished;
}
@@ -83,11 +83,10 @@ public class ProcessOutputReaderThread extends Thread {
* @param timeout Timeout in milliseconds to wait for (maximum).
*/
public void waitForFinish(long timeout) {
+ if (finished) return;
+
+ waiting = true;
synchronized (waiterSemaphore) {
- if (finished) {
- return;
- }
- waiting = true;
try {
waiterSemaphore.wait(timeout);
} catch (InterruptedException e) {
@@ -152,7 +151,7 @@ public class ProcessOutputReaderThread extends Thread {
* Called when the process finished and no more input is available. May be overridden by
* subclasses to extend functionality.
*/
- protected synchronized void finish() {
+ protected void finish() {
finished = true;
if (waiting) {
waiting = false;
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.runtime/src/org/eclipse/tcf/te/runtime/tracing/TraceHandler.java b/target_explorer/plugins/org.eclipse.tcf.te.runtime/src/org/eclipse/tcf/te/runtime/tracing/TraceHandler.java
index 36de8ff1e..5c1989cad 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.runtime/src/org/eclipse/tcf/te/runtime/tracing/TraceHandler.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.runtime/src/org/eclipse/tcf/te/runtime/tracing/TraceHandler.java
@@ -1,283 +1,283 @@
-/*******************************************************************************
- * 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.runtime.tracing;
-
-import org.eclipse.core.runtime.Assert;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.tcf.te.runtime.activator.CoreBundleActivator;
-
-/**
- * Helper class to handle tracing using the platforms debug capabilities.
- */
-public class TraceHandler {
- /**
- * The bundle identifier.
- */
- private final String identifier;
-
- /**
- * The tracer instance.
- */
- private Tracer tracer = null;
-
- /**
- * The tracer is responsible for writing the trace message to the desired
- * output media.
- */
- protected static class Tracer {
-
- /**
- * The bundle identifier.
- */
- private final String fIdentifier;
-
- /**
- * The qualifier for the default &quot;&lt;bundle identifier&gt;/debugmode&quot;
- * tracing slot.
- */
- private final String fDebugModeQualifier;
-
- /**
- * Constructor.
- *
- * @param identifier The bundle identifier. Must not be <code>null</code>.
- */
- public Tracer(String identifier) {
- Assert.isNotNull(identifier);
- fIdentifier = identifier;
-
- // Initialize the debug mode qualifier
- fDebugModeQualifier = fIdentifier + "/debugmode"; //$NON-NLS-1$
- }
-
- /**
- * Returns the value of the debug mode tracing slot.
- * <p>
- * If not set, or the value is not an {@link Integer}, the method returns <code>0</code>.
- *
- * @return The debug mode value.
- */
- protected int getDebugMode() {
- try {
- String mode = Platform.getDebugOption(fDebugModeQualifier);
- if (mode != null && Integer.decode(mode).intValue() > 0) {
- return Integer.decode(mode).intValue();
- }
- } catch (NumberFormatException e) { /* ignored on purpose */ }
-
- return 0;
- }
-
- /**
- * Check if the specified trace slot is enabled.
- *
- * @param slotId The name of the slot.
- * @return <code>true</code> if the slot is defined and enabled, <code>false</code> otherwise.
- */
- protected boolean isSlotEnabled(String slotId) {
- return fIdentifier != null ? Boolean.parseBoolean(Platform.getDebugOption(fIdentifier + "/" + slotId)) : false; //$NON-NLS-1$
- }
-
- /**
- * Check if tracing is enabled for given mode and slot.
- *
- * @param debugMode The debug mode for the current debug.
- * @param slotId The name of the slot.
- *
- * @return <code>true</code> if the debug should be written, <code>false</code> otherwise.
- */
- protected final boolean isEnabled(int debugMode, String slotId) {
- return getDebugMode() < 0 ||
- (debugMode <= getDebugMode() &&
- (slotId == null || slotId.trim().length() == 0 || isSlotEnabled(slotId)));
- }
-
- /**
- * Format the trace message.
- *
- * @param message The trace message.
- * @param debugMode The debug mode.
- * @param slotId The name of the slot.
- * @param severity The severity. See {@link IStatus} for valid severity values.
- * @param clazz The class that calls this tracer.
- *
- * @see IStatus
- */
- protected String getFormattedDebugMessage(String message, int debugMode, String slotId, int severity, Object clazz) {
- StringBuffer debug = new StringBuffer();
- if (slotId != null || clazz != null) {
- if (clazz != null) {
- String name = clazz instanceof Class<?> ? ((Class<?>)clazz).getSimpleName() : clazz.getClass().getSimpleName();
- debug.append((name != null && name.trim().length() > 0) ? name.trim() : clazz instanceof Class<?> ? ((Class<?>)clazz).getName() : clazz.getClass().getName());
- }
- if (slotId != null) {
- debug.append(" at "); //$NON-NLS-1$
- debug.append(slotId);
- }
- if (debugMode >= 0) {
- debug.append(" (Mode "); //$NON-NLS-1$
- debug.append(debugMode);
- debug.append(')');
- }
- debug.append('\n');
- debug.append('\t');
- }
- debug.append(message);
-
- return debug.toString();
- }
-
- /**
- * Write the trace message.
- *
- * @param message The trace message.
- * @param debugMode The debug mode.
- * @param slotId The name of the slot.
- * @param severity The severity. See {@link IStatus} for valid severity values.
- * @param clazz The class that calls this tracer.
- *
- * @see IStatus
- */
- protected void write(String message, int debugMode, String slotId, int severity, Object clazz) {
- String formattedMessage = getFormattedDebugMessage(message, debugMode, slotId, severity, clazz);
- if (severity == IStatus.ERROR || severity == IStatus.WARNING) {
- System.err.println(formattedMessage);
- }
- else {
- System.out.println(formattedMessage);
- }
- }
-
- /**
- * Trace the given message with the given debug mode and slot.
- *
- * @param message The trace message.
- * @param debugMode The debug mode.
- * @param slotId The name of the slot.
- * @param severity The severity. See {@link IStatus} for valid severity values.
- * @param clazz The class that calls this tracer.
- *
- * @see IStatus
- */
- public final void trace(String message, int debugMode, String slotId, int severity, Object clazz) {
- if (isEnabled(debugMode, slotId)) {
- write(message, debugMode, slotId, severity, clazz);
- }
- }
- }
-
- /**
- * Constructor.
- * <p>
- * Initializes the tracing handler with the given bundle identifier.
- *
- * @param identifier The bundle identifier or <code>null</code>.
- */
- public TraceHandler(String identifier) {
- this.identifier = identifier != null ? identifier : CoreBundleActivator.getUniqueIdentifier();
- Assert.isNotNull(this.identifier);
- }
-
- /**
- * Returns the identifier.
- */
- protected final String getIdentifier() {
- return identifier;
- }
-
- /**
- * Returns the tracer instance. Create a new tracer instance
- * on first invocation.
- *
- * @return The tracer instance.
- */
- protected Tracer getTracer() {
- if (tracer == null) {
- tracer = new Tracer(identifier);
- }
- return tracer;
- }
-
- /**
- * Return the current debug mode.
- */
- public final int getDebugMode() {
- return getTracer().getDebugMode();
- }
-
- /**
- * Check whether a trace slot is enabled with the given debug mode.
- *
- * @param debugMode The debug mode
- * @param slotId The name of the slot.
- *
- * @return <code>true</code> if the slot is enabled, <code>false</code> otherwise.
- */
- public final boolean isSlotEnabled(int debugMode, String slotId) {
- return getTracer().isEnabled(debugMode, slotId);
- }
-
- /**
- * Trace the given message.
- * <p>
- * The message severity will be {@link IStatus#INFO} and the message will be
- * traced unconditionally.
- *
- * @param message The message.
- * @param clazz The class that calls this tracer or <code>null</code>.
- */
- public final void trace(String message, Object clazz) {
- getTracer().trace(message, 0, null, IStatus.INFO, clazz);
- }
-
- /**
- * Trace the given message.
- * <p>
- * The message severity will be {@link IStatus#INFO}.
- *
- * @param message The message.
- * @param debugMode The minimum debug mode that has to be set to write out the message.
- * @param clazz The class that calls this tracer or <code>null</code>.
- */
- public final void trace(String message, int debugMode, Object clazz) {
- getTracer().trace(message, debugMode, null, IStatus.INFO, clazz);
- }
-
- /**
- * Trace the given message.
- * <p>
- * The message severity will be {@link IStatus#INFO} and the debug mode
- * will default to <code>0</code>.
- *
- * @param message The message.
- * @param slotId The slot that has to be enabled to write out the message.
- * @param clazz The class that calls this tracer or <code>null</code>.
- */
- public final void trace(String message, String slotId, Object clazz) {
- getTracer().trace(message, 0, slotId, IStatus.INFO, clazz);
- }
-
- /**
- * Trace the given message.
- *
- * @param message The message.
- * @param debugMode The minimum debug mode that has to be set to write out the message.
- * @param slotId The slot that has to be enabled to write out the message.
- * @param severity The severity. See {@link IStatus} for valid severity values.
- * @param clazz The class that calls this tracer or <code>null</code>.
- *
- * @see IStatus
- */
- public final void trace(String message, int debugMode, String slotId, int severity, Object clazz) {
- getTracer().trace(message, debugMode, slotId, severity, clazz);
- }
-
-}
+/*******************************************************************************
+ * 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.runtime.tracing;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.tcf.te.runtime.activator.CoreBundleActivator;
+
+/**
+ * Helper class to handle tracing using the platforms debug capabilities.
+ */
+public class TraceHandler {
+ /**
+ * The bundle identifier.
+ */
+ private final String identifier;
+
+ /**
+ * The tracer instance.
+ */
+ private Tracer tracer = null;
+
+ /**
+ * The tracer is responsible for writing the trace message to the desired
+ * output media.
+ */
+ protected static class Tracer {
+
+ /**
+ * The bundle identifier.
+ */
+ private final String fIdentifier;
+
+ /**
+ * The qualifier for the default &quot;&lt;bundle identifier&gt;/debugmode&quot;
+ * tracing slot.
+ */
+ private final String fDebugModeQualifier;
+
+ /**
+ * Constructor.
+ *
+ * @param identifier The bundle identifier. Must not be <code>null</code>.
+ */
+ public Tracer(String identifier) {
+ Assert.isNotNull(identifier);
+ fIdentifier = identifier;
+
+ // Initialize the debug mode qualifier
+ fDebugModeQualifier = fIdentifier + "/debugmode"; //$NON-NLS-1$
+ }
+
+ /**
+ * Returns the value of the debug mode tracing slot.
+ * <p>
+ * If not set, or the value is not an {@link Integer}, the method returns <code>0</code>.
+ *
+ * @return The debug mode value.
+ */
+ protected int getDebugMode() {
+ try {
+ String mode = Platform.getDebugOption(fDebugModeQualifier);
+ if (mode != null && Integer.decode(mode).intValue() > 0) {
+ return Integer.decode(mode).intValue();
+ }
+ } catch (NumberFormatException e) { /* ignored on purpose */ }
+
+ return 0;
+ }
+
+ /**
+ * Check if the specified trace slot is enabled.
+ *
+ * @param slotId The name of the slot.
+ * @return <code>true</code> if the slot is defined and enabled, <code>false</code> otherwise.
+ */
+ protected boolean isSlotEnabled(String slotId) {
+ return fIdentifier != null ? Boolean.parseBoolean(Platform.getDebugOption(fIdentifier + "/" + slotId)) : false; //$NON-NLS-1$
+ }
+
+ /**
+ * Check if tracing is enabled for given mode and slot.
+ *
+ * @param debugMode The debug mode for the current debug.
+ * @param slotId The name of the slot.
+ *
+ * @return <code>true</code> if the debug should be written, <code>false</code> otherwise.
+ */
+ protected final boolean isEnabled(int debugMode, String slotId) {
+ return getDebugMode() < 0 ||
+ (debugMode <= getDebugMode() &&
+ (slotId == null || slotId.trim().length() == 0 || isSlotEnabled(slotId)));
+ }
+
+ /**
+ * Format the trace message.
+ *
+ * @param message The trace message.
+ * @param debugMode The debug mode.
+ * @param slotId The name of the slot.
+ * @param severity The severity. See {@link IStatus} for valid severity values.
+ * @param clazz The class that calls this tracer.
+ *
+ * @see IStatus
+ */
+ protected String getFormattedDebugMessage(String message, int debugMode, String slotId, int severity, Object clazz) {
+ StringBuffer debug = new StringBuffer();
+ if (slotId != null || clazz != null) {
+ if (clazz != null) {
+ String name = clazz instanceof Class<?> ? ((Class<?>)clazz).getSimpleName() : clazz.getClass().getSimpleName();
+ debug.append(name.trim().length() > 0 ? name.trim() : clazz instanceof Class<?> ? ((Class<?>)clazz).getName() : clazz.getClass().getName());
+ }
+ if (slotId != null) {
+ debug.append(" at "); //$NON-NLS-1$
+ debug.append(slotId);
+ }
+ if (debugMode >= 0) {
+ debug.append(" (Mode "); //$NON-NLS-1$
+ debug.append(debugMode);
+ debug.append(')');
+ }
+ debug.append('\n');
+ debug.append('\t');
+ }
+ debug.append(message);
+
+ return debug.toString();
+ }
+
+ /**
+ * Write the trace message.
+ *
+ * @param message The trace message.
+ * @param debugMode The debug mode.
+ * @param slotId The name of the slot.
+ * @param severity The severity. See {@link IStatus} for valid severity values.
+ * @param clazz The class that calls this tracer.
+ *
+ * @see IStatus
+ */
+ protected void write(String message, int debugMode, String slotId, int severity, Object clazz) {
+ String formattedMessage = getFormattedDebugMessage(message, debugMode, slotId, severity, clazz);
+ if (severity == IStatus.ERROR || severity == IStatus.WARNING) {
+ System.err.println(formattedMessage);
+ }
+ else {
+ System.out.println(formattedMessage);
+ }
+ }
+
+ /**
+ * Trace the given message with the given debug mode and slot.
+ *
+ * @param message The trace message.
+ * @param debugMode The debug mode.
+ * @param slotId The name of the slot.
+ * @param severity The severity. See {@link IStatus} for valid severity values.
+ * @param clazz The class that calls this tracer.
+ *
+ * @see IStatus
+ */
+ public final void trace(String message, int debugMode, String slotId, int severity, Object clazz) {
+ if (isEnabled(debugMode, slotId)) {
+ write(message, debugMode, slotId, severity, clazz);
+ }
+ }
+ }
+
+ /**
+ * Constructor.
+ * <p>
+ * Initializes the tracing handler with the given bundle identifier.
+ *
+ * @param identifier The bundle identifier or <code>null</code>.
+ */
+ public TraceHandler(String identifier) {
+ this.identifier = identifier != null ? identifier : CoreBundleActivator.getUniqueIdentifier();
+ Assert.isNotNull(this.identifier);
+ }
+
+ /**
+ * Returns the identifier.
+ */
+ protected final String getIdentifier() {
+ return identifier;
+ }
+
+ /**
+ * Returns the tracer instance. Create a new tracer instance
+ * on first invocation.
+ *
+ * @return The tracer instance.
+ */
+ protected Tracer getTracer() {
+ if (tracer == null) {
+ tracer = new Tracer(identifier);
+ }
+ return tracer;
+ }
+
+ /**
+ * Return the current debug mode.
+ */
+ public final int getDebugMode() {
+ return getTracer().getDebugMode();
+ }
+
+ /**
+ * Check whether a trace slot is enabled with the given debug mode.
+ *
+ * @param debugMode The debug mode
+ * @param slotId The name of the slot.
+ *
+ * @return <code>true</code> if the slot is enabled, <code>false</code> otherwise.
+ */
+ public final boolean isSlotEnabled(int debugMode, String slotId) {
+ return getTracer().isEnabled(debugMode, slotId);
+ }
+
+ /**
+ * Trace the given message.
+ * <p>
+ * The message severity will be {@link IStatus#INFO} and the message will be
+ * traced unconditionally.
+ *
+ * @param message The message.
+ * @param clazz The class that calls this tracer or <code>null</code>.
+ */
+ public final void trace(String message, Object clazz) {
+ getTracer().trace(message, 0, null, IStatus.INFO, clazz);
+ }
+
+ /**
+ * Trace the given message.
+ * <p>
+ * The message severity will be {@link IStatus#INFO}.
+ *
+ * @param message The message.
+ * @param debugMode The minimum debug mode that has to be set to write out the message.
+ * @param clazz The class that calls this tracer or <code>null</code>.
+ */
+ public final void trace(String message, int debugMode, Object clazz) {
+ getTracer().trace(message, debugMode, null, IStatus.INFO, clazz);
+ }
+
+ /**
+ * Trace the given message.
+ * <p>
+ * The message severity will be {@link IStatus#INFO} and the debug mode
+ * will default to <code>0</code>.
+ *
+ * @param message The message.
+ * @param slotId The slot that has to be enabled to write out the message.
+ * @param clazz The class that calls this tracer or <code>null</code>.
+ */
+ public final void trace(String message, String slotId, Object clazz) {
+ getTracer().trace(message, 0, slotId, IStatus.INFO, clazz);
+ }
+
+ /**
+ * Trace the given message.
+ *
+ * @param message The message.
+ * @param debugMode The minimum debug mode that has to be set to write out the message.
+ * @param slotId The slot that has to be enabled to write out the message.
+ * @param severity The severity. See {@link IStatus} for valid severity values.
+ * @param clazz The class that calls this tracer or <code>null</code>.
+ *
+ * @see IStatus
+ */
+ public final void trace(String message, int debugMode, String slotId, int severity, Object clazz) {
+ getTracer().trace(message, debugMode, slotId, severity, clazz);
+ }
+
+}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.core.scripting/src/org/eclipse/tcf/te/tcf/core/scripting/parser/Parser.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.core.scripting/src/org/eclipse/tcf/te/tcf/core/scripting/parser/Parser.java
index 7db81909e..6b391b360 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.core.scripting/src/org/eclipse/tcf/te/tcf/core/scripting/parser/Parser.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.core.scripting/src/org/eclipse/tcf/te/tcf/core/scripting/parser/Parser.java
@@ -103,7 +103,7 @@ public class Parser {
StringTokenizer tokenizer = new StringTokenizer(arguments, " "); //$NON-NLS-1$
while (tokenizer.hasMoreTokens()) {
String tok = tokenizer.nextToken();
- if (tok == null || "".equals(tok.trim())) continue; //$NON-NLS-1$
+ if ("".equals(tok.trim())) continue; //$NON-NLS-1$
if (tok.equals("null")) { //$NON-NLS-1$
token.addArgument(null);
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/nls/Messages.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/nls/Messages.java
index 5eb1e1acc..a6e05c307 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/nls/Messages.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/nls/Messages.java
@@ -58,9 +58,7 @@ public class Messages extends NLS {
if (key != null) {
try {
Field field = Messages.class.getDeclaredField(key);
- if (field != null) {
- return (String)field.get(null);
- }
+ return (String)field.get(null);
} catch (Exception e) { /* ignored on purpose */ }
}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/compare/MergeTypedElement.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/compare/MergeTypedElement.java
index c6df7d82f..37e96269d 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/compare/MergeTypedElement.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/compare/MergeTypedElement.java
@@ -1,99 +1,99 @@
-/*******************************************************************************
- * 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
- * William Chen (Wind River)- [345552] Edit the remote files with a proper editor
- *******************************************************************************/
-package org.eclipse.tcf.te.tcf.filesystem.ui.internal.compare;
-
-import org.eclipse.compare.BufferedContent;
-import org.eclipse.compare.CompareUI;
-import org.eclipse.compare.ITypedElement;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.tcf.te.tcf.filesystem.core.model.FSTreeNode;
-
-/**
- * A <code>MergeTypedElement</code> wraps an <code>FSTreeNode</code> so that it
- * can be used as input for the differencing engine (<code>ITypedElement</code>).
- */
-public abstract class MergeTypedElement extends BufferedContent implements ITypedElement {
- // The File System tree node to be wrapped.
- protected FSTreeNode node;
-
- /**
- * Create a MergeTypedElement for the given node.
- *
- * @param node
- * The node.
- */
- public MergeTypedElement(FSTreeNode node) {
- this.node = node;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.compare.ITypedElement#getImage()
- */
- @Override
- public Image getImage() {
- return CompareUI.getImage(getType());
- }
-
- /**
- * Return the tree node wrapped.
- *
- * @return The tree node of the file
- */
- public FSTreeNode getFSTreeNode() {
- return node;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.compare.ITypedElement#getType()
- */
- @Override
- public String getType() {
- if (node != null) {
- if (node.isDirectory()) {
- return ITypedElement.FOLDER_TYPE;
- }
- String s = node.name;
- int dot = s.lastIndexOf('.');
- if (dot != -1) s = s.substring(dot + 1);
- if (s != null) return s;
- }
- return ITypedElement.UNKNOWN_TYPE;
- }
-
- /* (non-Javadoc)
- * @see java.lang.Object#equals(java.lang.Object)
- */
- @Override
- public boolean equals(Object other) {
- if (other instanceof ITypedElement) {
- return toString().equals(other.toString());
- }
- return super.equals(other);
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.compare.ITypedElement#getName()
- */
- @Override
- public String getName() {
- return node.name;
- }
-
- /* (non-Javadoc)
- * @see java.lang.Object#hashCode()
- *
- * Returns the hash code of the name.
- */
- @Override
- public int hashCode() {
- return toString().hashCode();
- }
-}
+/*******************************************************************************
+ * 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
+ * William Chen (Wind River)- [345552] Edit the remote files with a proper editor
+ *******************************************************************************/
+package org.eclipse.tcf.te.tcf.filesystem.ui.internal.compare;
+
+import org.eclipse.compare.BufferedContent;
+import org.eclipse.compare.CompareUI;
+import org.eclipse.compare.ITypedElement;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.tcf.te.tcf.filesystem.core.model.FSTreeNode;
+
+/**
+ * A <code>MergeTypedElement</code> wraps an <code>FSTreeNode</code> so that it
+ * can be used as input for the differencing engine (<code>ITypedElement</code>).
+ */
+public abstract class MergeTypedElement extends BufferedContent implements ITypedElement {
+ // The File System tree node to be wrapped.
+ protected FSTreeNode node;
+
+ /**
+ * Create a MergeTypedElement for the given node.
+ *
+ * @param node
+ * The node.
+ */
+ public MergeTypedElement(FSTreeNode node) {
+ this.node = node;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.compare.ITypedElement#getImage()
+ */
+ @Override
+ public Image getImage() {
+ return CompareUI.getImage(getType());
+ }
+
+ /**
+ * Return the tree node wrapped.
+ *
+ * @return The tree node of the file
+ */
+ public FSTreeNode getFSTreeNode() {
+ return node;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.compare.ITypedElement#getType()
+ */
+ @Override
+ public String getType() {
+ if (node != null) {
+ if (node.isDirectory()) {
+ return ITypedElement.FOLDER_TYPE;
+ }
+ String s = node.name;
+ int dot = s.lastIndexOf('.');
+ if (dot != -1) s = s.substring(dot + 1);
+ return s;
+ }
+ return ITypedElement.UNKNOWN_TYPE;
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ @Override
+ public boolean equals(Object other) {
+ if (other instanceof ITypedElement) {
+ return toString().equals(other.toString());
+ }
+ return super.equals(other);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.compare.ITypedElement#getName()
+ */
+ @Override
+ public String getName() {
+ return node.name;
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#hashCode()
+ *
+ * Returns the hash code of the name.
+ */
+ @Override
+ public int hashCode() {
+ return toString().hashCode();
+ }
+}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/nls/Messages.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/nls/Messages.java
index d7e228f7a..9ca9893b9 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/nls/Messages.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/nls/Messages.java
@@ -59,9 +59,7 @@ public class Messages extends NLS {
if (key != null) {
try {
Field field = Messages.class.getDeclaredField(key);
- if (field != null) {
- return (String)field.get(null);
- }
+ return (String)field.get(null);
} catch (Exception e) { /* ignored on purpose */ }
}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.core/src/org/eclipse/tcf/te/tcf/launch/core/internal/EventListenerDelegate.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.core/src/org/eclipse/tcf/te/tcf/launch/core/internal/EventListenerDelegate.java
index 39faa871a..e2bf6eed6 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.core/src/org/eclipse/tcf/te/tcf/launch/core/internal/EventListenerDelegate.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.core/src/org/eclipse/tcf/te/tcf/launch/core/internal/EventListenerDelegate.java
@@ -12,6 +12,7 @@ package org.eclipse.tcf.te.tcf.launch.core.internal;
import java.util.EventObject;
import java.util.Map;
+import java.util.Map.Entry;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.ILaunchConfiguration;
@@ -61,8 +62,8 @@ public class EventListenerDelegate implements IEventListener {
attributes.remove(ICommonLaunchAttributes.ATTR_UUID);
attributes.remove(ICommonLaunchAttributes.ATTR_LAST_LAUNCHED);
final ILaunchConfigurationWorkingCopy wc = config.getWorkingCopy();
- for (String key : attributes.keySet()) {
- LaunchConfigHelper.addLaunchConfigAttribute(wc, key, attributes.get(key));
+ for (Entry<String, String> entry : attributes.entrySet()) {
+ LaunchConfigHelper.addLaunchConfigAttribute(wc, entry.getKey(), entry.getValue());
}
ExecutorsUtil.executeInUI(new Runnable() {
@Override
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.core/src/org/eclipse/tcf/te/tcf/launch/core/lm/delegates/AttachLaunchManagerDelegate.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.core/src/org/eclipse/tcf/te/tcf/launch/core/lm/delegates/AttachLaunchManagerDelegate.java
index ca432d1e9..a3541804b 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.core/src/org/eclipse/tcf/te/tcf/launch/core/lm/delegates/AttachLaunchManagerDelegate.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.core/src/org/eclipse/tcf/te/tcf/launch/core/lm/delegates/AttachLaunchManagerDelegate.java
@@ -16,6 +16,7 @@ import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
+import java.util.Map.Entry;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationListener;
@@ -125,8 +126,8 @@ public class AttachLaunchManagerDelegate extends DefaultLaunchManagerDelegate im
attributes.remove(ILaunchContextLaunchAttributes.ATTR_LAUNCH_CONTEXTS);
attributes.remove(ICommonLaunchAttributes.ATTR_UUID);
attributes.remove(ICommonLaunchAttributes.ATTR_LAST_LAUNCHED);
- for (String key : attributes.keySet()) {
- launchSpec.addAttribute(key, attributes.get(key), true);
+ for (Entry<String, String> entry : attributes.entrySet()) {
+ launchSpec.addAttribute(entry.getKey(), entry.getValue(), true);
}
}
catch (Exception e) {
@@ -147,7 +148,7 @@ public class AttachLaunchManagerDelegate extends DefaultLaunchManagerDelegate im
public String getDefaultLaunchName(ILaunchSpecification launchSpec) {
IModelNode[] contexts = LaunchContextsPersistenceDelegate.getLaunchContexts(launchSpec);
String name = getDefaultLaunchName((contexts != null && contexts.length > 0 ? contexts[0] : null));
- return name != null && name.trim().length() > 0 ? name.trim() : super.getDefaultLaunchName(launchSpec);
+ return name.trim().length() > 0 ? name.trim() : super.getDefaultLaunchName(launchSpec);
}
/* (non-Javadoc)
@@ -157,7 +158,7 @@ public class AttachLaunchManagerDelegate extends DefaultLaunchManagerDelegate im
public String getDefaultLaunchName(ILaunchConfiguration launchConfig) {
IModelNode[] contexts = LaunchContextsPersistenceDelegate.getLaunchContexts(launchConfig);
String name = getDefaultLaunchName((contexts != null && contexts.length > 0 ? contexts[0] : null));
- return name != null && name.trim().length() > 0 ? name.trim() : super.getDefaultLaunchName(launchConfig);
+ return name.trim().length() > 0 ? name.trim() : super.getDefaultLaunchName(launchConfig);
}
private String getDefaultLaunchName(IModelNode context) {
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.core/src/org/eclipse/tcf/te/tcf/launch/core/lm/delegates/RemoteAppLaunchManagerDelegate.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.core/src/org/eclipse/tcf/te/tcf/launch/core/lm/delegates/RemoteAppLaunchManagerDelegate.java
index c4d796d8d..12c6e53ad 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.core/src/org/eclipse/tcf/te/tcf/launch/core/lm/delegates/RemoteAppLaunchManagerDelegate.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.core/src/org/eclipse/tcf/te/tcf/launch/core/lm/delegates/RemoteAppLaunchManagerDelegate.java
@@ -1,312 +1,312 @@
-/*******************************************************************************
- * 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.tcf.launch.core.lm.delegates;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.debug.core.ILaunchConfiguration;
-import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
-import org.eclipse.tcf.te.launch.core.exceptions.LaunchServiceException;
-import org.eclipse.tcf.te.launch.core.interfaces.IReferencedProjectItem;
-import org.eclipse.tcf.te.launch.core.lm.delegates.DefaultLaunchManagerDelegate;
-import org.eclipse.tcf.te.launch.core.lm.interfaces.IFileTransferLaunchAttributes;
-import org.eclipse.tcf.te.launch.core.lm.interfaces.ILaunchContextLaunchAttributes;
-import org.eclipse.tcf.te.launch.core.lm.interfaces.ILaunchSpecification;
-import org.eclipse.tcf.te.launch.core.lm.interfaces.IReferencedProjectLaunchAttributes;
-import org.eclipse.tcf.te.launch.core.persistence.DefaultPersistenceDelegate;
-import org.eclipse.tcf.te.launch.core.persistence.filetransfer.FileTransfersPersistenceDelegate;
-import org.eclipse.tcf.te.launch.core.persistence.launchcontext.LaunchContextsPersistenceDelegate;
-import org.eclipse.tcf.te.launch.core.persistence.projects.ReferencedProjectItem;
-import org.eclipse.tcf.te.launch.core.persistence.projects.ReferencedProjectsPersistenceDelegate;
-import org.eclipse.tcf.te.launch.core.selection.interfaces.IProjectSelectionContext;
-import org.eclipse.tcf.te.launch.core.selection.interfaces.IRemoteSelectionContext;
-import org.eclipse.tcf.te.launch.core.selection.interfaces.ISelectionContext;
-import org.eclipse.tcf.te.runtime.model.interfaces.IModelNode;
-import org.eclipse.tcf.te.runtime.services.ServiceManager;
-import org.eclipse.tcf.te.runtime.services.filetransfer.FileTransferItem;
-import org.eclipse.tcf.te.runtime.services.interfaces.IPropertiesAccessService;
-import org.eclipse.tcf.te.runtime.services.interfaces.constants.IPropertiesAccessServiceConstants;
-import org.eclipse.tcf.te.runtime.services.interfaces.filetransfer.IFileTransferItem;
-import org.eclipse.tcf.te.tcf.launch.core.interfaces.IRemoteAppLaunchAttributes;
-
-/**
- * RemoteAppLaunchManagerDelegate
- */
-public class RemoteAppLaunchManagerDelegate extends DefaultLaunchManagerDelegate {
-
- private static final String[] MANDATORY_CONFIG_ATTRIBUTES = new String[] {
- ILaunchContextLaunchAttributes.ATTR_LAUNCH_CONTEXTS,
- IRemoteAppLaunchAttributes.ATTR_PROCESS_IMAGE
- };
-
- /**
- * Constructor.
- */
- public RemoteAppLaunchManagerDelegate() {
- super();
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.tcf.te.launch.core.lm.delegates.DefaultLaunchManagerDelegate#initLaunchConfigAttributes(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy, org.eclipse.tcf.te.launch.core.lm.interfaces.ILaunchSpecification)
- */
- @Override
- public void initLaunchConfigAttributes(ILaunchConfigurationWorkingCopy wc, ILaunchSpecification launchSpec) {
- super.initLaunchConfigAttributes(wc, launchSpec);
-
- if (launchSpec.hasAttribute(ILaunchContextLaunchAttributes.ATTR_LAUNCH_CONTEXTS)) {
- wc.setAttribute(ILaunchContextLaunchAttributes.ATTR_LAUNCH_CONTEXTS, (String)launchSpec.getAttribute(ILaunchContextLaunchAttributes.ATTR_LAUNCH_CONTEXTS).getValue());
- }
- if (launchSpec.hasAttribute(IRemoteAppLaunchAttributes.ATTR_PROCESS_IMAGE)) {
- wc.setAttribute(IRemoteAppLaunchAttributes.ATTR_PROCESS_IMAGE, (String)launchSpec.getAttribute(IRemoteAppLaunchAttributes.ATTR_PROCESS_IMAGE).getValue());
- }
- if (launchSpec.hasAttribute(IFileTransferLaunchAttributes.ATTR_FILE_TRANSFERS)) {
- wc.setAttribute(IFileTransferLaunchAttributes.ATTR_FILE_TRANSFERS, (String)launchSpec.getAttribute(IFileTransferLaunchAttributes.ATTR_FILE_TRANSFERS).getValue());
- }
- if (launchSpec.hasAttribute(IReferencedProjectLaunchAttributes.ATTR_REFERENCED_PROJECTS)) {
- wc.setAttribute(IReferencedProjectLaunchAttributes.ATTR_REFERENCED_PROJECTS, (String)launchSpec.getAttribute(IReferencedProjectLaunchAttributes.ATTR_REFERENCED_PROJECTS).getValue());
- }
- }
-
- @Override
- public void updateLaunchConfig(ILaunchConfigurationWorkingCopy wc, ISelectionContext selContext, boolean replace) {
- super.updateLaunchConfig(wc, selContext, replace);
-
- if (selContext instanceof IProjectSelectionContext) {
- List<IFileTransferItem> transfers;
- List<IReferencedProjectItem> projects;
- String processPath;
- if (replace) {
- transfers = new ArrayList<IFileTransferItem>();
- projects = new ArrayList<IReferencedProjectItem>();
- processPath = getProcessImageAndSetProjectAndTransfer((IProjectSelectionContext)selContext, transfers, projects);
-
- FileTransfersPersistenceDelegate.setFileTransfers(wc, transfers.toArray(new IFileTransferItem[transfers.size()]));
- ReferencedProjectsPersistenceDelegate.setReferencedProjects(wc, projects.toArray(new IReferencedProjectItem[projects.size()]));
- if (processPath != null && processPath.trim().length() > 0) {
- DefaultPersistenceDelegate.setAttribute(wc, IRemoteAppLaunchAttributes.ATTR_PROCESS_IMAGE, processPath);
- }
- }
- else {
- transfers = new ArrayList<IFileTransferItem>(Arrays.asList(FileTransfersPersistenceDelegate.getFileTransfers(wc)));
- projects = new ArrayList<IReferencedProjectItem>(Arrays.asList(ReferencedProjectsPersistenceDelegate.getReferencedProjects(wc)));
- processPath = getProcessImageAndSetProjectAndTransfer((IProjectSelectionContext)selContext, transfers, projects);
-
- FileTransfersPersistenceDelegate.setFileTransfers(wc, transfers.toArray(new IFileTransferItem[transfers.size()]));
- ReferencedProjectsPersistenceDelegate.setReferencedProjects(wc, projects.toArray(new IReferencedProjectItem[projects.size()]));
- if (processPath != null && processPath.trim().length() > 0 && !DefaultPersistenceDelegate.hasAttribute(wc, IRemoteAppLaunchAttributes.ATTR_PROCESS_IMAGE)) {
- DefaultPersistenceDelegate.setAttribute(wc, IRemoteAppLaunchAttributes.ATTR_PROCESS_IMAGE, processPath);
- }
- }
- }
- else if (selContext instanceof IRemoteSelectionContext) {
- IRemoteSelectionContext remoteCtx = (IRemoteSelectionContext)selContext;
- LaunchContextsPersistenceDelegate.setLaunchContexts(wc, new IModelNode[]{remoteCtx.getRemoteCtx()});
- }
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.tcf.te.launch.core.lm.delegates.DefaultLaunchManagerDelegate#addLaunchSpecAttributes(org.eclipse.tcf.te.launch.core.lm.interfaces.ILaunchSpecification, java.lang.String, org.eclipse.tcf.te.launch.core.selection.interfaces.ISelectionContext)
- */
- @Override
- protected ILaunchSpecification addLaunchSpecAttributes(ILaunchSpecification launchSpec, String launchConfigTypeId, ISelectionContext selectionContext) {
- launchSpec = super.addLaunchSpecAttributes(launchSpec, launchConfigTypeId, selectionContext);
-
- if (selectionContext instanceof IRemoteSelectionContext) {
- List<IModelNode> launchContexts = new ArrayList<IModelNode>(Arrays.asList(LaunchContextsPersistenceDelegate.getLaunchContexts(launchSpec)));
- IModelNode remoteCtx = ((IRemoteSelectionContext)selectionContext).getRemoteCtx();
- if (!launchContexts.contains(remoteCtx)) {
- launchContexts.add(remoteCtx);
- LaunchContextsPersistenceDelegate.setLaunchContexts(launchSpec, launchContexts.toArray(new IModelNode[launchContexts.size()]));
- }
-
- launchSpec.setLaunchConfigName(getDefaultLaunchName(launchSpec));
- }
- else if (selectionContext instanceof IProjectSelectionContext) {
- List<IFileTransferItem> transfers = new ArrayList<IFileTransferItem>(Arrays.asList(FileTransfersPersistenceDelegate.getFileTransfers(launchSpec)));
- List<IReferencedProjectItem> projects = new ArrayList<IReferencedProjectItem>(Arrays.asList(ReferencedProjectsPersistenceDelegate.getReferencedProjects(launchSpec)));
- String processPath = getProcessImageAndSetProjectAndTransfer((IProjectSelectionContext)selectionContext, transfers, projects);
-
- FileTransfersPersistenceDelegate.setFileTransfers(launchSpec, transfers.toArray(new IFileTransferItem[transfers.size()]));
- ReferencedProjectsPersistenceDelegate.setReferencedProjects(launchSpec, projects.toArray(new IReferencedProjectItem[projects.size()]));
- launchSpec.addAttribute(IRemoteAppLaunchAttributes.ATTR_PROCESS_IMAGE, processPath);
-
- launchSpec.setLaunchConfigName(getDefaultLaunchName(launchSpec));
- }
-
- return launchSpec;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.tcf.te.launch.core.lm.delegates.DefaultLaunchManagerDelegate#getDefaultLaunchName(org.eclipse.tcf.te.launch.core.lm.interfaces.ILaunchSpecification)
- */
- @Override
- public String getDefaultLaunchName(ILaunchSpecification launchSpec) {
- IModelNode[] contexts = LaunchContextsPersistenceDelegate.getLaunchContexts(launchSpec);
- String processPath = (String)launchSpec.getAttribute(IRemoteAppLaunchAttributes.ATTR_PROCESS_IMAGE, null);
- String name = getDefaultLaunchName((contexts != null && contexts.length > 0 ? contexts[0] : null), processPath);
- return name != null && name.trim().length() > 0 ? name.trim() : super.getDefaultLaunchName(launchSpec);
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.tcf.te.launch.core.lm.delegates.DefaultLaunchManagerDelegate#getDefaultLaunchName(org.eclipse.debug.core.ILaunchConfiguration)
- */
- @Override
- public String getDefaultLaunchName(ILaunchConfiguration launchConfig) {
- IModelNode[] contexts = LaunchContextsPersistenceDelegate.getLaunchContexts(launchConfig);
- String processPath = DefaultPersistenceDelegate.getAttribute(launchConfig, IRemoteAppLaunchAttributes.ATTR_PROCESS_IMAGE, (String)null);
- String name = getDefaultLaunchName((contexts != null && contexts.length > 0 ? contexts[0] : null), processPath);
- return name != null && name.trim().length() > 0 ? name.trim() : super.getDefaultLaunchName(launchConfig);
- }
-
- private String getDefaultLaunchName(IModelNode context, String processPath) {
- String name = ""; //$NON-NLS-1$
- if (processPath != null) {
- name += new Path(processPath).lastSegment();
- }
- if (context != null) {
- IPropertiesAccessService service = ServiceManager.getInstance().getService(context, IPropertiesAccessService.class);
- Object dnsName = service != null ? service.getProperty(context, "dns.name.transient") : null; //$NON-NLS-1$
- String ctxName = service != null ? (String)service.getTargetAddress(context).get(IPropertiesAccessServiceConstants.PROP_ADDRESS) : null;
- ctxName = dnsName != null && dnsName.toString().trim().length() > 0 ? dnsName.toString().trim() : ctxName;
-
- name += " (" + ctxName + ")"; //$NON-NLS-1$ //$NON-NLS-2$
- }
- return name.trim();
- }
-
- private String getProcessImageAndSetProjectAndTransfer(IProjectSelectionContext prjContext, List<IFileTransferItem> transfers, List<IReferencedProjectItem> projects) {
- String processName = null;
- String processPath = null;
-
- boolean added = false;
- for (Object selection : prjContext.getSelections()) {
- if (selection instanceof IPath) {
- IPath path = (IPath)selection;
- IFileTransferItem transfer = new FileTransferItem(path, new Path("/tmp/")); //$NON-NLS-1$
- if (!transfers.contains(transfer)) {
- transfers.add(transfer);
- }
- if (!added) {
- processName = path.lastSegment();
- processPath = "/tmp/" + processName; //$NON-NLS-1$
- }
- added = true;
- }
- }
-
- IReferencedProjectItem project = new ReferencedProjectItem(prjContext.getProjectCtx().getName());
- if (!projects.contains(project)) {
- projects.add(project);
- }
-
- return processPath;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.tcf.te.launch.core.lm.delegates.DefaultLaunchManagerDelegate#validate(java.lang.String, org.eclipse.debug.core.ILaunchConfiguration)
- */
- @Override
- public void validate(String launchMode, ILaunchConfiguration launchConfig) throws LaunchServiceException {
- super.validate(launchMode, launchConfig);
-
- StringBuilder missingAttributes = new StringBuilder();
- for (String attribute : MANDATORY_CONFIG_ATTRIBUTES) {
- if (!isValidAttribute(attribute, launchConfig, launchMode)) {
- if (missingAttributes.length() == 0) {
- missingAttributes.append(attribute);
- } else {
- missingAttributes.append(", "); //$NON-NLS-1$
- missingAttributes.append(attribute);
- }
- }
- }
- if (missingAttributes.length() > 0) {
- throw new LaunchServiceException("Missing launch configuration attributes: " + '\n' + missingAttributes.toString(), LaunchServiceException.TYPE_MISSING_LAUNCH_CONFIG_ATTR); //$NON-NLS-1$
- }
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.tcf.te.launch.core.lm.delegates.DefaultLaunchManagerDelegate#equals(java.lang.String, java.lang.Object, java.lang.Object, org.eclipse.tcf.te.launch.core.lm.interfaces.ILaunchSpecification, org.eclipse.debug.core.ILaunchConfiguration, java.lang.String)
- */
- @Override
- protected int equals(String attributeKey, Object specValue, Object confValue, ILaunchSpecification launchSpec, ILaunchConfiguration launchConfig, String launchMode) {
-
- if (IRemoteAppLaunchAttributes.ATTR_PROCESS_IMAGE.equals(attributeKey)) {
- // get match of object
- int match = specValue.equals(confValue) ? FULL_MATCH : NO_MATCH;
- // compare objects in the list when they are not already equal
- if (match != FULL_MATCH) {
- IPath confPath = new Path(confValue.toString());
- IPath specPath = new Path(specValue.toString());
-
- if (confPath.lastSegment().equals(specPath.lastSegment())) {
- match = PARTIAL_MATCH;
- }
- else {
- match = NO_MATCH;
- }
- }
- return match;
- }
-
- return super.equals(attributeKey, specValue, confValue, launchSpec, launchConfig, launchMode);
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.tcf.te.launch.core.lm.delegates.DefaultLaunchManagerDelegate#getNumAttributes()
- */
- @Override
- protected int getNumAttributes() {
- return 5;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.tcf.te.launch.core.lm.delegates.DefaultLaunchManagerDelegate#getAttributeRanking(java.lang.String)
- */
- @Override
- protected int getAttributeRanking(String attributeKey) {
- if (ILaunchContextLaunchAttributes.ATTR_LAUNCH_CONTEXTS.equals(attributeKey)) {
- return getNumAttributes() * 32;
- }
- else if (IRemoteAppLaunchAttributes.ATTR_PROCESS_IMAGE.equals(attributeKey)) {
- return getNumAttributes() * 16;
- }
- else if (IRemoteAppLaunchAttributes.ATTR_PROCESS_ARGUMENTS.equals(attributeKey)) {
- return getNumAttributes() * 8;
- }
- else if (IFileTransferLaunchAttributes.ATTR_FILE_TRANSFERS.equals(attributeKey)) {
- return getNumAttributes() * 4;
- }
- else if (IReferencedProjectLaunchAttributes.ATTR_REFERENCED_PROJECTS.equals(attributeKey)) {
- return getNumAttributes() * 2;
- }
- else {
- return 1;
- }
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.tcf.te.launch.core.lm.delegates.DefaultLaunchManagerDelegate#getDescription(org.eclipse.debug.core.ILaunchConfiguration)
- */
- @Override
- public String getDescription(ILaunchConfiguration config) {
- String image = DefaultPersistenceDelegate.getAttribute(config, IRemoteAppLaunchAttributes.ATTR_PROCESS_IMAGE, (String)null);
- String args = DefaultPersistenceDelegate.getAttribute(config, IRemoteAppLaunchAttributes.ATTR_PROCESS_ARGUMENTS, ""); //$NON-NLS-1$
- if (image != null) {
- return new Path(image).toPortableString() + " " + args; //$NON-NLS-1$
- }
- return ""; //$NON-NLS-1$
- }
-}
+/*******************************************************************************
+ * 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.tcf.launch.core.lm.delegates;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.debug.core.ILaunchConfiguration;
+import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
+import org.eclipse.tcf.te.launch.core.exceptions.LaunchServiceException;
+import org.eclipse.tcf.te.launch.core.interfaces.IReferencedProjectItem;
+import org.eclipse.tcf.te.launch.core.lm.delegates.DefaultLaunchManagerDelegate;
+import org.eclipse.tcf.te.launch.core.lm.interfaces.IFileTransferLaunchAttributes;
+import org.eclipse.tcf.te.launch.core.lm.interfaces.ILaunchContextLaunchAttributes;
+import org.eclipse.tcf.te.launch.core.lm.interfaces.ILaunchSpecification;
+import org.eclipse.tcf.te.launch.core.lm.interfaces.IReferencedProjectLaunchAttributes;
+import org.eclipse.tcf.te.launch.core.persistence.DefaultPersistenceDelegate;
+import org.eclipse.tcf.te.launch.core.persistence.filetransfer.FileTransfersPersistenceDelegate;
+import org.eclipse.tcf.te.launch.core.persistence.launchcontext.LaunchContextsPersistenceDelegate;
+import org.eclipse.tcf.te.launch.core.persistence.projects.ReferencedProjectItem;
+import org.eclipse.tcf.te.launch.core.persistence.projects.ReferencedProjectsPersistenceDelegate;
+import org.eclipse.tcf.te.launch.core.selection.interfaces.IProjectSelectionContext;
+import org.eclipse.tcf.te.launch.core.selection.interfaces.IRemoteSelectionContext;
+import org.eclipse.tcf.te.launch.core.selection.interfaces.ISelectionContext;
+import org.eclipse.tcf.te.runtime.model.interfaces.IModelNode;
+import org.eclipse.tcf.te.runtime.services.ServiceManager;
+import org.eclipse.tcf.te.runtime.services.filetransfer.FileTransferItem;
+import org.eclipse.tcf.te.runtime.services.interfaces.IPropertiesAccessService;
+import org.eclipse.tcf.te.runtime.services.interfaces.constants.IPropertiesAccessServiceConstants;
+import org.eclipse.tcf.te.runtime.services.interfaces.filetransfer.IFileTransferItem;
+import org.eclipse.tcf.te.tcf.launch.core.interfaces.IRemoteAppLaunchAttributes;
+
+/**
+ * RemoteAppLaunchManagerDelegate
+ */
+public class RemoteAppLaunchManagerDelegate extends DefaultLaunchManagerDelegate {
+
+ private static final String[] MANDATORY_CONFIG_ATTRIBUTES = new String[] {
+ ILaunchContextLaunchAttributes.ATTR_LAUNCH_CONTEXTS,
+ IRemoteAppLaunchAttributes.ATTR_PROCESS_IMAGE
+ };
+
+ /**
+ * Constructor.
+ */
+ public RemoteAppLaunchManagerDelegate() {
+ super();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.launch.core.lm.delegates.DefaultLaunchManagerDelegate#initLaunchConfigAttributes(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy, org.eclipse.tcf.te.launch.core.lm.interfaces.ILaunchSpecification)
+ */
+ @Override
+ public void initLaunchConfigAttributes(ILaunchConfigurationWorkingCopy wc, ILaunchSpecification launchSpec) {
+ super.initLaunchConfigAttributes(wc, launchSpec);
+
+ if (launchSpec.hasAttribute(ILaunchContextLaunchAttributes.ATTR_LAUNCH_CONTEXTS)) {
+ wc.setAttribute(ILaunchContextLaunchAttributes.ATTR_LAUNCH_CONTEXTS, (String)launchSpec.getAttribute(ILaunchContextLaunchAttributes.ATTR_LAUNCH_CONTEXTS).getValue());
+ }
+ if (launchSpec.hasAttribute(IRemoteAppLaunchAttributes.ATTR_PROCESS_IMAGE)) {
+ wc.setAttribute(IRemoteAppLaunchAttributes.ATTR_PROCESS_IMAGE, (String)launchSpec.getAttribute(IRemoteAppLaunchAttributes.ATTR_PROCESS_IMAGE).getValue());
+ }
+ if (launchSpec.hasAttribute(IFileTransferLaunchAttributes.ATTR_FILE_TRANSFERS)) {
+ wc.setAttribute(IFileTransferLaunchAttributes.ATTR_FILE_TRANSFERS, (String)launchSpec.getAttribute(IFileTransferLaunchAttributes.ATTR_FILE_TRANSFERS).getValue());
+ }
+ if (launchSpec.hasAttribute(IReferencedProjectLaunchAttributes.ATTR_REFERENCED_PROJECTS)) {
+ wc.setAttribute(IReferencedProjectLaunchAttributes.ATTR_REFERENCED_PROJECTS, (String)launchSpec.getAttribute(IReferencedProjectLaunchAttributes.ATTR_REFERENCED_PROJECTS).getValue());
+ }
+ }
+
+ @Override
+ public void updateLaunchConfig(ILaunchConfigurationWorkingCopy wc, ISelectionContext selContext, boolean replace) {
+ super.updateLaunchConfig(wc, selContext, replace);
+
+ if (selContext instanceof IProjectSelectionContext) {
+ List<IFileTransferItem> transfers;
+ List<IReferencedProjectItem> projects;
+ String processPath;
+ if (replace) {
+ transfers = new ArrayList<IFileTransferItem>();
+ projects = new ArrayList<IReferencedProjectItem>();
+ processPath = getProcessImageAndSetProjectAndTransfer((IProjectSelectionContext)selContext, transfers, projects);
+
+ FileTransfersPersistenceDelegate.setFileTransfers(wc, transfers.toArray(new IFileTransferItem[transfers.size()]));
+ ReferencedProjectsPersistenceDelegate.setReferencedProjects(wc, projects.toArray(new IReferencedProjectItem[projects.size()]));
+ if (processPath != null && processPath.trim().length() > 0) {
+ DefaultPersistenceDelegate.setAttribute(wc, IRemoteAppLaunchAttributes.ATTR_PROCESS_IMAGE, processPath);
+ }
+ }
+ else {
+ transfers = new ArrayList<IFileTransferItem>(Arrays.asList(FileTransfersPersistenceDelegate.getFileTransfers(wc)));
+ projects = new ArrayList<IReferencedProjectItem>(Arrays.asList(ReferencedProjectsPersistenceDelegate.getReferencedProjects(wc)));
+ processPath = getProcessImageAndSetProjectAndTransfer((IProjectSelectionContext)selContext, transfers, projects);
+
+ FileTransfersPersistenceDelegate.setFileTransfers(wc, transfers.toArray(new IFileTransferItem[transfers.size()]));
+ ReferencedProjectsPersistenceDelegate.setReferencedProjects(wc, projects.toArray(new IReferencedProjectItem[projects.size()]));
+ if (processPath != null && processPath.trim().length() > 0 && !DefaultPersistenceDelegate.hasAttribute(wc, IRemoteAppLaunchAttributes.ATTR_PROCESS_IMAGE)) {
+ DefaultPersistenceDelegate.setAttribute(wc, IRemoteAppLaunchAttributes.ATTR_PROCESS_IMAGE, processPath);
+ }
+ }
+ }
+ else if (selContext instanceof IRemoteSelectionContext) {
+ IRemoteSelectionContext remoteCtx = (IRemoteSelectionContext)selContext;
+ LaunchContextsPersistenceDelegate.setLaunchContexts(wc, new IModelNode[]{remoteCtx.getRemoteCtx()});
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.launch.core.lm.delegates.DefaultLaunchManagerDelegate#addLaunchSpecAttributes(org.eclipse.tcf.te.launch.core.lm.interfaces.ILaunchSpecification, java.lang.String, org.eclipse.tcf.te.launch.core.selection.interfaces.ISelectionContext)
+ */
+ @Override
+ protected ILaunchSpecification addLaunchSpecAttributes(ILaunchSpecification launchSpec, String launchConfigTypeId, ISelectionContext selectionContext) {
+ launchSpec = super.addLaunchSpecAttributes(launchSpec, launchConfigTypeId, selectionContext);
+
+ if (selectionContext instanceof IRemoteSelectionContext) {
+ List<IModelNode> launchContexts = new ArrayList<IModelNode>(Arrays.asList(LaunchContextsPersistenceDelegate.getLaunchContexts(launchSpec)));
+ IModelNode remoteCtx = ((IRemoteSelectionContext)selectionContext).getRemoteCtx();
+ if (!launchContexts.contains(remoteCtx)) {
+ launchContexts.add(remoteCtx);
+ LaunchContextsPersistenceDelegate.setLaunchContexts(launchSpec, launchContexts.toArray(new IModelNode[launchContexts.size()]));
+ }
+
+ launchSpec.setLaunchConfigName(getDefaultLaunchName(launchSpec));
+ }
+ else if (selectionContext instanceof IProjectSelectionContext) {
+ List<IFileTransferItem> transfers = new ArrayList<IFileTransferItem>(Arrays.asList(FileTransfersPersistenceDelegate.getFileTransfers(launchSpec)));
+ List<IReferencedProjectItem> projects = new ArrayList<IReferencedProjectItem>(Arrays.asList(ReferencedProjectsPersistenceDelegate.getReferencedProjects(launchSpec)));
+ String processPath = getProcessImageAndSetProjectAndTransfer((IProjectSelectionContext)selectionContext, transfers, projects);
+
+ FileTransfersPersistenceDelegate.setFileTransfers(launchSpec, transfers.toArray(new IFileTransferItem[transfers.size()]));
+ ReferencedProjectsPersistenceDelegate.setReferencedProjects(launchSpec, projects.toArray(new IReferencedProjectItem[projects.size()]));
+ launchSpec.addAttribute(IRemoteAppLaunchAttributes.ATTR_PROCESS_IMAGE, processPath);
+
+ launchSpec.setLaunchConfigName(getDefaultLaunchName(launchSpec));
+ }
+
+ return launchSpec;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.launch.core.lm.delegates.DefaultLaunchManagerDelegate#getDefaultLaunchName(org.eclipse.tcf.te.launch.core.lm.interfaces.ILaunchSpecification)
+ */
+ @Override
+ public String getDefaultLaunchName(ILaunchSpecification launchSpec) {
+ IModelNode[] contexts = LaunchContextsPersistenceDelegate.getLaunchContexts(launchSpec);
+ String processPath = (String)launchSpec.getAttribute(IRemoteAppLaunchAttributes.ATTR_PROCESS_IMAGE, null);
+ String name = getDefaultLaunchName((contexts != null && contexts.length > 0 ? contexts[0] : null), processPath);
+ return name.trim().length() > 0 ? name.trim() : super.getDefaultLaunchName(launchSpec);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.launch.core.lm.delegates.DefaultLaunchManagerDelegate#getDefaultLaunchName(org.eclipse.debug.core.ILaunchConfiguration)
+ */
+ @Override
+ public String getDefaultLaunchName(ILaunchConfiguration launchConfig) {
+ IModelNode[] contexts = LaunchContextsPersistenceDelegate.getLaunchContexts(launchConfig);
+ String processPath = DefaultPersistenceDelegate.getAttribute(launchConfig, IRemoteAppLaunchAttributes.ATTR_PROCESS_IMAGE, (String)null);
+ String name = getDefaultLaunchName((contexts != null && contexts.length > 0 ? contexts[0] : null), processPath);
+ return name.trim().length() > 0 ? name.trim() : super.getDefaultLaunchName(launchConfig);
+ }
+
+ private String getDefaultLaunchName(IModelNode context, String processPath) {
+ String name = ""; //$NON-NLS-1$
+ if (processPath != null) {
+ name += new Path(processPath).lastSegment();
+ }
+ if (context != null) {
+ IPropertiesAccessService service = ServiceManager.getInstance().getService(context, IPropertiesAccessService.class);
+ Object dnsName = service != null ? service.getProperty(context, "dns.name.transient") : null; //$NON-NLS-1$
+ String ctxName = service != null ? (String)service.getTargetAddress(context).get(IPropertiesAccessServiceConstants.PROP_ADDRESS) : null;
+ ctxName = dnsName != null && dnsName.toString().trim().length() > 0 ? dnsName.toString().trim() : ctxName;
+
+ name += " (" + ctxName + ")"; //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ return name.trim();
+ }
+
+ private String getProcessImageAndSetProjectAndTransfer(IProjectSelectionContext prjContext, List<IFileTransferItem> transfers, List<IReferencedProjectItem> projects) {
+ String processName = null;
+ String processPath = null;
+
+ boolean added = false;
+ for (Object selection : prjContext.getSelections()) {
+ if (selection instanceof IPath) {
+ IPath path = (IPath)selection;
+ IFileTransferItem transfer = new FileTransferItem(path, new Path("/tmp/")); //$NON-NLS-1$
+ if (!transfers.contains(transfer)) {
+ transfers.add(transfer);
+ }
+ if (!added) {
+ processName = path.lastSegment();
+ processPath = "/tmp/" + processName; //$NON-NLS-1$
+ }
+ added = true;
+ }
+ }
+
+ IReferencedProjectItem project = new ReferencedProjectItem(prjContext.getProjectCtx().getName());
+ if (!projects.contains(project)) {
+ projects.add(project);
+ }
+
+ return processPath;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.launch.core.lm.delegates.DefaultLaunchManagerDelegate#validate(java.lang.String, org.eclipse.debug.core.ILaunchConfiguration)
+ */
+ @Override
+ public void validate(String launchMode, ILaunchConfiguration launchConfig) throws LaunchServiceException {
+ super.validate(launchMode, launchConfig);
+
+ StringBuilder missingAttributes = new StringBuilder();
+ for (String attribute : MANDATORY_CONFIG_ATTRIBUTES) {
+ if (!isValidAttribute(attribute, launchConfig, launchMode)) {
+ if (missingAttributes.length() == 0) {
+ missingAttributes.append(attribute);
+ } else {
+ missingAttributes.append(", "); //$NON-NLS-1$
+ missingAttributes.append(attribute);
+ }
+ }
+ }
+ if (missingAttributes.length() > 0) {
+ throw new LaunchServiceException("Missing launch configuration attributes: " + '\n' + missingAttributes.toString(), LaunchServiceException.TYPE_MISSING_LAUNCH_CONFIG_ATTR); //$NON-NLS-1$
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.launch.core.lm.delegates.DefaultLaunchManagerDelegate#equals(java.lang.String, java.lang.Object, java.lang.Object, org.eclipse.tcf.te.launch.core.lm.interfaces.ILaunchSpecification, org.eclipse.debug.core.ILaunchConfiguration, java.lang.String)
+ */
+ @Override
+ protected int equals(String attributeKey, Object specValue, Object confValue, ILaunchSpecification launchSpec, ILaunchConfiguration launchConfig, String launchMode) {
+
+ if (IRemoteAppLaunchAttributes.ATTR_PROCESS_IMAGE.equals(attributeKey)) {
+ // get match of object
+ int match = specValue.equals(confValue) ? FULL_MATCH : NO_MATCH;
+ // compare objects in the list when they are not already equal
+ if (match != FULL_MATCH) {
+ IPath confPath = new Path(confValue.toString());
+ IPath specPath = new Path(specValue.toString());
+
+ if (confPath.lastSegment().equals(specPath.lastSegment())) {
+ match = PARTIAL_MATCH;
+ }
+ else {
+ match = NO_MATCH;
+ }
+ }
+ return match;
+ }
+
+ return super.equals(attributeKey, specValue, confValue, launchSpec, launchConfig, launchMode);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.launch.core.lm.delegates.DefaultLaunchManagerDelegate#getNumAttributes()
+ */
+ @Override
+ protected int getNumAttributes() {
+ return 5;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.launch.core.lm.delegates.DefaultLaunchManagerDelegate#getAttributeRanking(java.lang.String)
+ */
+ @Override
+ protected int getAttributeRanking(String attributeKey) {
+ if (ILaunchContextLaunchAttributes.ATTR_LAUNCH_CONTEXTS.equals(attributeKey)) {
+ return getNumAttributes() * 32;
+ }
+ else if (IRemoteAppLaunchAttributes.ATTR_PROCESS_IMAGE.equals(attributeKey)) {
+ return getNumAttributes() * 16;
+ }
+ else if (IRemoteAppLaunchAttributes.ATTR_PROCESS_ARGUMENTS.equals(attributeKey)) {
+ return getNumAttributes() * 8;
+ }
+ else if (IFileTransferLaunchAttributes.ATTR_FILE_TRANSFERS.equals(attributeKey)) {
+ return getNumAttributes() * 4;
+ }
+ else if (IReferencedProjectLaunchAttributes.ATTR_REFERENCED_PROJECTS.equals(attributeKey)) {
+ return getNumAttributes() * 2;
+ }
+ else {
+ return 1;
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.launch.core.lm.delegates.DefaultLaunchManagerDelegate#getDescription(org.eclipse.debug.core.ILaunchConfiguration)
+ */
+ @Override
+ public String getDescription(ILaunchConfiguration config) {
+ String image = DefaultPersistenceDelegate.getAttribute(config, IRemoteAppLaunchAttributes.ATTR_PROCESS_IMAGE, (String)null);
+ String args = DefaultPersistenceDelegate.getAttribute(config, IRemoteAppLaunchAttributes.ATTR_PROCESS_ARGUMENTS, ""); //$NON-NLS-1$
+ if (image != null) {
+ return new Path(image).toPortableString() + " " + args; //$NON-NLS-1$
+ }
+ return ""; //$NON-NLS-1$
+ }
+}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.ui/src/org/eclipse/tcf/te/tcf/launch/ui/editor/AbstractTcfLaunchTabContainerEditorPage.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.ui/src/org/eclipse/tcf/te/tcf/launch/ui/editor/AbstractTcfLaunchTabContainerEditorPage.java
index 7c17fff43..299bb8716 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.ui/src/org/eclipse/tcf/te/tcf/launch/ui/editor/AbstractTcfLaunchTabContainerEditorPage.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.ui/src/org/eclipse/tcf/te/tcf/launch/ui/editor/AbstractTcfLaunchTabContainerEditorPage.java
@@ -12,6 +12,7 @@ package org.eclipse.tcf.te.tcf.launch.ui.editor;
import java.util.HashMap;
import java.util.Map;
+import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
import org.eclipse.debug.core.ILaunchManager;
@@ -63,7 +64,8 @@ public abstract class AbstractTcfLaunchTabContainerEditorPage extends AbstractLa
ILaunchConfigurationWorkingCopy wc = null;
if (peerModel != null) {
IPropertiesAccessService service = ServiceManager.getInstance().getService(peerModel, IPropertiesAccessService.class);
- if (service != null && service.getProperty(peerModel, PROP_LAUNCH_CONFIG_WC) instanceof ILaunchConfigurationWorkingCopy) {
+ Assert.isNotNull(service);
+ if (service.getProperty(peerModel, PROP_LAUNCH_CONFIG_WC) instanceof ILaunchConfigurationWorkingCopy) {
wc = (ILaunchConfigurationWorkingCopy)service.getProperty(peerModel, PROP_LAUNCH_CONFIG_WC);
}
else {
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/internal/nls/Messages.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/internal/nls/Messages.java
index 7a053e140..c52249d53 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/internal/nls/Messages.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/internal/nls/Messages.java
@@ -58,9 +58,7 @@ public class Messages extends NLS {
if (key != null) {
try {
Field field = Messages.class.getDeclaredField(key);
- if (field != null) {
- return (String)field.get(null);
- }
+ return (String)field.get(null);
} catch (Exception e) { /* ignored on purpose */ }
}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/nodes/LocatorModel.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/nodes/LocatorModel.java
index 5e2833a7b..5a08691af 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/nodes/LocatorModel.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/nodes/LocatorModel.java
@@ -333,13 +333,12 @@ public class LocatorModel extends PlatformObject implements ILocatorModel {
}
IScanner scanner = getScanner();
+ Assert.isNotNull(scanner);
- if (scanner != null) {
- // Pass on the schedule parameter
- Map<String, Object> config = new HashMap<String, Object>(scanner.getConfiguration());
- config.put(IScanner.PROP_SCHEDULE, Long.valueOf(schedule));
- scanner.setConfiguration(config);
- }
+ // Pass on the schedule parameter
+ Map<String, Object> config = new HashMap<String, Object>(scanner.getConfiguration());
+ config.put(IScanner.PROP_SCHEDULE, Long.valueOf(schedule));
+ scanner.setConfiguration(config);
// The default scanner implementation is a job.
// -> schedule here if it is a job
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.processes.core/src/org/eclipse/tcf/te/tcf/processes/core/launcher/ProcessStreamsListener.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.processes.core/src/org/eclipse/tcf/te/tcf/processes/core/launcher/ProcessStreamsListener.java
index 8b46198e2..51df9e9d4 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.processes.core/src/org/eclipse/tcf/te/tcf/processes/core/launcher/ProcessStreamsListener.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.processes.core/src/org/eclipse/tcf/te/tcf/processes/core/launcher/ProcessStreamsListener.java
@@ -513,9 +513,9 @@ public class ProcessStreamsListener implements IStreams.StreamsListener, IProces
synchronized (this) {
// Mark the runnable definitely stopped
stopped = true;
- // Invoke the callback directly, if any
- if (callback != null) callback.done(this, Status.OK_STATUS);
}
+ // Invoke the callback directly, if any
+ if (callback != null) callback.done(this, Status.OK_STATUS);
return;
}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.terminals.core/src/org/eclipse/tcf/te/tcf/terminals/core/launcher/TerminalsStreamsListener.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.terminals.core/src/org/eclipse/tcf/te/tcf/terminals/core/launcher/TerminalsStreamsListener.java
index 3dc3299aa..d0be4f78b 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.terminals.core/src/org/eclipse/tcf/te/tcf/terminals/core/launcher/TerminalsStreamsListener.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.terminals.core/src/org/eclipse/tcf/te/tcf/terminals/core/launcher/TerminalsStreamsListener.java
@@ -318,9 +318,9 @@ public class TerminalsStreamsListener implements IStreams.StreamsListener, ITerm
synchronized (this) {
// Mark the runnable definitely stopped
stopped = true;
- // Disconnect is done, ignore any error, invoke the callback
- if (getCallback() != null) getCallback().done(this, Status.OK_STATUS);
}
+ // Disconnect is done, ignore any error, invoke the callback
+ if (getCallback() != null) getCallback().done(this, Status.OK_STATUS);
}
});
} else {
@@ -520,9 +520,9 @@ public class TerminalsStreamsListener implements IStreams.StreamsListener, ITerm
synchronized (this) {
// Mark the runnable definitely stopped
stopped = true;
- // Invoke the callback directly, if any
- if (callback != null) callback.done(this, Status.OK_STATUS);
}
+ // Invoke the callback directly, if any
+ if (callback != null) callback.done(this, Status.OK_STATUS);
return;
}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/navigator/DelegatingLabelProvider.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/navigator/DelegatingLabelProvider.java
index 71b186a66..7d24cbce8 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/navigator/DelegatingLabelProvider.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/navigator/DelegatingLabelProvider.java
@@ -96,7 +96,7 @@ public class DelegatingLabelProvider extends LabelProvider implements ILabelDeco
}
String label = builder.toString();
- if (label != null && !"".equals(label.trim())) { //$NON-NLS-1$
+ if (!"".equals(label.trim())) { //$NON-NLS-1$
return label;
}
} else if (element instanceof PeerRedirectorGroupNode) {
@@ -205,7 +205,7 @@ public class DelegatingLabelProvider extends LabelProvider implements ILabelDeco
label = builder.toString();
- if (label != null && !"".equals(label.trim()) && !"<noname>".equals(label.trim())) { //$NON-NLS-1$ //$NON-NLS-2$
+ if (!"".equals(label.trim()) && !"<noname>".equals(label.trim())) { //$NON-NLS-1$ //$NON-NLS-2$
return label;
}
}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/nls/Messages.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/nls/Messages.java
index 1b5a71ef2..756e19902 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/nls/Messages.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/nls/Messages.java
@@ -40,9 +40,7 @@ public class Messages extends NLS {
if (key != null) {
try {
Field field = Messages.class.getDeclaredField(key);
- if (field != null) {
- return (String)field.get(null);
- }
+ return (String)field.get(null);
} catch (Exception e) { /* ignored on purpose */ }
}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui.controls/src/org/eclipse/tcf/te/ui/controls/nls/Messages.java b/target_explorer/plugins/org.eclipse.tcf.te.ui.controls/src/org/eclipse/tcf/te/ui/controls/nls/Messages.java
index 89b45200b..e5a4af3eb 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.ui.controls/src/org/eclipse/tcf/te/ui/controls/nls/Messages.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.ui.controls/src/org/eclipse/tcf/te/ui/controls/nls/Messages.java
@@ -58,9 +58,7 @@ public class Messages extends NLS {
if (key != null) {
try {
Field field = Messages.class.getDeclaredField(key);
- if (field != null) {
- return (String)field.get(null);
- }
+ return (String)field.get(null);
} catch (Exception e) { /* ignored on purpose */ }
}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui.swt/src/org/eclipse/tcf/te/ui/swt/SWTControlUtil.java b/target_explorer/plugins/org.eclipse.tcf.te.ui.swt/src/org/eclipse/tcf/te/ui/swt/SWTControlUtil.java
index 0037fe080..f9f292fdf 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.ui.swt/src/org/eclipse/tcf/te/ui/swt/SWTControlUtil.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.ui.swt/src/org/eclipse/tcf/te/ui/swt/SWTControlUtil.java
@@ -700,7 +700,7 @@ public final class SWTControlUtil {
if (image == null || image.getImageData().data == null) {
Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
image = makeShot(shell, checked||grayed, grayed, enabled);
- if (image != null && image.getImageData().data != null) {
+ if (image.getImageData().data != null) {
JFaceResources.getImageRegistry().put(key, image);
}
}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui.swt/src/org/eclipse/tcf/te/ui/swt/nls/Messages.java b/target_explorer/plugins/org.eclipse.tcf.te.ui.swt/src/org/eclipse/tcf/te/ui/swt/nls/Messages.java
index 1161f869f..d6e6a53ad 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.ui.swt/src/org/eclipse/tcf/te/ui/swt/nls/Messages.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.ui.swt/src/org/eclipse/tcf/te/ui/swt/nls/Messages.java
@@ -40,9 +40,7 @@ public class Messages extends NLS {
if (key != null) {
try {
Field field = Messages.class.getDeclaredField(key);
- if (field != null) {
- return (String)field.get(null);
- }
+ return (String)field.get(null);
} catch (Exception e) { /* ignored on purpose */ }
}

Back to the top