Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUwe Stieber2012-04-30 12:46:44 +0000
committerUwe Stieber2012-04-30 12:46:44 +0000
commitbc412002ea7fec6a6d84fb24af9663afc67299d0 (patch)
tree2b3239ba509632a8f8b2369e966e0738a3a59b4a
parentccf966c976415fc331d963c7392990529ca56aad (diff)
downloadorg.eclipse.tcf-bc412002ea7fec6a6d84fb24af9663afc67299d0.tar.gz
org.eclipse.tcf-bc412002ea7fec6a6d84fb24af9663afc67299d0.tar.xz
org.eclipse.tcf-bc412002ea7fec6a6d84fb24af9663afc67299d0.zip
Target Explorer: "Add To" category command handling rework
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.runtime/src/org/eclipse/tcf/te/runtime/extensions/ExecutableExtension.java19
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/plugin.properties8
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/plugin.xml102
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/handler/AddToFavoritesCommandHandler.java58
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/handler/RemoveFromFavoritesCommandHandler.java58
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/internal/adapters/AdapterFactory.java4
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/internal/adapters/CategorizableAdapter.java96
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/navigator/ContentProviderDelegate.java14
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.ui.views/plugin.properties5
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.ui.views/plugin.xml58
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.ui.views/schema/categories.exsd2
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/categories/Category.java14
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/interfaces/categories/ICategorizable.java35
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/internal/categories/AbstractCategoryContributionItem.java301
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/internal/categories/CategoryAddToContributionItem.java128
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/internal/categories/CategoryPropertyTester.java45
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/nls/Messages.java6
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/nls/Messages.properties6
18 files changed, 699 insertions, 260 deletions
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.runtime/src/org/eclipse/tcf/te/runtime/extensions/ExecutableExtension.java b/target_explorer/plugins/org.eclipse.tcf.te.runtime/src/org/eclipse/tcf/te/runtime/extensions/ExecutableExtension.java
index 3859e43b7..1c8cfc3cd 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.runtime/src/org/eclipse/tcf/te/runtime/extensions/ExecutableExtension.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.runtime/src/org/eclipse/tcf/te/runtime/extensions/ExecutableExtension.java
@@ -133,4 +133,23 @@ public class ExecutableExtension extends PlatformObject implements IExecutableEx
public String getDescription() {
return description != null ? description.trim() : ""; //$NON-NLS-1$
}
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ @Override
+ public boolean equals(Object obj) {
+ if (obj instanceof ExecutableExtension) {
+ return id.equals(((ExecutableExtension)obj).id);
+ }
+ return super.equals(obj);
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#hashCode()
+ */
+ @Override
+ public int hashCode() {
+ return id.hashCode();
+ }
}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/plugin.properties b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/plugin.properties
index 402aa5828..fbc3693d2 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/plugin.properties
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/plugin.properties
@@ -52,11 +52,3 @@ command.redirect.tooltip=Redirect communication to this node through a proxy
command.resetredirect.name=Reset Redirect Command
command.resetredirect.label=Reset Redirect
command.resetredirect.tooltip=Reset communication redirection of this node
-
-command.removefromfavorites.name=Remove From Favorites Command
-command.removefromfavorites.label=Remove From Favorites
-command.removefromfavorites.tooltip=Remove the selected nodes from the Favorites category
-
-command.addtofavorites.name=Add To Favorites Command
-command.addtofavorites.label=Add To Favorites
-command.addtofavorites.tooltip=Add the selected nodes to the Favorites category
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/plugin.xml b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/plugin.xml
index 4087d6c8d..aaabfedba 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/plugin.xml
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/plugin.xml
@@ -233,47 +233,6 @@
</visibleWhen>
</command>
</menuContribution>
-
- <menuContribution locationURI="popup:org.eclipse.tcf.te.ui.views.View#Popup?after=group.categories">
- <command
- commandId="org.eclipse.tcf.te.tcf.ui.command.addtofavorites"
- helpContextId="org.eclipse.tcf.te.tcf.ui.command_AddToFavorites"
- id="org.eclipse.tcf.te.tcf.ui.commands.addtofavorites"
- label="%command.addtofavorites.label"
- mnemonic="d"
- style="push"
- tooltip="%command.addtofavorites.tooltip">
- <visibleWhen checkEnabled="false">
- <with variable="selection">
- <count value="1"/>
- <iterate operator="and" ifEmpty="false">
- <and>
- <instanceof value="org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerModel"/>
- </and>
- </iterate>
- </with>
- </visibleWhen>
- </command>
- <command
- commandId="org.eclipse.tcf.te.tcf.ui.command.removefromfavorites"
- helpContextId="org.eclipse.tcf.te.tcf.ui.command_RemoveFromFavorites"
- id="org.eclipse.tcf.te.tcf.ui.commands.removefromfavorites"
- label="%command.removefromfavorites.label"
- mnemonic="m"
- style="push"
- tooltip="%command.removefromfavorites.tooltip">
- <visibleWhen checkEnabled="false">
- <with variable="selection">
- <count value="1"/>
- <iterate operator="and" ifEmpty="false">
- <and>
- <instanceof value="org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerModel"/>
- </and>
- </iterate>
- </with>
- </visibleWhen>
- </command>
- </menuContribution>
</extension>
<!-- Command contributions -->
@@ -290,18 +249,6 @@
id="org.eclipse.tcf.te.tcf.ui.command.resetredirect"
name="%command.resetredirect.name">
</command>
- <command
- categoryId="org.eclipse.tcf.te.ui.commands.category"
- helpContextId="org.eclipse.tcf.te.tcf.ui.command_AddToFavorites"
- id="org.eclipse.tcf.te.tcf.ui.command.addtofavorites"
- name="%command.addtofavorites.name">
- </command>
- <command
- categoryId="org.eclipse.tcf.te.ui.commands.category"
- helpContextId="org.eclipse.tcf.te.tcf.ui.command_RemoveFromFavorites"
- id="org.eclipse.tcf.te.tcf.ui.command.removefromfavorites"
- name="%command.removefromfavorites.name">
- </command>
</extension>
<!-- Handler contributions -->
@@ -347,55 +294,6 @@
</with>
</enabledWhen>
</handler>
-
- <handler
- class="org.eclipse.tcf.te.tcf.ui.handler.AddToFavoritesCommandHandler"
- commandId="org.eclipse.tcf.te.tcf.ui.command.addtofavorites">
- <activeWhen>
- <with variable="activePartId">
- <equals value="org.eclipse.tcf.te.ui.views.View"/>
- </with>
- </activeWhen>
- <enabledWhen>
- <with variable="selection">
- <and>
- <count value="1"/>
- <not>
- <test property="org.eclipse.tcf.te.ui.views.parentCategoryId" value="org.eclipse.tcf.te.ui.views.category.favorites"/>
- </not>
- <iterate operator="and" ifEmpty="false">
- <and>
- <instanceof value="org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerModel"/>
- <not>
- <test property="org.eclipse.tcf.te.ui.views.belongsTo" value="org.eclipse.tcf.te.ui.views.category.favorites"/>
- </not>
- </and>
- </iterate>
- </and>
- </with>
- </enabledWhen>
- </handler>
-
- <handler
- class="org.eclipse.tcf.te.tcf.ui.handler.RemoveFromFavoritesCommandHandler"
- commandId="org.eclipse.tcf.te.tcf.ui.command.removefromfavorites">
- <activeWhen>
- <with variable="activePartId">
- <equals value="org.eclipse.tcf.te.ui.views.View"/>
- </with>
- </activeWhen>
- <enabledWhen>
- <with variable="selection">
- <and>
- <count value="1"/>
- <test property="org.eclipse.tcf.te.ui.views.parentCategoryId" value="org.eclipse.tcf.te.ui.views.category.favorites"/>
- <iterate operator="and" ifEmpty="false">
- <instanceof value="org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerModel"/>
- </iterate>
- </and>
- </with>
- </enabledWhen>
- </handler>
</extension>
<!-- Tabbed properties view contributions -->
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/handler/AddToFavoritesCommandHandler.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/handler/AddToFavoritesCommandHandler.java
deleted file mode 100644
index 4c59be421..000000000
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/handler/AddToFavoritesCommandHandler.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2012 Wind River Systems, Inc. and others. All rights reserved.
- * This program and the accompanying materials are made available under the terms
- * of the Eclipse Public License v1.0 which accompanies this distribution, and is
- * available at http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Wind River Systems - initial API and implementation
- *******************************************************************************/
-package org.eclipse.tcf.te.tcf.ui.handler;
-
-import java.util.Iterator;
-
-import org.eclipse.core.commands.AbstractHandler;
-import org.eclipse.core.commands.ExecutionEvent;
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerModel;
-import org.eclipse.tcf.te.ui.views.Managers;
-import org.eclipse.tcf.te.ui.views.ViewsUtil;
-import org.eclipse.tcf.te.ui.views.interfaces.IUIConstants;
-import org.eclipse.ui.handlers.HandlerUtil;
-
-/**
- * Command handler implementation: Add the selected nodes to the "Favorites" categories.
- */
-public class AddToFavoritesCommandHandler extends AbstractHandler {
-
- /* (non-Javadoc)
- * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
- */
- @Override
- public Object execute(ExecutionEvent event) throws ExecutionException {
- // Get the active selection
- ISelection selection = HandlerUtil.getCurrentSelection(event);
- if (selection instanceof IStructuredSelection && !selection.isEmpty()) {
- boolean refresh = false;
- Iterator<?> iterator = ((IStructuredSelection)selection).iterator();
- while (iterator.hasNext()) {
- Object element = iterator.next();
- if (element instanceof IPeerModel) {
- String peerId = ((IPeerModel)element).getPeerId();
- if (!Managers.getCategoryManager().belongsTo(IUIConstants.ID_CAT_FAVORITES, peerId)) {
- Managers.getCategoryManager().add(IUIConstants.ID_CAT_FAVORITES, peerId);
- refresh = true;
- }
- }
- }
-
- // Refresh the view
- if (refresh) ViewsUtil.refresh(IUIConstants.ID_EXPLORER);
- }
-
- return null;
- }
-
-}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/handler/RemoveFromFavoritesCommandHandler.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/handler/RemoveFromFavoritesCommandHandler.java
deleted file mode 100644
index baa065d86..000000000
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/handler/RemoveFromFavoritesCommandHandler.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2012 Wind River Systems, Inc. and others. All rights reserved.
- * This program and the accompanying materials are made available under the terms
- * of the Eclipse Public License v1.0 which accompanies this distribution, and is
- * available at http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Wind River Systems - initial API and implementation
- *******************************************************************************/
-package org.eclipse.tcf.te.tcf.ui.handler;
-
-import java.util.Iterator;
-
-import org.eclipse.core.commands.AbstractHandler;
-import org.eclipse.core.commands.ExecutionEvent;
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerModel;
-import org.eclipse.tcf.te.ui.views.Managers;
-import org.eclipse.tcf.te.ui.views.ViewsUtil;
-import org.eclipse.tcf.te.ui.views.interfaces.IUIConstants;
-import org.eclipse.ui.handlers.HandlerUtil;
-
-/**
- * Command handler implementation: Remove the selected nodes from the "Favorites" categories.
- */
-public class RemoveFromFavoritesCommandHandler extends AbstractHandler {
-
- /* (non-Javadoc)
- * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
- */
- @Override
- public Object execute(ExecutionEvent event) throws ExecutionException {
- // Get the active selection
- ISelection selection = HandlerUtil.getCurrentSelection(event);
- if (selection instanceof IStructuredSelection && !selection.isEmpty()) {
- boolean refresh = false;
- Iterator<?> iterator = ((IStructuredSelection)selection).iterator();
- while (iterator.hasNext()) {
- Object element = iterator.next();
- if (element instanceof IPeerModel) {
- String peerId = ((IPeerModel)element).getPeerId();
- if (Managers.getCategoryManager().belongsTo(IUIConstants.ID_CAT_FAVORITES, peerId)) {
- Managers.getCategoryManager().remove(IUIConstants.ID_CAT_FAVORITES, peerId);
- refresh = true;
- }
- }
- }
-
- // Refresh the view
- if (refresh) ViewsUtil.refresh(IUIConstants.ID_EXPLORER);
- }
-
- return null;
- }
-
-}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/internal/adapters/AdapterFactory.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/internal/adapters/AdapterFactory.java
index 330fde4e5..2fbce6218 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/internal/adapters/AdapterFactory.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/internal/adapters/AdapterFactory.java
@@ -28,8 +28,6 @@ public class AdapterFactory implements IAdapterFactory {
private final IRefreshHandlerDelegate refreshDelegate = new RefreshHandlerDelegate();
// The delete handler delegate adapter
private final IDeleteHandlerDelegate deleteDelegate = new DeleteHandlerDelegate();
- // The categorizable element adapter
- private final ICategorizable categorizableAdapter = new CategorizableAdapter();
// The adapter class.
private Class<?>[] adapters = {
@@ -59,7 +57,7 @@ public class AdapterFactory implements IAdapterFactory {
return new PersistablePeerModel((IPeerModel)adaptableObject);
}
if (ICategorizable.class.equals(adapterType)) {
- return categorizableAdapter;
+ return new CategorizableAdapter(adaptableObject);
}
}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/internal/adapters/CategorizableAdapter.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/internal/adapters/CategorizableAdapter.java
index 258701f2e..2b0f840c0 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/internal/adapters/CategorizableAdapter.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/internal/adapters/CategorizableAdapter.java
@@ -9,26 +9,108 @@
*******************************************************************************/
package org.eclipse.tcf.te.tcf.ui.internal.adapters;
+import java.util.concurrent.atomic.AtomicBoolean;
+
import org.eclipse.core.runtime.Assert;
+import org.eclipse.tcf.protocol.Protocol;
import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerModel;
+import org.eclipse.tcf.te.ui.views.Managers;
+import org.eclipse.tcf.te.ui.views.interfaces.ICategory;
+import org.eclipse.tcf.te.ui.views.interfaces.IUIConstants;
import org.eclipse.tcf.te.ui.views.interfaces.categories.ICategorizable;
/**
* Categorizable element adapter implementation
*/
public class CategorizableAdapter implements ICategorizable {
+ // Reference to the adapted element
+ /* default */ final Object element;
- /* (non-Javadoc)
- * @see org.eclipse.tcf.te.ui.views.interfaces.categories.ICategorizable#getId(java.lang.Object)
- */
- @Override
- public String getId(Object element) {
- Assert.isNotNull(element);
+ /**
+ * Constructor.
+ *
+ * @param element The adapted element. Must not be <code>null</code>.
+ */
+ public CategorizableAdapter(Object element) {
+ Assert.isNotNull(element);
+ this.element = element;
+ }
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.ui.views.interfaces.categories.ICategorizable#getId()
+ */
+ @Override
+ public String getId() {
if (element instanceof IPeerModel) {
return ((IPeerModel)element).getPeerId();
}
-
return null;
}
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.ui.views.interfaces.categories.ICategorizable#isValid(org.eclipse.tcf.te.ui.views.interfaces.categories.ICategorizable.OPERATION, org.eclipse.tcf.te.ui.views.interfaces.ICategory, org.eclipse.tcf.te.ui.views.interfaces.ICategory)
+ */
+ @Override
+ public boolean isValid(OPERATION operation, ICategory parentCategory, ICategory category) {
+ Assert.isNotNull(operation);
+ Assert.isNotNull(parentCategory);
+ Assert.isNotNull(category);
+
+ if (element instanceof IPeerModel) {
+ // ADD: Parent and destination category are the same -> not valid
+ if (OPERATION.ADD.equals(operation) && category.equals(parentCategory)) return false;
+
+ // ALL: Static peer's cannot be removed from or added to "My Targets"
+ if (IUIConstants.ID_CAT_MY_TARGETS.equals(category.getId())) {
+ final AtomicBoolean isStatic = new AtomicBoolean();
+
+ Runnable runnable = new Runnable() {
+ @Override
+ public void run() {
+ String value = ((IPeerModel)element).getPeer().getAttributes().get("static.transient"); //$NON-NLS-1$
+ isStatic.set(value != null && Boolean.parseBoolean(value.trim()));
+ }
+ };
+
+ if (Protocol.isDispatchThread()) runnable.run();
+ else Protocol.invokeAndWait(runnable);
+
+ if (isStatic.get()) return false;
+ }
+
+ // ALL: Destination is "Neighborhood" -> not valid
+ if (IUIConstants.ID_CAT_NEIGHBORHOOD.equals(category.getId())) return false;
+
+ return true;
+ }
+
+ return false;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.ui.views.interfaces.categories.ICategorizable#isEnabled(org.eclipse.tcf.te.ui.views.interfaces.categories.ICategorizable.OPERATION, org.eclipse.tcf.te.ui.views.interfaces.ICategory)
+ */
+ @Override
+ public boolean isEnabled(OPERATION operation, ICategory category) {
+ Assert.isNotNull(operation);
+ Assert.isNotNull(category);
+
+ if (element instanceof IPeerModel) {
+ // ADD: element belongs to category -> not enabled
+ if (OPERATION.ADD.equals(operation)
+ && Managers.getCategoryManager().belongsTo(category.getId(), getId())) {
+ return false;
+ }
+
+ // REMOVE: element belongs not to category -> not enabled
+ if (OPERATION.REMOVE.equals(operation)
+ && !Managers.getCategoryManager().belongsTo(category.getId(), getId())) {
+ return false;
+ }
+
+ return true;
+ }
+
+ return false;
+ }
}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/navigator/ContentProviderDelegate.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/navigator/ContentProviderDelegate.java
index d5371db32..c0d440911 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/navigator/ContentProviderDelegate.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/navigator/ContentProviderDelegate.java
@@ -96,12 +96,10 @@ public class ContentProviderDelegate implements ICommonContentProvider, ITreePat
String value = peer.getPeer().getAttributes().get("static.transient"); //$NON-NLS-1$
boolean isStatic = value != null && Boolean.parseBoolean(value.trim());
- if (System.getProperty("user.name").equals(peer.getPeer().getUserName())) { //$NON-NLS-1$
- isStatic = true;
- }
-
+ // Static peers, or if launched by current user -> add automatically to "My Targets"
+ boolean startedByCurrentUser = System.getProperty("user.name").equals(peer.getPeer().getUserName()); //$NON-NLS-1$
boolean isMyTargets = Managers.getCategoryManager().belongsTo(catID, peer.getPeerId());
- if (!isMyTargets && isStatic) {
+ if (!isMyTargets && (isStatic || startedByCurrentUser)) {
Managers.getCategoryManager().add(catID, peer.getPeerId());
isMyTargets = true;
}
@@ -116,17 +114,13 @@ public class ContentProviderDelegate implements ICommonContentProvider, ITreePat
String value = peer.getPeer().getAttributes().get("static.transient"); //$NON-NLS-1$
boolean isStatic = value != null && Boolean.parseBoolean(value.trim());
- if (System.getProperty("user.name").equals(peer.getPeer().getUserName())) { //$NON-NLS-1$
- isStatic = true;
- }
-
boolean isNeighborhood = Managers.getCategoryManager().belongsTo(catID, peer.getPeerId());
if (!isNeighborhood && !isStatic) {
Managers.getCategoryManager().add(catID, peer.getPeerId());
isNeighborhood = true;
}
- if (isNeighborhood && !candidates.contains(peer)) {
+ if ((isNeighborhood || !isStatic) && !candidates.contains(peer)) {
candidates.add(peer);
}
}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui.views/plugin.properties b/target_explorer/plugins/org.eclipse.tcf.te.ui.views/plugin.properties
index db00d846f..9d27d630e 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.ui.views/plugin.properties
+++ b/target_explorer/plugins/org.eclipse.tcf.te.ui.views/plugin.properties
@@ -60,4 +60,7 @@ command.delete.description=Delete the selected node
command.filters.label = Filters...
command.content.label = Content...
command.filters.name = Filters
-command.content.name = Content \ No newline at end of file
+command.content.name = Content
+
+menu.categories.addto.label=Add To
+menu.categories.removefrom.label=Remove From
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui.views/plugin.xml b/target_explorer/plugins/org.eclipse.tcf.te.ui.views/plugin.xml
index a031bfcc3..eeea0553f 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.ui.views/plugin.xml
+++ b/target_explorer/plugins/org.eclipse.tcf.te.ui.views/plugin.xml
@@ -287,8 +287,8 @@
<visibleWhen checkEnabled="true"/>
</menu>
</menuContribution>
- <menuContribution
- locationURI="menu:org.eclipse.tcf.te.ui.views.View?after=additions">
+
+ <menuContribution locationURI="menu:org.eclipse.tcf.te.ui.views.View?after=additions">
<separator
name="group.filters"
visible="true">
@@ -320,6 +320,39 @@
style="push">
</command>
</menuContribution>
+
+ <menuContribution locationURI="popup:org.eclipse.tcf.te.ui.views.View#Popup?after=group.categories">
+ <menu
+ id="org.eclipse.tcf.te.ui.views.menu.categories.add"
+ label="%menu.categories.addto.label">
+ <dynamic
+ id="org.eclipse.tcf.te.ui.views.dynamic.categories.add.multi"
+ class="org.eclipse.tcf.te.ui.views.internal.categories.CategoryAddToContributionItem">
+ <visibleWhen checkEnabled="false">
+ <with variable="selection">
+ <test property="org.eclipse.tcf.te.ui.views.validAddToCategoriesCount" value="(1-"/>
+ <iterate operator="and" ifEmpty="false">
+ <adapt type="org.eclipse.tcf.te.ui.views.interfaces.categories.ICategorizable"/>
+ </iterate>
+ </with>
+ </visibleWhen>
+ </dynamic>
+ </menu>
+
+ <dynamic
+ id="org.eclipse.tcf.te.ui.views.dynamic.categories.add.single"
+ class="org.eclipse.tcf.te.ui.views.internal.categories.CategoryAddToContributionItem">
+ <visibleWhen checkEnabled="false">
+ <with variable="selection">
+ <test property="org.eclipse.tcf.te.ui.views.validAddToCategoriesCount" value="1"/>
+ <iterate operator="and" ifEmpty="false">
+ <adapt type="org.eclipse.tcf.te.ui.views.interfaces.categories.ICategorizable"/>
+ </iterate>
+ </with>
+ </visibleWhen>
+ </dynamic>
+ </menuContribution>
+
</extension>
<!-- Command contributions -->
@@ -504,9 +537,26 @@
class="org.eclipse.tcf.te.ui.views.internal.categories.CategoryPropertyTester"
id="org.eclipse.tcf.te.ui.views.categories.CategoryPropertyTester"
namespace="org.eclipse.tcf.te.ui.views"
- properties="isCategoryID,parentCategoryId,belongsTo"
- type="java.lang.Object">
+ properties="isCategoryID,belongsTo"
+ type="org.eclipse.tcf.te.ui.views.interfaces.ICategory">
+ </propertyTester>
+
+ <propertyTester
+ class="org.eclipse.tcf.te.ui.views.internal.categories.CategoryPropertyTester"
+ id="org.eclipse.tcf.te.ui.views.categories.CategoryPropertyTester"
+ namespace="org.eclipse.tcf.te.ui.views"
+ properties="belongsTo"
+ type="org.eclipse.tcf.te.ui.views.interfaces.categories.ICategorizable">
</propertyTester>
+
+ <propertyTester
+ class="org.eclipse.tcf.te.ui.views.internal.categories.CategoryPropertyTester"
+ id="org.eclipse.tcf.te.ui.views.categories.CategoryPropertyTester"
+ namespace="org.eclipse.tcf.te.ui.views"
+ properties="parentCategoryId,validAddToCategoriesCount"
+ type="org.eclipse.jface.viewers.ISelection">
+ </propertyTester>
+
</extension>
<!-- Preference contributions -->
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui.views/schema/categories.exsd b/target_explorer/plugins/org.eclipse.tcf.te.ui.views/schema/categories.exsd
index 966efd3af..a32023e8e 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.ui.views/schema/categories.exsd
+++ b/target_explorer/plugins/org.eclipse.tcf.te.ui.views/schema/categories.exsd
@@ -65,7 +65,7 @@
</documentation>
</annotation>
</attribute>
- <attribute name="label" type="string">
+ <attribute name="label" type="string" use="required">
<annotation>
<documentation>
The label representing the category within the UI.
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/categories/Category.java b/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/categories/Category.java
index 17ec098c6..8e5103315 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/categories/Category.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/categories/Category.java
@@ -113,4 +113,18 @@ public class Category extends ExecutableExtension implements ICategory, IDisposa
public int getRank() {
return rank;
}
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public String toString() {
+ StringBuffer buffer = new StringBuffer(getLabel());
+ buffer.append(" ["); //$NON-NLS-1$
+ buffer.append(getId());
+ buffer.append("] {rank="); //$NON-NLS-1$
+ buffer.append(getRank());
+ buffer.append("}"); //$NON-NLS-1$
+ return buffer.toString();
+ }
}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/interfaces/categories/ICategorizable.java b/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/interfaces/categories/ICategorizable.java
index c0059abbc..ab6ccd3d3 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/interfaces/categories/ICategorizable.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/interfaces/categories/ICategorizable.java
@@ -9,17 +9,46 @@
*******************************************************************************/
package org.eclipse.tcf.te.ui.views.interfaces.categories;
+import org.eclipse.tcf.te.ui.views.interfaces.ICategory;
+
/**
* Interface to be implemented by categorizable element adapters.
*/
public interface ICategorizable {
/**
- * Returns the unique categorizable id for the given element. The id
+ * Defines the possible category operations.
+ */
+ public enum OPERATION { ADD, REMOVE }
+
+ /**
+ * Returns the unique categorizable id for the adapted element. The id
* must not change once queried and must be the same across session.
*
- * @param The element. Must not or <code>null</code>.
* @return The unique categorizable element id, or <code>null</code>.
*/
- public String getId(Object element);
+ public String getId();
+
+ /**
+ * Returns if or if not the given operation is valid for the given parent
+ * category and destination category.
+ *
+ * @param operation The operation. Must not be <code>null</code>.
+ * @param parentCategory The parent category. Must not be <code>null</code>.
+ * @param category The destination category. Must not be <code>null</code>.
+ *
+ * @return <code>True</code> if the operation is valid, <code>false</code> otherwise.
+ */
+ public boolean isValid(OPERATION operation, ICategory parentCategory, ICategory category);
+
+ /**
+ * Returns if or if not the given operation is enabled for the given
+ * destination category.
+ *
+ * @param operation The operation. Must not be <code>null</code>.
+ * @param category The destination category. Must not be <code>null</code>.
+ *
+ * @return <code>True</code> if the operation is valid, <code>false</code> otherwise.
+ */
+ public boolean isEnabled(OPERATION operation, ICategory category);
}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/internal/categories/AbstractCategoryContributionItem.java b/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/internal/categories/AbstractCategoryContributionItem.java
new file mode 100644
index 000000000..c9fc5c76b
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/internal/categories/AbstractCategoryContributionItem.java
@@ -0,0 +1,301 @@
+/*******************************************************************************
+ * 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.ui.views.internal.categories;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.core.expressions.IEvaluationContext;
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.ActionContributionItem;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.action.IContributionItem;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.ITreeSelection;
+import org.eclipse.jface.viewers.TreePath;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.tcf.te.ui.views.ViewsUtil;
+import org.eclipse.tcf.te.ui.views.extensions.CategoriesExtensionPointManager;
+import org.eclipse.tcf.te.ui.views.interfaces.ICategory;
+import org.eclipse.tcf.te.ui.views.interfaces.IUIConstants;
+import org.eclipse.tcf.te.ui.views.interfaces.categories.ICategorizable;
+import org.eclipse.ui.ISources;
+import org.eclipse.ui.actions.CompoundContributionItem;
+import org.eclipse.ui.handlers.IHandlerService;
+import org.eclipse.ui.menus.IWorkbenchContribution;
+import org.eclipse.ui.services.IServiceLocator;
+
+/**
+ * Abstract categories dynamic menu contribution implementation.
+ */
+public abstract class AbstractCategoryContributionItem extends CompoundContributionItem implements IWorkbenchContribution {
+ // Service locator to located the handler service.
+ protected IServiceLocator serviceLocator;
+
+ /**
+ * Abstract category action implementation.
+ */
+ protected abstract static class AbstractCategoryAction extends Action {
+ // The parent contribution item
+ private final AbstractCategoryContributionItem item;
+ // The selection
+ private final ISelection selection;
+ // The category
+ private final ICategory category;
+
+ /**
+ * Constructor.
+ *
+ * @param item The parent contribution item. Must not be <code>null</code>:
+ * @param selection The selection. Must not be <code>null</code>.
+ * @param category The category. Must not be <code>null</code>.
+ * @param single <code>True</code> if the action is the only item added, <code>false</code> otherwise.
+ */
+ public AbstractCategoryAction(AbstractCategoryContributionItem item, ISelection selection, ICategory category, boolean single) {
+ super();
+
+ Assert.isNotNull(item);
+ this.item = item;
+ Assert.isNotNull(selection);
+ this.selection = selection;
+ Assert.isNotNull(category);
+ this.category = category;
+
+ initialize(single);
+ }
+
+ /**
+ * Initialize the action state.
+ *
+ * @param single <code>True</code> if the action is the only item added, <code>false</code> otherwise.
+ */
+ protected void initialize(boolean single) {
+ setText(single ? makeSingleText(category.getLabel()) : category.getLabel());
+
+ Image image = category.getImage();
+ if (image != null) setImageDescriptor(ImageDescriptor.createFromImage(image));
+ }
+
+ /**
+ * Returns the action label in "single" mode.
+ *
+ * @param text The original label. Must not be <code>null</code>.
+ * @return The "single" mode label.
+ */
+ protected String makeSingleText(String text) {
+ Assert.isNotNull(text);
+ return text;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.action.Action#run()
+ */
+ @Override
+ public void run() {
+ if (selection instanceof IStructuredSelection && !selection.isEmpty()) {
+ boolean refresh = false;
+ Iterator<?> iterator = ((IStructuredSelection)selection).iterator();
+ while (iterator.hasNext()) {
+ Object element = iterator.next();
+ refresh |= execute(element, category);
+ }
+
+ // Refresh the view
+ if (refresh) ViewsUtil.refresh(IUIConstants.ID_EXPLORER);
+ }
+ }
+
+ /**
+ * Returns the categorizable for the given element.
+ *
+ * @param element The element or <code>null</code>.
+ * @return The categorizable or <code>null</code>.
+ */
+ protected ICategorizable getCategorizable(Object element) {
+ return item.getCategorizable(element);
+ }
+
+ /**
+ * Executes the operation to do on the given element.
+ *
+ * @param selection The selection. Must not be <code>null</code>.
+ * @param category The category. Must not be <code>null</code>.
+ *
+ * @return <code>True</code> if the view needs refreshment, <code>false</code> otherwise.
+ */
+ protected abstract boolean execute(Object element, ICategory category);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.menus.IWorkbenchContribution#initialize(org.eclipse.ui.services.IServiceLocator)
+ */
+ @Override
+ public void initialize(IServiceLocator serviceLocator) {
+ this.serviceLocator = serviceLocator;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.actions.CompoundContributionItem#getContributionItems()
+ */
+ @Override
+ protected IContributionItem[] getContributionItems() {
+ // Get the selected node.
+ IHandlerService service = (IHandlerService)serviceLocator.getService(IHandlerService.class);
+ IEvaluationContext state = service.getCurrentState();
+ ISelection selection = (ISelection)state.getVariable(ISources.ACTIVE_CURRENT_SELECTION_NAME);
+ IStructuredSelection iss = (IStructuredSelection)selection;
+
+ List<IContributionItem> items = new ArrayList<IContributionItem>();
+ ICategory[] categories = getCategories(iss, false);
+
+ // Generate the action contribution items
+ for (ICategory category : categories) {
+ IAction action = createAction(this, iss, category, categories.length == 1);
+ if (action != null) {
+ action.setEnabled(isEnabled(iss, category));
+ items.add(new ActionContributionItem(action));
+ }
+ }
+
+ return items.toArray(new IContributionItem[items.size()]);
+ }
+
+ /**
+ * Returns the list of valid categories for the given selection.
+ *
+ * @param selection The selection. Must not be <code>null</code>.
+ * @param onlyEnabled If <code>true</code>, returns categories which are valid and enabled only.
+ *
+ * @return The list of valid categories for the given selection, or an empty list.
+ */
+ protected ICategory[] getCategories(IStructuredSelection selection, boolean onlyEnabled) {
+ Assert.isNotNull(selection);
+
+ List<ICategory> categories = new ArrayList<ICategory>();
+ ICategory[] allCategories = CategoriesExtensionPointManager.getInstance().getCategories(false);
+
+ // Analyze the selection and add categories valid for all items in the selection
+ boolean firstRun = true;
+ Iterator<?> iterator = selection.iterator();
+ while (iterator.hasNext()) {
+ Object element = iterator.next();
+ ICategory parentCategory = getParentCategory(element, selection);
+
+ List<ICategory> candidates = new ArrayList<ICategory>();
+ for (ICategory category : allCategories) {
+ if (isValid(parentCategory, element, category)
+ && (!onlyEnabled || isEnabled(selection, category))) {
+ candidates.add(category);
+ }
+ }
+
+ // On first run, we remember the candidates as is
+ if (firstRun) {
+ categories.addAll(candidates);
+ firstRun = false;
+ } else {
+ // Eliminate all categories not being listed as candidate too
+ Iterator<ICategory> catIterator = categories.iterator();
+ while (catIterator.hasNext()) {
+ ICategory category = catIterator.next();
+ if (!candidates.contains(category)) {
+ catIterator.remove();
+ }
+ }
+ }
+ }
+
+ return categories.toArray(new ICategory[categories.size()]);
+ }
+
+ /**
+ * Creates the category action instance.
+ *
+ * @param item The parent contribution item. Must not be <code>null</code>:
+ * @param selection The selection. Must not be <code>null</code>.
+ * @param category The category. Must not be <code>null</code>.
+ * @param single <code>True</code> if the action is the only item added, <code>false</code> otherwise.
+ *
+ * @return The category action instance.
+ */
+ protected abstract IAction createAction(AbstractCategoryContributionItem item, ISelection selection, ICategory category, boolean single);
+
+ /**
+ * Tests if the given combination is valid. If not valid, the combination
+ * will not be added to the menu.
+ *
+ * @param parentCategory The parent category. Must not be <code>null</code>.
+ * @param element The element. Must not be <code>null</code>.
+ * @param category The category. Must not be <code>null</code>.
+ *
+ * @return <code>True</code> if the given combination is valid, <code>false</code> otherwise.
+ */
+ protected abstract boolean isValid(ICategory parentCategory, Object element, ICategory category);
+
+ /**
+ * Tests if the given combination is enabled.
+ *
+ * @param element The selection. Must not be <code>null</code>.
+ * @param category The category. Must not be <code>null</code>.
+ *
+ * @return <code>True</code> if the given combination is enabled, <code>false</code> otherwise.
+ */
+ protected abstract boolean isEnabled(ISelection selection, ICategory category);
+
+ /**
+ * Determines the parent category for the given element, based on the
+ * given selection.
+ *
+ * @param element The element. Must not be <code>null</code>.
+ * @param selection The selection. Must not be <code>null</code>.
+ *
+ * @return The parent category or <code>null</code>.
+ */
+ protected ICategory getParentCategory(Object element, IStructuredSelection selection) {
+ Assert.isNotNull(element);
+ Assert.isNotNull(selection);
+
+ ICategory parent = null;
+
+ if (selection instanceof ITreeSelection) {
+ TreePath[] pathes = ((ITreeSelection)selection).getPathsFor(element);
+ for (TreePath path : pathes) {
+ TreePath parentPath = path.getParentPath();
+ while (parentPath != null) {
+ if (parentPath.getLastSegment() instanceof ICategory) {
+ parent = (ICategory)parentPath.getLastSegment();
+ break;
+ }
+ parentPath = parentPath.getParentPath();
+ }
+ }
+ }
+
+ return parent;
+ }
+
+ /**
+ * Returns the categorizable for the given element.
+ *
+ * @param element The element or <code>null</code>.
+ * @return The categorizable or <code>null</code>.
+ */
+ protected ICategorizable getCategorizable(Object element) {
+ ICategorizable categorizable = element instanceof IAdaptable ? (ICategorizable)((IAdaptable)element).getAdapter(ICategorizable.class) : null;
+ if (categorizable == null) categorizable = (ICategorizable)Platform.getAdapterManager().getAdapter(element, ICategorizable.class);
+ return categorizable;
+ }
+}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/internal/categories/CategoryAddToContributionItem.java b/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/internal/categories/CategoryAddToContributionItem.java
new file mode 100644
index 000000000..9649966cc
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/internal/categories/CategoryAddToContributionItem.java
@@ -0,0 +1,128 @@
+/*******************************************************************************
+ * 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.ui.views.internal.categories;
+
+import java.util.Iterator;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.tcf.te.ui.views.Managers;
+import org.eclipse.tcf.te.ui.views.interfaces.ICategory;
+import org.eclipse.tcf.te.ui.views.interfaces.categories.ICategorizable;
+import org.eclipse.tcf.te.ui.views.nls.Messages;
+
+
+/**
+ * Dynamic menu contribution: Add To &lt;Category&gt;
+ */
+public class CategoryAddToContributionItem extends AbstractCategoryContributionItem {
+
+ /**
+ * Category action implementation.
+ */
+ protected static class AddToCategoryAction extends AbstractCategoryAction {
+
+ /**
+ * Constructor.
+ *
+ * @param item The parent contribution item. Must not be <code>null</code>:
+ * @param selection The selection. Must not be <code>null</code>.
+ * @param category The category. Must not be <code>null</code>.
+ * @param single <code>True</code> if the action is the only item added, <code>false</code> otherwise.
+ */
+ public AddToCategoryAction(AbstractCategoryContributionItem item, ISelection selection, ICategory category, boolean single) {
+ super(item, selection, category, single);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.ui.views.internal.categories.AbstractCategoryContributionItem.AbstractCategoryAction#makeSingleText(java.lang.String)
+ */
+ @Override
+ protected String makeSingleText(String text) {
+ Assert.isNotNull(text);
+ return NLS.bind(Messages.AddToCategoryAction_single_text, text);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.ui.views.internal.categories.AbstractCategoryContributionItem.AbstractCategoryAction#execute(java.lang.Object, org.eclipse.tcf.te.ui.views.interfaces.ICategory)
+ */
+ @Override
+ protected boolean execute(Object element, ICategory category) {
+ Assert.isNotNull(element);
+ Assert.isNotNull(category);
+
+ boolean refresh = false;
+
+ ICategorizable categorizable = getCategorizable(element);
+ Assert.isNotNull(categorizable);
+
+ if (!Managers.getCategoryManager().belongsTo(category.getId(), categorizable.getId())) {
+ Managers.getCategoryManager().add(category.getId(), categorizable.getId());
+ refresh = true;
+ }
+
+ return refresh;
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.ui.views.internal.categories.AbstractCategoryContributionItem#createAction(org.eclipse.tcf.te.ui.views.internal.categories.AbstractCategoryContributionItem, org.eclipse.jface.viewers.ISelection, org.eclipse.tcf.te.ui.views.interfaces.ICategory, boolean)
+ */
+ @Override
+ protected IAction createAction(AbstractCategoryContributionItem item, ISelection selection, ICategory category, boolean single) {
+ return new AddToCategoryAction(item, selection, category, single);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.ui.views.internal.categories.AbstractCategoryContributionItem#isValid(org.eclipse.tcf.te.ui.views.interfaces.ICategory, java.lang.Object, org.eclipse.tcf.te.ui.views.interfaces.ICategory)
+ */
+ @Override
+ protected boolean isValid(ICategory parentCategory, Object element, ICategory category) {
+ Assert.isNotNull(parentCategory);
+ Assert.isNotNull(element);
+ Assert.isNotNull(category);
+
+ // Delegate to the categorizable element
+ ICategorizable categorizable = getCategorizable(element);
+ Assert.isNotNull(categorizable);
+
+ return categorizable.isValid(ICategorizable.OPERATION.ADD, parentCategory, category);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.ui.views.internal.categories.AbstractCategoryContributionItem#isEnabled(org.eclipse.jface.viewers.ISelection, org.eclipse.tcf.te.ui.views.interfaces.ICategory)
+ */
+ @Override
+ protected boolean isEnabled(ISelection selection, ICategory category) {
+ Assert.isNotNull(selection);
+ Assert.isNotNull(category);
+
+ boolean enabled = false;
+
+ if (selection instanceof IStructuredSelection && !selection.isEmpty()) {
+ enabled = true;
+ Iterator<?> iterator = ((IStructuredSelection)selection).iterator();
+ while (iterator.hasNext()) {
+ Object element = iterator.next();
+
+ // Delegate to the categorizable element
+ ICategorizable categorizable = getCategorizable(element);
+ Assert.isNotNull(categorizable);
+ enabled &= categorizable.isEnabled(ICategorizable.OPERATION.ADD, category);
+ if (!enabled) break;
+ }
+ }
+
+ return enabled;
+ }
+}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/internal/categories/CategoryPropertyTester.java b/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/internal/categories/CategoryPropertyTester.java
index 92ee6ccb5..e5f82440c 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/internal/categories/CategoryPropertyTester.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/internal/categories/CategoryPropertyTester.java
@@ -9,8 +9,14 @@
*******************************************************************************/
package org.eclipse.tcf.te.ui.views.internal.categories;
+import org.eclipse.core.expressions.EvaluationContext;
+import org.eclipse.core.expressions.EvaluationResult;
+import org.eclipse.core.expressions.ICountable;
+import org.eclipse.core.expressions.IEvaluationContext;
import org.eclipse.core.expressions.PropertyTester;
+import org.eclipse.core.internal.expressions.CountExpression;
import org.eclipse.core.runtime.Assert;
+import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.Platform;
import org.eclipse.jface.viewers.IStructuredSelection;
@@ -23,6 +29,7 @@ import org.eclipse.tcf.te.ui.views.interfaces.categories.ICategorizable;
/**
* Category property tester.
*/
+@SuppressWarnings("restriction")
public class CategoryPropertyTester extends PropertyTester {
/* (non-Javadoc)
@@ -49,7 +56,7 @@ public class CategoryPropertyTester extends PropertyTester {
* @return <code>True</code> if the property to test has the expected value, <code>false</code>
* otherwise.
*/
- protected boolean testSelection(IStructuredSelection selection, String property, Object[] args, Object expectedValue) {
+ protected boolean testSelection(IStructuredSelection selection, String property, Object[] args, Object expectedValue) {
Assert.isNotNull(selection);
if ("parentCategoryId".equals(property) && !selection.isEmpty()) { //$NON-NLS-1$
@@ -73,6 +80,34 @@ public class CategoryPropertyTester extends PropertyTester {
}
}
+ if ("validAddToCategoriesCount".equals(property)) { //$NON-NLS-1$
+ // Determine the number of valid "Add To" Categories
+ AbstractCategoryContributionItem item = new CategoryAddToContributionItem();
+ ICategory[] categories = item.getCategories(selection, true);
+ final int count = categories.length;
+
+ // Re-use the count expression to allow the same value syntax
+ String value = expectedValue instanceof String ? (String)expectedValue : expectedValue != null ? expectedValue.toString() : null;
+ if (value != null) {
+ CountExpression expression = new CountExpression(value);
+ IEvaluationContext context = new EvaluationContext(null, new ICountable() {
+ @Override
+ public int count() {
+ return count;
+ }
+ });
+
+ EvaluationResult result = EvaluationResult.FALSE;
+ try {
+ result = expression.evaluate(context);
+ } catch (CoreException e) {
+ if (Platform.inDebugMode()) e.printStackTrace();
+ }
+
+ return result.equals(EvaluationResult.TRUE);
+ }
+ }
+
return false;
}
@@ -80,11 +115,11 @@ public class CategoryPropertyTester extends PropertyTester {
* Internal helper to {@link #test(Object, String, Object[], Object)}.
*/
protected boolean internalTest(Object receiver, String property, Object[] args, Object expectedValue) {
- ICategorizable adapter = receiver instanceof IAdaptable ? (ICategorizable)((IAdaptable)receiver).getAdapter(ICategorizable.class) : null;
- if (adapter == null) adapter = (ICategorizable)Platform.getAdapterManager().getAdapter(receiver, ICategorizable.class);
+ ICategorizable categorizable = receiver instanceof IAdaptable ? (ICategorizable)((IAdaptable)receiver).getAdapter(ICategorizable.class) : null;
+ if (categorizable == null) categorizable = (ICategorizable)Platform.getAdapterManager().getAdapter(receiver, ICategorizable.class);
- if ("belongsTo".equals(property) && adapter != null) { //$NON-NLS-1$
- String id = adapter.getId(receiver);
+ if ("belongsTo".equals(property) && categorizable != null) { //$NON-NLS-1$
+ String id = categorizable.getId();
if (id != null && expectedValue instanceof String) {
return Managers.getCategoryManager().belongsTo((String)expectedValue, id);
}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/nls/Messages.java b/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/nls/Messages.java
index 6e2803673..7ac2de35a 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/nls/Messages.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/nls/Messages.java
@@ -35,15 +35,21 @@ public class Messages extends NLS {
public static String PropertiesCommandHandler_error_initPartFailed;
+ public static String AddToCategoryAction_single_text;
+ public static String RemoveFromCategoryAction_single_text;
+
public static String AbstractCustomFormToolkitEditorPage_HelpAction_label;
public static String AbstractCustomFormToolkitEditorPage_HelpAction_tooltip;
+
public static String CommonFilterDescriptorLabelProvider_ContentExtensionDescription;
+
public static String ConfigContentHandler_DialogTitle;
public static String ConfigContentHandler_InitialFilter;
public static String ConfigContentHandler_PromptMessage;
public static String ConfigFiltersHandler_DialogTitle;
public static String ConfigFiltersHandler_InitialFilter;
public static String ConfigFiltersHandler_PromptMessage;
+
public static String UpdateActiveExtensionsOperation_OperationName;
public static String UpdateActiveFiltersOperation_OperationName;
}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/nls/Messages.properties b/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/nls/Messages.properties
index 6b21ed87e..535cadfa5 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/nls/Messages.properties
+++ b/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/nls/Messages.properties
@@ -13,16 +13,22 @@ NewActionProvider_NewWizardCommandAction_tooltip=Open the New wizard
PropertiesCommandHandler_error_initPartFailed=Failed to initialize the properties editor for the selected node.
+AddToCategoryAction_single_text=Add To {0}
+RemoveFromCategoryAction_single_text=Remove From {0}
+
# ***** Editor Pages *****
AbstractCustomFormToolkitEditorPage_HelpAction_label=Help
AbstractCustomFormToolkitEditorPage_HelpAction_tooltip=Help
+
CommonFilterDescriptorLabelProvider_ContentExtensionDescription=Provides content from the "{0}" extension.
+
ConfigContentHandler_DialogTitle=Available Extensions
ConfigContentHandler_InitialFilter=enter name of extension
ConfigContentHandler_PromptMessage=Select the extensions to show (checked extensions will be visible):
ConfigFiltersHandler_DialogTitle=Available Filters
ConfigFiltersHandler_InitialFilter=enter name of filter
ConfigFiltersHandler_PromptMessage=Select the filters to apply (matching items will be hidden):
+
UpdateActiveExtensionsOperation_OperationName=Update CommonViewer Extensions
UpdateActiveFiltersOperation_OperationName=Update CommonViewer Filters

Back to the top