Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUwe Stieber2012-10-01 07:33:53 +0000
committerUwe Stieber2012-10-01 07:33:53 +0000
commit2104cb69f132ec23c7eeace43b4941de6a829678 (patch)
tree6d5b86ae845de76beef728791706fba9481c52e5 /target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui
parent3525da18a2c6137e8ad4ca03cd59a30fd328685e (diff)
downloadorg.eclipse.tcf-2104cb69f132ec23c7eeace43b4941de6a829678.tar.gz
org.eclipse.tcf-2104cb69f132ec23c7eeace43b4941de6a829678.tar.xz
org.eclipse.tcf-2104cb69f132ec23c7eeace43b4941de6a829678.zip
Target Explorer: Rework launch node content provider
Diffstat (limited to 'target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui')
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/controls/NavigatorContentProvider.java339
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/controls/TreeContentProvider.java193
2 files changed, 362 insertions, 170 deletions
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/controls/NavigatorContentProvider.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/controls/NavigatorContentProvider.java
index 6a65b751c..d6bb7a3fa 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/controls/NavigatorContentProvider.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/controls/NavigatorContentProvider.java
@@ -1,170 +1,169 @@
-/*******************************************************************************
- * 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.tcf.filesystem.ui.controls;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.core.runtime.Assert;
-import org.eclipse.jface.viewers.ITreeViewerListener;
-import org.eclipse.jface.viewers.TreeExpansionEvent;
-import org.eclipse.jface.viewers.Viewer;
-import org.eclipse.tcf.te.tcf.filesystem.core.model.AbstractTreeNode;
-import org.eclipse.tcf.te.tcf.filesystem.core.model.ITreeNodeModel;
-import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerModel;
-import org.eclipse.tcf.te.ui.trees.TreeContentProvider;
-
-
-/**
- * The base navigator content provider for File System and Process Monitor
- */
-public abstract class NavigatorContentProvider extends TreeContentProvider implements ITreeViewerListener {
-
- /* (non-Javadoc)
- * @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object)
- */
- @Override
- public Object getParent(Object element) {
- if (element instanceof AbstractTreeNode) {
- AbstractTreeNode node = (AbstractTreeNode) element;
- AbstractTreeNode parent = node.getParent();
- if (parent != null) {
- if (parent.isSystemRoot()) {
- if (isRootNodeVisible()) return parent;
- return null;
- }
- return parent;
- }
- if (isRootNodeVisible()) return node.peerNode;
- }
- return null;
- }
-
- /*
- * (non-Javadoc)
- * @see org.eclipse.jface.viewers.ITreeViewerListener#treeCollapsed(org.eclipse.jface.viewers.TreeExpansionEvent)
- */
- @Override
- public void treeCollapsed(TreeExpansionEvent event) {
- }
-
- /*
- * (non-Javadoc)
- * @see org.eclipse.jface.viewers.ITreeViewerListener#treeExpanded(org.eclipse.jface.viewers.TreeExpansionEvent)
- */
- @Override
- public void treeExpanded(TreeExpansionEvent event) {
- Object object = event.getElement();
- if(object instanceof AbstractTreeNode) {
- AbstractTreeNode parent = (AbstractTreeNode) object;
- if (parent.childrenQueried && !parent.childrenQueryRunning) {
- parent.refreshChildren();
- }
- }
- }
-
- /*
- * (non-Javadoc)
- * @see org.eclipse.tcf.te.ui.trees.TreeContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
- */
- @Override
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
- super.inputChanged(viewer, oldInput, newInput);
- this.viewer.addTreeListener(this);
- }
-
- /*
- * (non-Javadoc)
- * @see org.eclipse.tcf.te.ui.trees.TreeContentProvider#dispose()
- */
- @Override
- public void dispose() {
- this.viewer.removeTreeListener(this);
- super.dispose();
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object)
- */
- @Override
- public Object[] getChildren(Object parentElement) {
- super.getChildren(parentElement);
-
- if (parentElement instanceof IPeerModel) {
- final IPeerModel peerNode = (IPeerModel)parentElement;
- ITreeNodeModel model = doGetModel(peerNode);
- if (isRootNodeVisible()) {
- AbstractTreeNode root = model.getRoot();
- if(!root.childrenQueried && !root.childrenQueryRunning) {
- root.queryChildren();
- }
- return new Object[] { root };
- }
- return getChildren(model.getRoot());
- } else if (parentElement instanceof AbstractTreeNode) {
- AbstractTreeNode node = (AbstractTreeNode)parentElement;
- List<Object> current = new ArrayList<Object>(node.getChildren());
- if (!node.childrenQueried) {
- current.add(getPending(node));
- if (!node.childrenQueryRunning) {
- node.queryChildren();
- }
- }
- return current.toArray();
- }
-
- return NO_ELEMENTS;
- }
-
- /**
- * Get the tree node model for this peer node.
- *
- * @param peerNode The peer node from where to get the model.
- * @return The tree node model.
- */
- protected abstract ITreeNodeModel doGetModel(IPeerModel peerNode);
-
- /* (non-Javadoc)
- * @see org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java.lang.Object)
- */
- @Override
- public boolean hasChildren(final Object element) {
- Assert.isNotNull(element);
-
- boolean hasChildren = false;
-
- if (element instanceof AbstractTreeNode) {
- AbstractTreeNode node = (AbstractTreeNode)element;
- if(node.isSystemRoot()) {
- hasChildren = true;
- }
- else {
- hasChildren = !node.childrenQueried || super.hasChildren(element);
- }
- }
- else if (element instanceof IPeerModel) {
- IPeerModel peerModel = (IPeerModel) element;
- ITreeNodeModel model = doGetModel(peerModel);
- AbstractTreeNode root = model.getRoot();
- hasChildren = root != null ? hasChildren(root) : true;
- }
-
- return hasChildren;
- }
-
- /**
- * If the root node of the tree is visible.
- *
- * @return true if it is visible.
- */
- protected boolean isRootNodeVisible() {
- return true;
- }
-}
+/*******************************************************************************
+ * 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.tcf.filesystem.ui.controls;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.jface.viewers.ITreeViewerListener;
+import org.eclipse.jface.viewers.TreeExpansionEvent;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.tcf.te.tcf.filesystem.core.model.AbstractTreeNode;
+import org.eclipse.tcf.te.tcf.filesystem.core.model.ITreeNodeModel;
+import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerModel;
+
+
+/**
+ * The base navigator content provider for File System and Process Monitor
+ */
+public abstract class NavigatorContentProvider extends TreeContentProvider implements ITreeViewerListener {
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object)
+ */
+ @Override
+ public Object getParent(Object element) {
+ if (element instanceof AbstractTreeNode) {
+ AbstractTreeNode node = (AbstractTreeNode) element;
+ AbstractTreeNode parent = node.getParent();
+ if (parent != null) {
+ if (parent.isSystemRoot()) {
+ if (isRootNodeVisible()) return parent;
+ return null;
+ }
+ return parent;
+ }
+ if (isRootNodeVisible()) return node.peerNode;
+ }
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.jface.viewers.ITreeViewerListener#treeCollapsed(org.eclipse.jface.viewers.TreeExpansionEvent)
+ */
+ @Override
+ public void treeCollapsed(TreeExpansionEvent event) {
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.jface.viewers.ITreeViewerListener#treeExpanded(org.eclipse.jface.viewers.TreeExpansionEvent)
+ */
+ @Override
+ public void treeExpanded(TreeExpansionEvent event) {
+ Object object = event.getElement();
+ if(object instanceof AbstractTreeNode) {
+ AbstractTreeNode parent = (AbstractTreeNode) object;
+ if (parent.childrenQueried && !parent.childrenQueryRunning) {
+ parent.refreshChildren();
+ }
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.tcf.te.ui.trees.TreeContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
+ */
+ @Override
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ super.inputChanged(viewer, oldInput, newInput);
+ this.viewer.addTreeListener(this);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.tcf.te.ui.trees.TreeContentProvider#dispose()
+ */
+ @Override
+ public void dispose() {
+ this.viewer.removeTreeListener(this);
+ super.dispose();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object)
+ */
+ @Override
+ public Object[] getChildren(Object parentElement) {
+ super.getChildren(parentElement);
+
+ if (parentElement instanceof IPeerModel) {
+ final IPeerModel peerNode = (IPeerModel)parentElement;
+ ITreeNodeModel model = doGetModel(peerNode);
+ if (isRootNodeVisible()) {
+ AbstractTreeNode root = model.getRoot();
+ if(!root.childrenQueried && !root.childrenQueryRunning) {
+ root.queryChildren();
+ }
+ return new Object[] { root };
+ }
+ return getChildren(model.getRoot());
+ } else if (parentElement instanceof AbstractTreeNode) {
+ AbstractTreeNode node = (AbstractTreeNode)parentElement;
+ List<Object> current = new ArrayList<Object>(node.getChildren());
+ if (!node.childrenQueried) {
+ current.add(getPending(node));
+ if (!node.childrenQueryRunning) {
+ node.queryChildren();
+ }
+ }
+ return current.toArray();
+ }
+
+ return NO_ELEMENTS;
+ }
+
+ /**
+ * Get the tree node model for this peer node.
+ *
+ * @param peerNode The peer node from where to get the model.
+ * @return The tree node model.
+ */
+ protected abstract ITreeNodeModel doGetModel(IPeerModel peerNode);
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java.lang.Object)
+ */
+ @Override
+ public boolean hasChildren(final Object element) {
+ Assert.isNotNull(element);
+
+ boolean hasChildren = false;
+
+ if (element instanceof AbstractTreeNode) {
+ AbstractTreeNode node = (AbstractTreeNode)element;
+ if(node.isSystemRoot()) {
+ hasChildren = true;
+ }
+ else {
+ hasChildren = !node.childrenQueried || super.hasChildren(element);
+ }
+ }
+ else if (element instanceof IPeerModel) {
+ IPeerModel peerModel = (IPeerModel) element;
+ ITreeNodeModel model = doGetModel(peerModel);
+ AbstractTreeNode root = model.getRoot();
+ hasChildren = root != null ? hasChildren(root) : true;
+ }
+
+ return hasChildren;
+ }
+
+ /**
+ * If the root node of the tree is visible.
+ *
+ * @return true if it is visible.
+ */
+ protected boolean isRootNodeVisible() {
+ return true;
+ }
+}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/controls/TreeContentProvider.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/controls/TreeContentProvider.java
new file mode 100644
index 000000000..b06e1ded1
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/controls/TreeContentProvider.java
@@ -0,0 +1,193 @@
+/*******************************************************************************
+ * 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.tcf.filesystem.ui.controls;
+
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.ViewerFilter;
+import org.eclipse.tcf.te.core.interfaces.IPropertyChangeProvider;
+import org.eclipse.tcf.te.ui.trees.CommonViewerListener;
+import org.eclipse.tcf.te.ui.trees.Pending;
+
+/**
+ * The base tree content provider that defines several default methods.
+ */
+public abstract class TreeContentProvider implements ITreeContentProvider, PropertyChangeListener {
+
+ /**
+ * Static reference to the return value representing no elements.
+ */
+ protected final static Object[] NO_ELEMENTS = new Object[0];
+
+ // The listener to refresh the common viewer when properties change.
+ protected CommonViewerListener commonViewerListener;
+ // The viewer inputs that have been added a property change listener.
+ private Set<IPropertyChangeProvider> providers = Collections.synchronizedSet(new HashSet<IPropertyChangeProvider>());
+ // The viewer
+ protected TreeViewer viewer;
+ // The pending nodes and their direct parents.
+ private Map<Object, Pending> pendings;
+
+ /**
+ * Create a tree content provider.
+ */
+ public TreeContentProvider() {
+ pendings = new HashMap<Object, Pending>();
+ }
+
+ /**
+ * Get the pending node for the specified parent.
+ * If it exists, then return it. If not, create one
+ * and save it and return it.
+ */
+ protected Pending getPending(Object parent) {
+ Pending pending = pendings.get(parent);
+ if(pending == null && viewer != null) {
+ pending = new Pending(viewer);
+ pendings.put(parent, pending);
+ }
+ return pending;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent)
+ */
+ @Override
+ public void propertyChange(PropertyChangeEvent evt) {
+ String property = evt.getPropertyName();
+ if(property.equals("query_started")) { //$NON-NLS-1$
+ Object source = evt.getSource();
+ Pending pending = pendings.get(source);
+ if(pending != null) {
+ pending.startAnimation();
+ }
+ }
+ else if(property.equals("query_done")) { //$NON-NLS-1$
+ Object source = evt.getSource();
+ Pending pending = pendings.remove(source);
+ if(pending != null) {
+ pending.stopAnimation();
+ }
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.jface.viewers.IContentProvider#dispose()
+ */
+ @Override
+ public void dispose() {
+ for(IPropertyChangeProvider provider : providers) {
+ provider.removePropertyChangeListener(commonViewerListener);
+ provider.removePropertyChangeListener(this);
+ }
+ commonViewerListener.cancel();
+ providers.clear();
+ for(Pending pending : pendings.values()) {
+ pending.stopAnimation();
+ }
+ pendings.clear();
+ }
+
+ /**
+ * Get the filtered children of the parent using the
+ * filters registered in the viewer.
+ *
+ * @param parent The parent element.
+ * @return The children after filtering.
+ */
+ private Object[] getFilteredChildren(Object parent) {
+ Object[] result = getChildren(parent);
+ if (viewer != null) {
+ ViewerFilter[] filters = viewer.getFilters();
+ if (filters != null) {
+ for (ViewerFilter filter : filters) {
+ Object[] filteredResult = filter.filter(viewer, parent, result);
+ result = filteredResult;
+ }
+ }
+ }
+ return result;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object)
+ */
+ @Override
+ public Object[] getChildren(Object parentElement) {
+ Assert.isNotNull(parentElement);
+
+ if (parentElement instanceof IAdaptable) {
+ IAdaptable adaptable = (IAdaptable) parentElement;
+ IPropertyChangeProvider provider = (IPropertyChangeProvider) adaptable.getAdapter(IPropertyChangeProvider.class);
+ if (provider != null) {
+ installPropertyChangeListener(provider);
+ }
+ }
+
+ return NO_ELEMENTS;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
+ */
+ @Override
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ Assert.isTrue(viewer instanceof TreeViewer);
+ this.viewer = (TreeViewer) viewer;
+ this.commonViewerListener = new CommonViewerListener(this.viewer, this);
+ }
+
+ /**
+ * Install a property change listener to the specified element.
+ *
+ * @param provider The element node.
+ */
+ private void installPropertyChangeListener(IPropertyChangeProvider provider) {
+ if (provider != null && !providers.contains(provider) && commonViewerListener != null) {
+ provider.addPropertyChangeListener(commonViewerListener);
+ provider.addPropertyChangeListener(this);
+ providers.add(provider);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java.lang.Object)
+ */
+ @Override
+ public boolean hasChildren(Object element) {
+ Object[] children = getFilteredChildren(element);
+ return children != null && children.length > 0;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.jface.viewers.ITreeContentProvider#getElements(java.lang.Object)
+ */
+ @Override
+ public Object[] getElements(Object inputElement) {
+ return getChildren(inputElement);
+ }
+}

Back to the top