Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWilliam Chen2012-05-03 09:42:35 +0000
committerWilliam Chen2012-05-03 09:42:35 +0000
commit3c010ba2d91f0576a7459a761c15687f9a23b1ab (patch)
tree3141bf64300a716c21a0bbddbf34d1b461d016fc
parent8a95f2529a739c273c58fe83f155775dbdd6b861 (diff)
downloadorg.eclipse.tcf-3c010ba2d91f0576a7459a761c15687f9a23b1ab.tar.gz
org.eclipse.tcf-3c010ba2d91f0576a7459a761c15687f9a23b1ab.tar.xz
org.eclipse.tcf-3c010ba2d91f0576a7459a761c15687f9a23b1ab.zip
Target Explorer: Remove the redundant classes.
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.core/src/org/eclipse/tcf/te/core/utils/Ancestor.java114
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/adapters/RefreshHandlerDelegate.java77
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.processes.ui/src/org/eclipse/tcf/te/tcf/processes/ui/internal/adapters/RefreshHandlerDelegate.java56
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tests/src/org/eclipse/tcf/te/tests/tcf/filesystem/adapters/RefreshHandlerDelegateTest.java35
4 files changed, 114 insertions, 168 deletions
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.core/src/org/eclipse/tcf/te/core/utils/Ancestor.java b/target_explorer/plugins/org.eclipse.tcf.te.core/src/org/eclipse/tcf/te/core/utils/Ancestor.java
new file mode 100644
index 000000000..698b81bf4
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.core/src/org/eclipse/tcf/te/core/utils/Ancestor.java
@@ -0,0 +1,114 @@
+package org.eclipse.tcf.te.core.utils;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.runtime.Assert;
+
+public abstract class Ancestor<T> {
+
+ /**
+ * Get an element which is the common ancestor of all the specified elements.
+ *
+ * @param elements The element list.
+ * @return The ancestor element.
+ */
+ protected T getAncestor(List<T> elements) {
+ if (elements.isEmpty()) return null;
+ if (elements.size() == 1) return elements.get(0);
+ T element1 = elements.get(0);
+ for (int i = 1; i < elements.size(); i++) {
+ T element2 = elements.get(i);
+ element1 = getCommonAncestor(element1, element2);
+ if (element1 == null) return null;
+ }
+ return element1;
+ }
+
+ /**
+ * Get the top most elements of the specified list.
+ *
+ * @param elements The original list.
+ * @return The top most elements.
+ */
+ protected List<T> getAncestors(List<T> elements) {
+ List<T> result = new ArrayList<T>();
+ for (T element : elements) {
+ if (!hasAncestor(element, elements)) {
+ result.add(element);
+ }
+ }
+ return result;
+ }
+
+ /**
+ * Get the common ancestor of the specified two elements.
+ *
+ * @param element1 The first element.
+ * @param element2 The second element.
+ * @return The common ancestor.
+ */
+ private T getCommonAncestor(T element1, T element2) {
+ Assert.isNotNull(element1);
+ Assert.isNotNull(element2);
+ if (isAncestorOf(element1, element2)) {
+ return element1;
+ }
+ if (isAncestorOf(element2, element1)) {
+ return element2;
+ }
+ T ancestor = null;
+ T parent1 = getParent(element1);
+ if(parent1 != null) {
+ ancestor = getCommonAncestor(parent1, element2);
+ }
+ if(ancestor != null) return ancestor;
+ T parent2 = getParent(element2);
+ if(parent2 != null) {
+ ancestor = getCommonAncestor(element1, parent2);
+ }
+ if(ancestor != null) return ancestor;
+ if(parent1 != null && parent2 != null) {
+ ancestor = getCommonAncestor(parent1, parent2);
+ }
+ return ancestor;
+ }
+
+ /**
+ * If the target element has ancestor in the specified list.
+ *
+ * @param element The element to be tested.
+ * @param elements The element list to search in.
+ * @return true if the element has an ancestor in the list.
+ */
+ private boolean hasAncestor(T element, List<T> elements) {
+ for (T node : elements) {
+ if (isAncestorOf(node, element)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Judges if the first element is an ancestor of the second element.
+ *
+ * @param element1 The first element to be tested.
+ * @param element2 The second element to be tested.
+ * @return true if the first element is the ancestor of the second element.
+ */
+ private boolean isAncestorOf(T element1, T element2) {
+ if (element2 == null) return false;
+ T parent = getParent(element2);
+ if (parent == element1) return true;
+ return isAncestorOf(element1, parent);
+ }
+
+ /**
+ * Get the parent of the specified element in the display thread.
+ *
+ * @param element The element
+ * @return its parent.
+ */
+ protected abstract T getParent(T element);
+}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/adapters/RefreshHandlerDelegate.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/adapters/RefreshHandlerDelegate.java
deleted file mode 100644
index 38e882cd0..000000000
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/adapters/RefreshHandlerDelegate.java
+++ /dev/null
@@ -1,77 +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.filesystem.ui.internal.adapters;
-
-import org.eclipse.core.runtime.Assert;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.tcf.te.runtime.callback.Callback;
-import org.eclipse.tcf.te.runtime.interfaces.callback.ICallback;
-import org.eclipse.tcf.te.runtime.interfaces.properties.IPropertiesContainer;
-import org.eclipse.tcf.te.tcf.filesystem.core.internal.operations.IOpExecutor;
-import org.eclipse.tcf.te.tcf.filesystem.core.internal.operations.JobExecutor;
-import org.eclipse.tcf.te.tcf.filesystem.core.internal.operations.OpRefresh;
-import org.eclipse.tcf.te.tcf.filesystem.core.model.FSTreeNode;
-import org.eclipse.tcf.te.tcf.filesystem.ui.activator.UIPlugin;
-import org.eclipse.tcf.te.ui.views.interfaces.handler.IRefreshHandlerDelegate;
-import org.eclipse.ui.PlatformUI;
-
-/**
- * File System tree node refresh handler delegate implementation.
- */
-public class RefreshHandlerDelegate implements IRefreshHandlerDelegate {
-
- /* (non-Javadoc)
- * @see org.eclipse.tcf.te.ui.views.interfaces.handler.IRefreshHandlerDelegate#canRefresh(java.lang.Object)
- */
- @Override
- public boolean canRefresh(Object element) {
- if (element instanceof FSTreeNode) {
- FSTreeNode node = (FSTreeNode) element;
- return node.isSystemRoot() || node.isRoot() || node.isDirectory()
- || node.isFile() && !UIPlugin.isAutoSaving();
- }
- return false;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.tcf.te.ui.views.interfaces.handler.IRefreshHandlerDelegate#refresh(java.lang.Object, org.eclipse.tcf.te.runtime.interfaces.properties.IPropertiesContainer, org.eclipse.tcf.te.runtime.interfaces.callback.ICallback)
- */
- @Override
- public void refresh(Object element, IPropertiesContainer state, final ICallback callback) {
- Assert.isNotNull(element);
- Assert.isNotNull(state);
-
- if (canRefresh(element)) {
- final FSTreeNode node = (FSTreeNode) element;
- if (node.isSystemRoot() || node.isRoot() || node.isDirectory()) {
- IOpExecutor executor = new JobExecutor(new Callback(){
- @Override
- protected void internalDone(final Object caller, final IStatus status) {
- PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable(){
- @Override
- public void run() {
- if (callback != null) callback.done(caller, status);
- }});
- }
- });
- executor.execute(new OpRefresh(node));
- }
- else if (node.isFile() && !UIPlugin.isAutoSaving()) {
- node.refreshState(callback);
- }
- }
- else {
- if (callback != null) {
- callback.done(this, Status.OK_STATUS);
- }
- }
- }
-}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.processes.ui/src/org/eclipse/tcf/te/tcf/processes/ui/internal/adapters/RefreshHandlerDelegate.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.processes.ui/src/org/eclipse/tcf/te/tcf/processes/ui/internal/adapters/RefreshHandlerDelegate.java
deleted file mode 100644
index 7a8bad69d..000000000
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.processes.ui/src/org/eclipse/tcf/te/tcf/processes/ui/internal/adapters/RefreshHandlerDelegate.java
+++ /dev/null
@@ -1,56 +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.processes.ui.internal.adapters;
-
-import org.eclipse.core.runtime.Assert;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.tcf.te.runtime.interfaces.callback.ICallback;
-import org.eclipse.tcf.te.runtime.interfaces.properties.IPropertiesContainer;
-import org.eclipse.tcf.te.tcf.processes.core.model.ProcessModel;
-import org.eclipse.tcf.te.tcf.processes.core.model.ProcessTreeNode;
-import org.eclipse.tcf.te.ui.views.interfaces.handler.IRefreshHandlerDelegate;
-
-/**
- * Process tree node refresh handler delegate implementation.
- */
-public class RefreshHandlerDelegate implements IRefreshHandlerDelegate {
-
- /* (non-Javadoc)
- * @see org.eclipse.tcf.te.ui.views.interfaces.handler.IRefreshHandlerDelegate#canRefresh(java.lang.Object)
- */
- @Override
- public boolean canRefresh(Object element) {
- if (element instanceof ProcessTreeNode) {
- return true;
- }
- return false;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.tcf.te.ui.views.interfaces.handler.IRefreshHandlerDelegate#refresh(java.lang.Object, org.eclipse.tcf.te.runtime.interfaces.properties.IPropertiesContainer, org.eclipse.tcf.te.runtime.interfaces.callback.ICallback)
- */
- @Override
- public void refresh(Object element, IPropertiesContainer state, ICallback callback) {
- Assert.isNotNull(element);
- Assert.isNotNull(state);
-
- if (canRefresh(element)) {
- ProcessTreeNode process = (ProcessTreeNode) element;
- ProcessModel model = ProcessModel.getProcessModel(process.peerNode);
- model.refresh(process);
-
- if (callback != null) callback.done(this, Status.OK_STATUS);
- }
- else {
- if (callback != null) callback.done(this, Status.OK_STATUS);
- }
- }
-
-}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tests/src/org/eclipse/tcf/te/tests/tcf/filesystem/adapters/RefreshHandlerDelegateTest.java b/target_explorer/plugins/org.eclipse.tcf.te.tests/src/org/eclipse/tcf/te/tests/tcf/filesystem/adapters/RefreshHandlerDelegateTest.java
deleted file mode 100644
index 08e7e80be..000000000
--- a/target_explorer/plugins/org.eclipse.tcf.te.tests/src/org/eclipse/tcf/te/tests/tcf/filesystem/adapters/RefreshHandlerDelegateTest.java
+++ /dev/null
@@ -1,35 +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.tests.tcf.filesystem.adapters;
-
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.tcf.te.runtime.properties.PropertiesContainer;
-import org.eclipse.tcf.te.tests.tcf.filesystem.FSPeerTestCase;
-import org.eclipse.tcf.te.ui.views.interfaces.handler.IRefreshHandlerDelegate;
-
-public class RefreshHandlerDelegateTest extends FSPeerTestCase {
- private IRefreshHandlerDelegate delegate;
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- delegate = (IRefreshHandlerDelegate) Platform.getAdapterManager().getAdapter(testFolder, IRefreshHandlerDelegate.class);
- assertNotNull(delegate);
- }
-
- public void testCanRefresh() {
- assertTrue(delegate.canRefresh(testFolder));
- }
-
- public void testRefresh() throws Exception {
- PropertiesContainer props = new PropertiesContainer();
- delegate.refresh(testFolder, props, null);
- }
-}

Back to the top