diff options
author | Uwe Stieber | 2014-02-20 09:00:49 +0000 |
---|---|---|
committer | Uwe Stieber | 2014-02-20 09:02:15 +0000 |
commit | 5929e4e1fe422b86ff9581868ad4d6b2dab5556c (patch) | |
tree | ec1f96ef655a25cd3ee3bfbcbf71e2792531ee81 /target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org | |
parent | 1606f1f3a734e8d8648fe98799d39ee21833adac (diff) | |
download | org.eclipse.tcf-5929e4e1fe422b86ff9581868ad4d6b2dab5556c.tar.gz org.eclipse.tcf-5929e4e1fe422b86ff9581868ad4d6b2dab5556c.tar.xz org.eclipse.tcf-5929e4e1fe422b86ff9581868ad4d6b2dab5556c.zip |
Releng: Run "Fix copyrights" tool to update the copyrights prior to a possible TCF 1.2 release
Diffstat (limited to 'target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org')
39 files changed, 2544 insertions, 2544 deletions
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/controls/FSNavigatorContentProvider.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/controls/FSNavigatorContentProvider.java index 01f7f9f22..372fec425 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/controls/FSNavigatorContentProvider.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/controls/FSNavigatorContentProvider.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011, 2012 Wind River Systems, Inc. and others. All rights reserved. + * Copyright (c) 2011, 2014 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 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 2d6f04816..57b7058cd 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,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011, 2012 Wind River Systems, Inc. and others. All rights reserved. + * Copyright (c) 2011, 2014 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 diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/dialogs/FSOpenFileDialog.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/dialogs/FSOpenFileDialog.java index c2e51d531..21c08aba4 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/dialogs/FSOpenFileDialog.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/dialogs/FSOpenFileDialog.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011, 2012 Wind River Systems, Inc. and others. All rights reserved. + * Copyright (c) 2011, 2014 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 diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/adapters/FSTreeNodeAdapterFactory.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/adapters/FSTreeNodeAdapterFactory.java index c08e55d16..6d0895b18 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/adapters/FSTreeNodeAdapterFactory.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/adapters/FSTreeNodeAdapterFactory.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011, 2012 Wind River Systems, Inc. and others. All rights reserved. + * Copyright (c) 2011, 2014 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 diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/adapters/FSTreeNodeFactory.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/adapters/FSTreeNodeFactory.java index f92416340..34e6d8ebb 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/adapters/FSTreeNodeFactory.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/adapters/FSTreeNodeFactory.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2012 Wind River Systems, Inc. and others. All rights reserved. + * Copyright (c) 2012, 2014 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 diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/adapters/NodeStateFilter.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/adapters/NodeStateFilter.java index a0bce1bb5..1ca440246 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/adapters/NodeStateFilter.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/adapters/NodeStateFilter.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011, 2012 Wind River Systems, Inc. and others. All rights reserved. + * Copyright (c) 2011, 2013 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 diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/adapters/PeerNodeViewerInput.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/adapters/PeerNodeViewerInput.java index 119bd25d9..bdb3580c1 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/adapters/PeerNodeViewerInput.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/adapters/PeerNodeViewerInput.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011, 2012 Wind River Systems, Inc. and others. All rights reserved. + * Copyright (c) 2011, 2014 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 diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/adapters/ViewerInputAdapterFactory.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/adapters/ViewerInputAdapterFactory.java index 730b93328..5107a78d1 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/adapters/ViewerInputAdapterFactory.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/adapters/ViewerInputAdapterFactory.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011, 2012 Wind River Systems, Inc. and others. All rights reserved. + * Copyright (c) 2011, 2014 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 diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/autosave/SaveAllListener.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/autosave/SaveAllListener.java index b5258c792..74ec4d7d8 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/autosave/SaveAllListener.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/autosave/SaveAllListener.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011, 2012 Wind River Systems, Inc. and others. All rights reserved. + * Copyright (c) 2011, 2013 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 diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/columns/DefaultImageProvider.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/columns/DefaultImageProvider.java index f81bed5ec..2f3b78a81 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/columns/DefaultImageProvider.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/columns/DefaultImageProvider.java @@ -1,84 +1,84 @@ -/*******************************************************************************
- * 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.columns;
-
-import org.eclipse.jface.resource.ImageDescriptor;
-import org.eclipse.swt.graphics.Image;
-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.tcf.filesystem.ui.internal.ImageConsts;
-import org.eclipse.ui.IEditorRegistry;
-import org.eclipse.ui.IWorkbench;
-import org.eclipse.ui.PlatformUI;
-
-/**
- * The default implementation of ImageProvider, defining the images
- * based on predefined images based on the node simulator.
- */
-public class DefaultImageProvider implements ImageProvider {
- // The editor registry used to search a file's image.
- private IEditorRegistry editorRegistry = null;
-
- /*
- * (non-Javadoc)
- * @see org.eclipse.tcf.te.tcf.filesystem.internal.columns.ImageProvider#getImage(org.eclipse.tcf.te.tcf.filesystem.model.FSTreeNode)
- */
- @Override
- public Image getImage(FSTreeNode node) {
- if (node.isSystemRoot()) {
- return UIPlugin.getImage(ImageConsts.ROOT);
- }
- else if (node.isRoot()) {
- return UIPlugin.getImage(ImageConsts.ROOT_DRIVE);
- }
- else if (node.isDirectory()) {
- return UIPlugin.getImage(ImageConsts.FOLDER);
- }
- else if (node.isFile()) {
- return getPredefinedImage(node);
- }
- return null;
- }
-
- /**
- * Get a predefined image for the tree node. These images are retrieved from
- * editor registry.
- *
- * @param node The file tree node.
- * @return The editor image for this simulator.
- */
- protected Image getPredefinedImage(FSTreeNode node) {
- Image image;
- String key = node.name;
- image = UIPlugin.getImage(key);
- if (image == null) {
- ImageDescriptor descriptor = getEditorRegistry().getImageDescriptor(key);
- if (descriptor == null) {
- descriptor = getEditorRegistry().getSystemExternalEditorImageDescriptor(key);
- }
- if (descriptor != null) {
- UIPlugin.getDefault().getImageRegistry().put(key, descriptor);
- }
- image = UIPlugin.getImage(key);
- }
- return image;
- }
-
- /**
- * Returns the workbench's editor registry.
- */
- private IEditorRegistry getEditorRegistry() {
- if (editorRegistry == null) {
- IWorkbench workbench = PlatformUI.getWorkbench();
- if (workbench != null) editorRegistry = workbench.getEditorRegistry();
- }
- return editorRegistry;
- }
-}
+/******************************************************************************* + * Copyright (c) 2012, 2014 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.columns; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.swt.graphics.Image; +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.tcf.filesystem.ui.internal.ImageConsts; +import org.eclipse.ui.IEditorRegistry; +import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.PlatformUI; + +/** + * The default implementation of ImageProvider, defining the images + * based on predefined images based on the node simulator. + */ +public class DefaultImageProvider implements ImageProvider { + // The editor registry used to search a file's image. + private IEditorRegistry editorRegistry = null; + + /* + * (non-Javadoc) + * @see org.eclipse.tcf.te.tcf.filesystem.internal.columns.ImageProvider#getImage(org.eclipse.tcf.te.tcf.filesystem.model.FSTreeNode) + */ + @Override + public Image getImage(FSTreeNode node) { + if (node.isSystemRoot()) { + return UIPlugin.getImage(ImageConsts.ROOT); + } + else if (node.isRoot()) { + return UIPlugin.getImage(ImageConsts.ROOT_DRIVE); + } + else if (node.isDirectory()) { + return UIPlugin.getImage(ImageConsts.FOLDER); + } + else if (node.isFile()) { + return getPredefinedImage(node); + } + return null; + } + + /** + * Get a predefined image for the tree node. These images are retrieved from + * editor registry. + * + * @param node The file tree node. + * @return The editor image for this simulator. + */ + protected Image getPredefinedImage(FSTreeNode node) { + Image image; + String key = node.name; + image = UIPlugin.getImage(key); + if (image == null) { + ImageDescriptor descriptor = getEditorRegistry().getImageDescriptor(key); + if (descriptor == null) { + descriptor = getEditorRegistry().getSystemExternalEditorImageDescriptor(key); + } + if (descriptor != null) { + UIPlugin.getDefault().getImageRegistry().put(key, descriptor); + } + image = UIPlugin.getImage(key); + } + return image; + } + + /** + * Returns the workbench's editor registry. + */ + private IEditorRegistry getEditorRegistry() { + if (editorRegistry == null) { + IWorkbench workbench = PlatformUI.getWorkbench(); + if (workbench != null) editorRegistry = workbench.getEditorRegistry(); + } + return editorRegistry; + } +} diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/columns/FSTreeNodeComparator.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/columns/FSTreeNodeComparator.java index 3584097d1..4aaad28d0 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/columns/FSTreeNodeComparator.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/columns/FSTreeNodeComparator.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011, 2012 Wind River Systems, Inc. and others. All rights reserved. + * Copyright (c) 2011, 2013 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 diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/columns/FileTypeComparator.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/columns/FileTypeComparator.java index a0a8417b5..8b53a6bed 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/columns/FileTypeComparator.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/columns/FileTypeComparator.java @@ -1,30 +1,30 @@ -/*******************************************************************************
- * 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.internal.columns;
-
-import org.eclipse.tcf.te.tcf.filesystem.core.model.FSTreeNode;
-
-/**
- * The comparator for the tree column "simulator".
- */
-public class FileTypeComparator extends FSTreeNodeComparator {
- private static final long serialVersionUID = 1L;
-
- /*
- * (non-Javadoc)
- * @see org.eclipse.tcf.te.tcf.filesystem.internal.columns.FSTreeNodeComparator#doCompare(org.eclipse.tcf.te.tcf.filesystem.model.FSTreeNode, org.eclipse.tcf.te.tcf.filesystem.model.FSTreeNode)
- */
- @Override
- public int doCompare(FSTreeNode node1, FSTreeNode node2) {
- String type1 = node1.getFileType();
- String type2 = node2.getFileType();
- return type1.compareTo(type2);
- }
-}
+/******************************************************************************* + * Copyright (c) 2011, 2014 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.columns; + +import org.eclipse.tcf.te.tcf.filesystem.core.model.FSTreeNode; + +/** + * The comparator for the tree column "simulator". + */ +public class FileTypeComparator extends FSTreeNodeComparator { + private static final long serialVersionUID = 1L; + + /* + * (non-Javadoc) + * @see org.eclipse.tcf.te.tcf.filesystem.internal.columns.FSTreeNodeComparator#doCompare(org.eclipse.tcf.te.tcf.filesystem.model.FSTreeNode, org.eclipse.tcf.te.tcf.filesystem.model.FSTreeNode) + */ + @Override + public int doCompare(FSTreeNode node1, FSTreeNode node2) { + String type1 = node1.getFileType(); + String type2 = node2.getFileType(); + return type1.compareTo(type2); + } +} diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/columns/FileTypeLabelProvider.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/columns/FileTypeLabelProvider.java index 9981023ba..d97fa3d31 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/columns/FileTypeLabelProvider.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/columns/FileTypeLabelProvider.java @@ -1,32 +1,32 @@ -/*******************************************************************************
- * 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.internal.columns;
-
-import org.eclipse.jface.viewers.LabelProvider;
-import org.eclipse.tcf.te.tcf.filesystem.core.model.FSTreeNode;
-
-/**
- * The label provider for the tree column "simulator".
- */
-public class FileTypeLabelProvider extends LabelProvider {
-
- /*
- * (non-Javadoc)
- * @see org.eclipse.jface.viewers.LabelProvider#getText(java.lang.Object)
- */
- @Override
- public String getText(Object element) {
- if (element instanceof FSTreeNode) {
- FSTreeNode node = (FSTreeNode) element;
- return node.getFileType();
- }
- return super.getText(element);
- }
-}
+/******************************************************************************* + * Copyright (c) 2011, 2014 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.columns; + +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.tcf.te.tcf.filesystem.core.model.FSTreeNode; + +/** + * The label provider for the tree column "simulator". + */ +public class FileTypeLabelProvider extends LabelProvider { + + /* + * (non-Javadoc) + * @see org.eclipse.jface.viewers.LabelProvider#getText(java.lang.Object) + */ + @Override + public String getText(Object element) { + if (element instanceof FSTreeNode) { + FSTreeNode node = (FSTreeNode) element; + return node.getFileType(); + } + return super.getText(element); + } +} diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/compare/EditableSharedDocumentAdapter.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/compare/EditableSharedDocumentAdapter.java index a06079e6d..ae087ace0 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/compare/EditableSharedDocumentAdapter.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/compare/EditableSharedDocumentAdapter.java @@ -1,256 +1,256 @@ -/*******************************************************************************
- * Copyright (c) 2005, 2012 IBM Corporation 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:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.tcf.te.tcf.filesystem.ui.internal.compare;
-
-import org.eclipse.compare.SharedDocumentAdapter;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.ui.IEditorInput;
-import org.eclipse.ui.texteditor.IDocumentProvider;
-import org.eclipse.ui.texteditor.IElementStateListener;
-
-/**
- * A shared document adapter that tracks whether the element is connected to a
- * shared document and whether the contents have been flushed from a compare
- * viewer. When contents are flushed, this adapter will connect to the document
- * provider to ensure that the changes are not lost (see
- * {@link #hasBufferedContents()}). In order to avoid a leak, the buffer must
- * either be saved (see
- * {@link #saveDocument(IEditorInput, boolean, IProgressMonitor)}) or released
- * (see {@link #releaseBuffer()}).
- * <p>
- * This adapter must have a one-to-one correspondence to a typed element.
- *
- * @since 3.7 - Copied from
- * org.eclipse.team.internal.ui.synchronize.EditableSharedDocumentAdapter
- */
-public class EditableSharedDocumentAdapter extends SharedDocumentAdapter implements IElementStateListener {
-
- private int connectionCount;
- private final ISharedDocumentAdapterListener listener;
- private IEditorInput bufferedKey;
-
- /**
- * Interface that provides this adapter with the action of the typed element
- * and supports call backs to the element when the adapter action changes.
- */
- public interface ISharedDocumentAdapterListener {
-
- /**
- * Method that is invoked when the adapter connects to the document
- * provider. This method is only invoked when the adapter first connects
- * to the document.
- */
- void handleDocumentConnected();
-
- /**
- * Method that is invoked when the adapter disconnects from the document
- * provider. This method is only invoked when the adapter no longer has
- * any connection to the document provider.
- */
- void handleDocumentDisconnected();
-
- /**
- * Method invoked when changes in the document are flushed to the
- * adapter.
- */
- void handleDocumentFlushed();
-
- /**
- * Method invoked when the file behind the shared document is deleted.
- */
- void handleDocumentDeleted();
-
- /**
- * Method invoked when the document dirty action changes from dirty to
- * clean.
- */
- void handleDocumentSaved();
- }
-
- /**
- * Create the shared document adapter for the given element.
- *
- * @param listener
- * access to element internals
- */
- public EditableSharedDocumentAdapter(ISharedDocumentAdapterListener listener) {
- super();
- this.listener = listener;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.compare.SharedDocumentAdapter#connect(org.eclipse.ui.texteditor.IDocumentProvider, org.eclipse.ui.IEditorInput)
- */
- @Override
- public void connect(IDocumentProvider provider, IEditorInput documentKey)
- throws CoreException {
- super.connect(provider, documentKey);
- connectionCount++;
- if (connectionCount == 1) {
- provider.addElementStateListener(this);
- listener.handleDocumentConnected();
- }
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.compare.SharedDocumentAdapter#disconnect(org.eclipse.ui.texteditor.IDocumentProvider, org.eclipse.ui.IEditorInput)
- */
- @Override
- public void disconnect(IDocumentProvider provider, IEditorInput documentKey) {
- try {
- super.disconnect(provider, documentKey);
- } finally {
- if (connectionCount > 0)
- connectionCount--;
- if (connectionCount == 0) {
- provider.removeElementStateListener(this);
- listener.handleDocumentDisconnected();
- }
- }
- }
-
- /**
- * Return whether the element is connected to a shared document.
- *
- * @return whether the element is connected to a shared document
- */
- public boolean isConnected() {
- return connectionCount > 0;
- }
-
- /**
- * Save the shared document of the element of this adapter.
- *
- * @param input
- * the document key of the element.
- * @param monitor
- * a progress monitor
- * @return whether the save succeeded or not
- * @throws CoreException
- */
- public boolean saveDocument(IEditorInput input, IProgressMonitor monitor)
- throws CoreException {
- if (isConnected()) {
- IDocumentProvider provider = SharedDocumentAdapter
- .getDocumentProvider(input);
- try {
- saveDocument(provider, input, provider.getDocument(input),
- true, monitor);
- } finally {
- // When we write the document, remove out hold on the buffer
- releaseBuffer();
- }
- return true;
- }
- return false;
- }
-
- /**
- * Release the buffer if this adapter has buffered the contents in response
- * to a
- * {@link #flushDocument(IDocumentProvider, IEditorInput, IDocument, boolean)}
- * .
- */
- public void releaseBuffer() {
- if (bufferedKey != null) {
- IDocumentProvider provider = SharedDocumentAdapter
- .getDocumentProvider(bufferedKey);
- provider.disconnect(bufferedKey);
- bufferedKey = null;
- }
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.compare.ISharedDocumentAdapter#flushDocument(org.eclipse.ui.texteditor.IDocumentProvider, org.eclipse.ui.IEditorInput, org.eclipse.jface.text.IDocument, boolean)
- */
- @Override
- public void flushDocument(IDocumentProvider provider,
- IEditorInput documentKey, IDocument document, boolean overwrite)
- throws CoreException {
- if (!hasBufferedContents()) {
- // On a flush, make an extra connection to the shared document so it
- // will be kept even
- // if it is no longer being viewed.
- bufferedKey = documentKey;
- provider.connect(bufferedKey);
- }
- this.listener.handleDocumentFlushed();
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.ui.texteditor.IElementStateListener#elementContentAboutToBeReplaced(java.lang.Object)
- */
- @Override
- public void elementContentAboutToBeReplaced(Object element) {
- // Nothing to do
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.ui.texteditor.IElementStateListener#elementContentReplaced(java.lang.Object)
- */
- @Override
- public void elementContentReplaced(Object element) {
- // Nothing to do
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.ui.texteditor.IElementStateListener#elementDeleted(java.lang.Object)
- */
- @Override
- public void elementDeleted(Object element) {
- listener.handleDocumentDeleted();
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.ui.texteditor.IElementStateListener#elementDirtyStateChanged(java.lang.Object, boolean)
- */
- @Override
- public void elementDirtyStateChanged(Object element, boolean isDirty) {
- if (!isDirty) {
- this.listener.handleDocumentSaved();
- }
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.ui.texteditor.IElementStateListener#elementMoved(java.lang.Object, java.lang.Object)
- */
- @Override
- public void elementMoved(Object originalElement, Object movedElement) {
- // Nothing to do
- }
-
- /**
- * Return whether the adapter has buffered contents. The adapter buffers
- * contents by connecting to the document through the document provider.
- * This means that the adapter must be disconnected either by saving or
- * discarding the buffer.
- *
- * @return whether the adapter has buffered contents
- */
- public boolean hasBufferedContents() {
- return bufferedKey != null;
- }
-
- /**
- * Override getDocumentKey in the super class to provide an editor input
- * when the element is a <code>LocalTypedElement</code>.
- */
- @Override
- public IEditorInput getDocumentKey(Object element) {
- if (element instanceof LocalTypedElement) {
- LocalTypedElement localElement = (LocalTypedElement) element;
- return localElement.getEditorInput();
- }
- return super.getDocumentKey(element);
- }
-}
+/******************************************************************************* + * Copyright (c) 2005, 2014 IBM Corporation 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: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.tcf.te.tcf.filesystem.ui.internal.compare; + +import org.eclipse.compare.SharedDocumentAdapter; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.jface.text.IDocument; +import org.eclipse.ui.IEditorInput; +import org.eclipse.ui.texteditor.IDocumentProvider; +import org.eclipse.ui.texteditor.IElementStateListener; + +/** + * A shared document adapter that tracks whether the element is connected to a + * shared document and whether the contents have been flushed from a compare + * viewer. When contents are flushed, this adapter will connect to the document + * provider to ensure that the changes are not lost (see + * {@link #hasBufferedContents()}). In order to avoid a leak, the buffer must + * either be saved (see + * {@link #saveDocument(IEditorInput, boolean, IProgressMonitor)}) or released + * (see {@link #releaseBuffer()}). + * <p> + * This adapter must have a one-to-one correspondence to a typed element. + * + * @since 3.7 - Copied from + * org.eclipse.team.internal.ui.synchronize.EditableSharedDocumentAdapter + */ +public class EditableSharedDocumentAdapter extends SharedDocumentAdapter implements IElementStateListener { + + private int connectionCount; + private final ISharedDocumentAdapterListener listener; + private IEditorInput bufferedKey; + + /** + * Interface that provides this adapter with the action of the typed element + * and supports call backs to the element when the adapter action changes. + */ + public interface ISharedDocumentAdapterListener { + + /** + * Method that is invoked when the adapter connects to the document + * provider. This method is only invoked when the adapter first connects + * to the document. + */ + void handleDocumentConnected(); + + /** + * Method that is invoked when the adapter disconnects from the document + * provider. This method is only invoked when the adapter no longer has + * any connection to the document provider. + */ + void handleDocumentDisconnected(); + + /** + * Method invoked when changes in the document are flushed to the + * adapter. + */ + void handleDocumentFlushed(); + + /** + * Method invoked when the file behind the shared document is deleted. + */ + void handleDocumentDeleted(); + + /** + * Method invoked when the document dirty action changes from dirty to + * clean. + */ + void handleDocumentSaved(); + } + + /** + * Create the shared document adapter for the given element. + * + * @param listener + * access to element internals + */ + public EditableSharedDocumentAdapter(ISharedDocumentAdapterListener listener) { + super(); + this.listener = listener; + } + + /* (non-Javadoc) + * @see org.eclipse.compare.SharedDocumentAdapter#connect(org.eclipse.ui.texteditor.IDocumentProvider, org.eclipse.ui.IEditorInput) + */ + @Override + public void connect(IDocumentProvider provider, IEditorInput documentKey) + throws CoreException { + super.connect(provider, documentKey); + connectionCount++; + if (connectionCount == 1) { + provider.addElementStateListener(this); + listener.handleDocumentConnected(); + } + } + + /* (non-Javadoc) + * @see org.eclipse.compare.SharedDocumentAdapter#disconnect(org.eclipse.ui.texteditor.IDocumentProvider, org.eclipse.ui.IEditorInput) + */ + @Override + public void disconnect(IDocumentProvider provider, IEditorInput documentKey) { + try { + super.disconnect(provider, documentKey); + } finally { + if (connectionCount > 0) + connectionCount--; + if (connectionCount == 0) { + provider.removeElementStateListener(this); + listener.handleDocumentDisconnected(); + } + } + } + + /** + * Return whether the element is connected to a shared document. + * + * @return whether the element is connected to a shared document + */ + public boolean isConnected() { + return connectionCount > 0; + } + + /** + * Save the shared document of the element of this adapter. + * + * @param input + * the document key of the element. + * @param monitor + * a progress monitor + * @return whether the save succeeded or not + * @throws CoreException + */ + public boolean saveDocument(IEditorInput input, IProgressMonitor monitor) + throws CoreException { + if (isConnected()) { + IDocumentProvider provider = SharedDocumentAdapter + .getDocumentProvider(input); + try { + saveDocument(provider, input, provider.getDocument(input), + true, monitor); + } finally { + // When we write the document, remove out hold on the buffer + releaseBuffer(); + } + return true; + } + return false; + } + + /** + * Release the buffer if this adapter has buffered the contents in response + * to a + * {@link #flushDocument(IDocumentProvider, IEditorInput, IDocument, boolean)} + * . + */ + public void releaseBuffer() { + if (bufferedKey != null) { + IDocumentProvider provider = SharedDocumentAdapter + .getDocumentProvider(bufferedKey); + provider.disconnect(bufferedKey); + bufferedKey = null; + } + } + + /* (non-Javadoc) + * @see org.eclipse.compare.ISharedDocumentAdapter#flushDocument(org.eclipse.ui.texteditor.IDocumentProvider, org.eclipse.ui.IEditorInput, org.eclipse.jface.text.IDocument, boolean) + */ + @Override + public void flushDocument(IDocumentProvider provider, + IEditorInput documentKey, IDocument document, boolean overwrite) + throws CoreException { + if (!hasBufferedContents()) { + // On a flush, make an extra connection to the shared document so it + // will be kept even + // if it is no longer being viewed. + bufferedKey = documentKey; + provider.connect(bufferedKey); + } + this.listener.handleDocumentFlushed(); + } + + /* (non-Javadoc) + * @see org.eclipse.ui.texteditor.IElementStateListener#elementContentAboutToBeReplaced(java.lang.Object) + */ + @Override + public void elementContentAboutToBeReplaced(Object element) { + // Nothing to do + } + + /* (non-Javadoc) + * @see org.eclipse.ui.texteditor.IElementStateListener#elementContentReplaced(java.lang.Object) + */ + @Override + public void elementContentReplaced(Object element) { + // Nothing to do + } + + /* (non-Javadoc) + * @see org.eclipse.ui.texteditor.IElementStateListener#elementDeleted(java.lang.Object) + */ + @Override + public void elementDeleted(Object element) { + listener.handleDocumentDeleted(); + } + + /* (non-Javadoc) + * @see org.eclipse.ui.texteditor.IElementStateListener#elementDirtyStateChanged(java.lang.Object, boolean) + */ + @Override + public void elementDirtyStateChanged(Object element, boolean isDirty) { + if (!isDirty) { + this.listener.handleDocumentSaved(); + } + } + + /* (non-Javadoc) + * @see org.eclipse.ui.texteditor.IElementStateListener#elementMoved(java.lang.Object, java.lang.Object) + */ + @Override + public void elementMoved(Object originalElement, Object movedElement) { + // Nothing to do + } + + /** + * Return whether the adapter has buffered contents. The adapter buffers + * contents by connecting to the document through the document provider. + * This means that the adapter must be disconnected either by saving or + * discarding the buffer. + * + * @return whether the adapter has buffered contents + */ + public boolean hasBufferedContents() { + return bufferedKey != null; + } + + /** + * Override getDocumentKey in the super class to provide an editor input + * when the element is a <code>LocalTypedElement</code>. + */ + @Override + public IEditorInput getDocumentKey(Object element) { + if (element instanceof LocalTypedElement) { + LocalTypedElement localElement = (LocalTypedElement) element; + return localElement.getEditorInput(); + } + return super.getDocumentKey(element); + } +} diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/compare/LocalFileSaveable.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/compare/LocalFileSaveable.java index 3ed1015e4..db636b588 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/compare/LocalFileSaveable.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/compare/LocalFileSaveable.java @@ -1,481 +1,481 @@ -/*******************************************************************************
- * 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.CompareEditorInput;
-import org.eclipse.compare.ICompareContainer;
-import org.eclipse.compare.IContentChangeListener;
-import org.eclipse.compare.IContentChangeNotifier;
-import org.eclipse.compare.ISharedDocumentAdapter;
-import org.eclipse.compare.SharedDocumentAdapter;
-import org.eclipse.compare.contentmergeviewer.ContentMergeViewer;
-import org.eclipse.core.runtime.Assert;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.ListenerList;
-import org.eclipse.core.runtime.NullProgressMonitor;
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.core.runtime.SafeRunner;
-import org.eclipse.jface.resource.ImageDescriptor;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.util.IPropertyChangeListener;
-import org.eclipse.jface.util.PropertyChangeEvent;
-import org.eclipse.jface.util.SafeRunnable;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.tcf.te.tcf.filesystem.core.internal.operations.IOpExecutor;
-import org.eclipse.tcf.te.tcf.filesystem.core.internal.operations.OpUpload;
-import org.eclipse.tcf.te.tcf.filesystem.core.model.FSTreeNode;
-import org.eclipse.tcf.te.tcf.filesystem.ui.internal.compare.EditableSharedDocumentAdapter.ISharedDocumentAdapterListener;
-import org.eclipse.tcf.te.tcf.filesystem.ui.internal.operations.UiExecutor;
-import org.eclipse.ui.IEditorInput;
-import org.eclipse.ui.IPropertyListener;
-import org.eclipse.ui.ISaveablesLifecycleListener;
-import org.eclipse.ui.IWorkbenchPart;
-import org.eclipse.ui.IWorkbenchPartConstants;
-import org.eclipse.ui.Saveable;
-import org.eclipse.ui.SaveablesLifecycleEvent;
-import org.eclipse.ui.texteditor.IDocumentProvider;
-
-/**
- * A <code>LocalFileSaveable</code> is used as the saveable object that provides
- * the save behavior for the merge editor input(<code>MergeEditorInput</code>).
- */
-public class LocalFileSaveable extends Saveable implements
- IPropertyChangeListener, ISharedDocumentAdapterListener,
- IContentChangeListener {
- // The property listener list.
- private ListenerList listeners = new ListenerList(ListenerList.IDENTITY);
-
- // The merge input that provides the left and the right compared elements.
- private final MergeInput input;
-
- // The input of the editor that provides the comparing view.
- private final MergeEditorInput editorInput;
-
- // If the current document of the file is being saved.
- private boolean saving;
-
- // The local file element.
- private LocalTypedElement fileElement;
-
- // The document provided by the local file.
- private IDocument document;
-
- // If the current document has been connected.
- private boolean connected;
-
- /**
- * Create the file-based saveable comparison.
- *
- * @param input
- * the compare input to be save
- * @param editorInput
- * the editor input containing the comparison
- * @param fileElement
- * the file element that handles the saving and change
- * notification
- */
- public LocalFileSaveable(MergeInput input, MergeEditorInput editorInput, LocalTypedElement fileElement) {
- Assert.isNotNull(input);
-
- this.input = input;
- this.editorInput = editorInput;
- this.fileElement = fileElement;
- this.fileElement.addContentChangeListener(this);
- this.fileElement.setDocumentListener(this);
- }
-
- /**
- * Dispose of the saveable.
- */
- public void dispose() {
- fileElement.removeContentChangeListener(this);
- fileElement.discardBuffer();
- fileElement.setDocumentListener(null);
- }
-
- /**
- * Performs the save.
- *
- * @param monitor The progress monitor.
- *
- * @throws CoreException If the save operation fails.
- */
- protected void performSave(IProgressMonitor monitor) throws CoreException {
- try {
- saving = true;
- monitor.beginTask(null, 100);
- // First, we need to flush the viewers so the changes get buffered
- // in the input
- flushViewers(monitor);
- // Then we tell the input to commit its changes
- // Only the left is ever saveable
- if (fileElement.isDirty()) {
- if (fileElement.isConnected()) {
- fileElement.store2Document(monitor);
- } else {
- fileElement.store2Cache(monitor);
- }
- }
- } finally {
- // Make sure we fire a change for the compare input to update the
- // viewers
- fireInputChange();
- setDirty(false);
- saving = false;
- monitor.done();
- //Trigger upload action
- FSTreeNode node = fileElement.getFSTreeNode();
- IOpExecutor executor = new UiExecutor();
- executor.execute(new OpUpload(node));
- }
- }
-
- /**
- * Flush the contents of any viewers into the compare input.
- *
- * @param monitor
- * a progress monitor
- * @throws CoreException
- */
- protected void flushViewers(IProgressMonitor monitor) throws CoreException {
- editorInput.saveChanges(monitor);
- }
-
- /**
- * Fire an input change for the compare input after it has been saved.
- */
- protected void fireInputChange() {
- editorInput.getCompareResult().fireInputChanged();
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.ui.Saveable#isDirty()
- */
- @Override
- public boolean isDirty() {
- return editorInput.isSaveNeeded();
- }
-
- /**
- * Marks the editor input dirty.
- *
- * @param dirty <code>True</code> if the editor is dirty, <code>false</code> if not.
- */
- protected void setDirty(boolean dirty) {
- if (isDirty() != dirty) {
- editorInput.setDirty(dirty);
- firePropertyChange(IWorkbenchPartConstants.PROP_DIRTY);
- }
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.ui.Saveable#getName()
- */
- @Override
- public String getName() {
- // Return the name of the file element as held in the compare input
- if (fileElement.equals(input.getLeft())) {
- return input.getLeft().getName();
- }
- if (fileElement.equals(input.getRight())) {
- return input.getRight().getName();
- }
-
- // Fallback call returning name of the main non-null element of the input
- //
- // see org.eclipse.team.internal.ui.mapping.AbstractCompareInput#getMainElement()
- return input.getName();
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.ui.Saveable#getToolTipText()
- */
- @Override
- public String getToolTipText() {
- return editorInput.getToolTipText();
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.ui.Saveable#getImageDescriptor()
- */
- @Override
- public ImageDescriptor getImageDescriptor() {
- Image image = input.getImage();
- if (image != null)
- return ImageDescriptor.createFromImage(image);
- return null;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.jface.util.IPropertyChangeListener#propertyChange(org.eclipse.jface.util.PropertyChangeEvent)
- */
- @Override
- public void propertyChange(PropertyChangeEvent e) {
- String propertyName = e.getProperty();
- if (CompareEditorInput.DIRTY_STATE.equals(propertyName)) {
- boolean changed = false;
- Object newValue = e.getNewValue();
- if (newValue instanceof Boolean)
- changed = ((Boolean) newValue).booleanValue();
-
- ContentMergeViewer cmv = (ContentMergeViewer) e.getSource();
-
- if (fileElement.equals(input.getLeft())) {
- if (changed && cmv.internalIsLeftDirty())
- setDirty(changed);
- else if (!changed && !cmv.internalIsLeftDirty()) {
- setDirty(changed);
- }
- }
- if (fileElement.equals(input.getRight())) {
- if (changed && cmv.internalIsRightDirty())
- setDirty(changed);
- else if (!changed && !cmv.internalIsRightDirty()) {
- setDirty(changed);
- }
- }
- }
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.ui.Saveable#hashCode()
- */
- @Override
- public int hashCode() {
- if (document != null) {
- return document.hashCode();
- }
- return input.hashCode();
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.ui.Saveable#equals(java.lang.Object)
- */
- @Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
-
- if (!(obj instanceof Saveable))
- return false;
-
- if (document != null) {
- Object otherDocument = ((Saveable) obj).getAdapter(IDocument.class);
-
- if (otherDocument == null)
- return false;
-
- return document.equals(otherDocument);
- }
-
- if (obj instanceof LocalFileSaveable) {
- LocalFileSaveable saveable = (LocalFileSaveable) obj;
- return saveable.input.equals(input);
- }
- return false;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.ui.Saveable#getAdapter(java.lang.Class)
- */
- @Override
- public Object getAdapter(Class adapter) {
- if (adapter == IDocument.class) {
- if (document != null)
- return document;
- if (fileElement.isConnected()) {
- ISharedDocumentAdapter sda = (ISharedDocumentAdapter) fileElement
- .getAdapter(ISharedDocumentAdapter.class);
- if (sda != null) {
- IEditorInput input = sda.getDocumentKey(fileElement);
- if (input != null) {
- IDocumentProvider provider = SharedDocumentAdapter
- .getDocumentProvider(input);
- if (provider != null)
- return provider.getDocument(input);
- }
- }
- }
- }
- if (adapter == IEditorInput.class) {
- return fileElement.getEditorInput();
- }
- return super.getAdapter(adapter);
- }
-
- /**
- * Get an ISaveablesLifecycleListener from the specified workbench
- * part.
- * @param part The workbench part.
- * @return The listener.
- */
- private ISaveablesLifecycleListener getSaveablesLifecycleListener(
- IWorkbenchPart part) {
- if (part instanceof ISaveablesLifecycleListener)
- return (ISaveablesLifecycleListener) part;
-
- Object adapted = part.getAdapter(ISaveablesLifecycleListener.class);
- if (adapted instanceof ISaveablesLifecycleListener)
- return (ISaveablesLifecycleListener) adapted;
-
- adapted = Platform.getAdapterManager().loadAdapter(part,
- ISaveablesLifecycleListener.class.getName());
- if (adapted instanceof ISaveablesLifecycleListener)
- return (ISaveablesLifecycleListener) adapted;
-
- return (ISaveablesLifecycleListener) part.getSite().getService(
- ISaveablesLifecycleListener.class);
- }
-
- /**
- * When the document of the local file is connected, register this saveable.
- */
- private void registerSaveable() {
- ICompareContainer container = editorInput.getContainer();
- IWorkbenchPart part = container.getWorkbenchPart();
- if (part != null) {
- ISaveablesLifecycleListener lifecycleListener = getSaveablesLifecycleListener(part);
- // Remove this saveable from the lifecycle listener
- lifecycleListener.handleLifecycleEvent(new SaveablesLifecycleEvent(
- part, SaveablesLifecycleEvent.POST_CLOSE,
- new Saveable[] { this }, false));
- // Now fix the hashing so it uses the fConnected fDocument
- IDocument document = (IDocument) getAdapter(IDocument.class);
- if (document != null) {
- this.document = document;
- }
- // Finally, add this saveable back to the listener
- lifecycleListener.handleLifecycleEvent(new SaveablesLifecycleEvent(
- part, SaveablesLifecycleEvent.POST_OPEN,
- new Saveable[] { this }, false));
- }
- }
-
- /*
- * (non-Javadoc)
- * @see org.eclipse.tcf.te.tcf.filesystem.internal.compare.EditableSharedDocumentAdapter.ISharedDocumentAdapterListener#handleDocumentConnected()
- */
- @Override
- public void handleDocumentConnected() {
- if (connected)
- return;
- connected = true;
- registerSaveable();
- fileElement.setDocumentListener(null);
- }
-
- @Override
- public void handleDocumentDeleted() {
- // Ignore
- }
-
- @Override
- public void handleDocumentDisconnected() {
- // Ignore
- }
-
- @Override
- public void handleDocumentFlushed() {
- // Ignore
- }
-
- @Override
- public void handleDocumentSaved() {
- // Ignore
- }
-
- /*
- * (non-Javadoc)
- * @see org.eclipse.compare.IContentChangeListener#contentChanged(org.eclipse.compare.IContentChangeNotifier)
- */
- @Override
- public void contentChanged(IContentChangeNotifier source) {
- if (!saving) {
- try {
- performSave(new NullProgressMonitor());
- } catch (CoreException e) {
- e.printStackTrace();
- }
- }
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void doSave(IProgressMonitor monitor) throws CoreException {
- if (isDirty()) {
- performSave(monitor);
- setDirty(false);
- }
- }
-
- /**
- * Revert any changes in the buffer back to the last saved action.
- *
- * @param monitor
- * a progress monitor on <code>null</code> if progress feedback
- * is not required
- */
- public void doRevert(IProgressMonitor monitor) {
- if (!isDirty())
- return;
- fileElement.discardBuffer();
- setDirty(false);
- }
-
- /**
- * Add a property change listener. Adding a listener that is already
- * registered has no effect.
- *
- * @param listener
- * the listener
- */
- public void addPropertyListener(IPropertyListener listener) {
- listeners.add(listener);
- }
-
- /**
- * Remove a property change listener. Removing a listener that is not
- * registered has no effect.
- *
- * @param listener
- * the listener
- */
- public void removePropertyListener(IPropertyListener listener) {
- listeners.remove(listener);
- }
-
- /**
- * Fire a property change event for this buffer.
- *
- * @param property
- * the property that changed
- */
- protected void firePropertyChange(final int property) {
- Object[] allListeners = listeners.getListeners();
- for (int i = 0; i < allListeners.length; i++) {
- final Object object = allListeners[i];
- SafeRunner.run(new SafeRunnable() {
- @Override
- public void handleException(Throwable e) {
- // Ignore exception
- }
- @Override
- public void run() throws Exception {
- ((IPropertyListener) object).propertyChanged(
- LocalFileSaveable.this, property);
- }
- });
- }
- }
-}
+/******************************************************************************* + * Copyright (c) 2011, 2014 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.CompareEditorInput; +import org.eclipse.compare.ICompareContainer; +import org.eclipse.compare.IContentChangeListener; +import org.eclipse.compare.IContentChangeNotifier; +import org.eclipse.compare.ISharedDocumentAdapter; +import org.eclipse.compare.SharedDocumentAdapter; +import org.eclipse.compare.contentmergeviewer.ContentMergeViewer; +import org.eclipse.core.runtime.Assert; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.ListenerList; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.core.runtime.Platform; +import org.eclipse.core.runtime.SafeRunner; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.util.IPropertyChangeListener; +import org.eclipse.jface.util.PropertyChangeEvent; +import org.eclipse.jface.util.SafeRunnable; +import org.eclipse.swt.graphics.Image; +import org.eclipse.tcf.te.tcf.filesystem.core.internal.operations.IOpExecutor; +import org.eclipse.tcf.te.tcf.filesystem.core.internal.operations.OpUpload; +import org.eclipse.tcf.te.tcf.filesystem.core.model.FSTreeNode; +import org.eclipse.tcf.te.tcf.filesystem.ui.internal.compare.EditableSharedDocumentAdapter.ISharedDocumentAdapterListener; +import org.eclipse.tcf.te.tcf.filesystem.ui.internal.operations.UiExecutor; +import org.eclipse.ui.IEditorInput; +import org.eclipse.ui.IPropertyListener; +import org.eclipse.ui.ISaveablesLifecycleListener; +import org.eclipse.ui.IWorkbenchPart; +import org.eclipse.ui.IWorkbenchPartConstants; +import org.eclipse.ui.Saveable; +import org.eclipse.ui.SaveablesLifecycleEvent; +import org.eclipse.ui.texteditor.IDocumentProvider; + +/** + * A <code>LocalFileSaveable</code> is used as the saveable object that provides + * the save behavior for the merge editor input(<code>MergeEditorInput</code>). + */ +public class LocalFileSaveable extends Saveable implements + IPropertyChangeListener, ISharedDocumentAdapterListener, + IContentChangeListener { + // The property listener list. + private ListenerList listeners = new ListenerList(ListenerList.IDENTITY); + + // The merge input that provides the left and the right compared elements. + private final MergeInput input; + + // The input of the editor that provides the comparing view. + private final MergeEditorInput editorInput; + + // If the current document of the file is being saved. + private boolean saving; + + // The local file element. + private LocalTypedElement fileElement; + + // The document provided by the local file. + private IDocument document; + + // If the current document has been connected. + private boolean connected; + + /** + * Create the file-based saveable comparison. + * + * @param input + * the compare input to be save + * @param editorInput + * the editor input containing the comparison + * @param fileElement + * the file element that handles the saving and change + * notification + */ + public LocalFileSaveable(MergeInput input, MergeEditorInput editorInput, LocalTypedElement fileElement) { + Assert.isNotNull(input); + + this.input = input; + this.editorInput = editorInput; + this.fileElement = fileElement; + this.fileElement.addContentChangeListener(this); + this.fileElement.setDocumentListener(this); + } + + /** + * Dispose of the saveable. + */ + public void dispose() { + fileElement.removeContentChangeListener(this); + fileElement.discardBuffer(); + fileElement.setDocumentListener(null); + } + + /** + * Performs the save. + * + * @param monitor The progress monitor. + * + * @throws CoreException If the save operation fails. + */ + protected void performSave(IProgressMonitor monitor) throws CoreException { + try { + saving = true; + monitor.beginTask(null, 100); + // First, we need to flush the viewers so the changes get buffered + // in the input + flushViewers(monitor); + // Then we tell the input to commit its changes + // Only the left is ever saveable + if (fileElement.isDirty()) { + if (fileElement.isConnected()) { + fileElement.store2Document(monitor); + } else { + fileElement.store2Cache(monitor); + } + } + } finally { + // Make sure we fire a change for the compare input to update the + // viewers + fireInputChange(); + setDirty(false); + saving = false; + monitor.done(); + //Trigger upload action + FSTreeNode node = fileElement.getFSTreeNode(); + IOpExecutor executor = new UiExecutor(); + executor.execute(new OpUpload(node)); + } + } + + /** + * Flush the contents of any viewers into the compare input. + * + * @param monitor + * a progress monitor + * @throws CoreException + */ + protected void flushViewers(IProgressMonitor monitor) throws CoreException { + editorInput.saveChanges(monitor); + } + + /** + * Fire an input change for the compare input after it has been saved. + */ + protected void fireInputChange() { + editorInput.getCompareResult().fireInputChanged(); + } + + /* (non-Javadoc) + * @see org.eclipse.ui.Saveable#isDirty() + */ + @Override + public boolean isDirty() { + return editorInput.isSaveNeeded(); + } + + /** + * Marks the editor input dirty. + * + * @param dirty <code>True</code> if the editor is dirty, <code>false</code> if not. + */ + protected void setDirty(boolean dirty) { + if (isDirty() != dirty) { + editorInput.setDirty(dirty); + firePropertyChange(IWorkbenchPartConstants.PROP_DIRTY); + } + } + + /* (non-Javadoc) + * @see org.eclipse.ui.Saveable#getName() + */ + @Override + public String getName() { + // Return the name of the file element as held in the compare input + if (fileElement.equals(input.getLeft())) { + return input.getLeft().getName(); + } + if (fileElement.equals(input.getRight())) { + return input.getRight().getName(); + } + + // Fallback call returning name of the main non-null element of the input + // + // see org.eclipse.team.internal.ui.mapping.AbstractCompareInput#getMainElement() + return input.getName(); + } + + /* (non-Javadoc) + * @see org.eclipse.ui.Saveable#getToolTipText() + */ + @Override + public String getToolTipText() { + return editorInput.getToolTipText(); + } + + /* (non-Javadoc) + * @see org.eclipse.ui.Saveable#getImageDescriptor() + */ + @Override + public ImageDescriptor getImageDescriptor() { + Image image = input.getImage(); + if (image != null) + return ImageDescriptor.createFromImage(image); + return null; + } + + /* (non-Javadoc) + * @see org.eclipse.jface.util.IPropertyChangeListener#propertyChange(org.eclipse.jface.util.PropertyChangeEvent) + */ + @Override + public void propertyChange(PropertyChangeEvent e) { + String propertyName = e.getProperty(); + if (CompareEditorInput.DIRTY_STATE.equals(propertyName)) { + boolean changed = false; + Object newValue = e.getNewValue(); + if (newValue instanceof Boolean) + changed = ((Boolean) newValue).booleanValue(); + + ContentMergeViewer cmv = (ContentMergeViewer) e.getSource(); + + if (fileElement.equals(input.getLeft())) { + if (changed && cmv.internalIsLeftDirty()) + setDirty(changed); + else if (!changed && !cmv.internalIsLeftDirty()) { + setDirty(changed); + } + } + if (fileElement.equals(input.getRight())) { + if (changed && cmv.internalIsRightDirty()) + setDirty(changed); + else if (!changed && !cmv.internalIsRightDirty()) { + setDirty(changed); + } + } + } + } + + /* (non-Javadoc) + * @see org.eclipse.ui.Saveable#hashCode() + */ + @Override + public int hashCode() { + if (document != null) { + return document.hashCode(); + } + return input.hashCode(); + } + + /* (non-Javadoc) + * @see org.eclipse.ui.Saveable#equals(java.lang.Object) + */ + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + + if (!(obj instanceof Saveable)) + return false; + + if (document != null) { + Object otherDocument = ((Saveable) obj).getAdapter(IDocument.class); + + if (otherDocument == null) + return false; + + return document.equals(otherDocument); + } + + if (obj instanceof LocalFileSaveable) { + LocalFileSaveable saveable = (LocalFileSaveable) obj; + return saveable.input.equals(input); + } + return false; + } + + /* (non-Javadoc) + * @see org.eclipse.ui.Saveable#getAdapter(java.lang.Class) + */ + @Override + public Object getAdapter(Class adapter) { + if (adapter == IDocument.class) { + if (document != null) + return document; + if (fileElement.isConnected()) { + ISharedDocumentAdapter sda = (ISharedDocumentAdapter) fileElement + .getAdapter(ISharedDocumentAdapter.class); + if (sda != null) { + IEditorInput input = sda.getDocumentKey(fileElement); + if (input != null) { + IDocumentProvider provider = SharedDocumentAdapter + .getDocumentProvider(input); + if (provider != null) + return provider.getDocument(input); + } + } + } + } + if (adapter == IEditorInput.class) { + return fileElement.getEditorInput(); + } + return super.getAdapter(adapter); + } + + /** + * Get an ISaveablesLifecycleListener from the specified workbench + * part. + * @param part The workbench part. + * @return The listener. + */ + private ISaveablesLifecycleListener getSaveablesLifecycleListener( + IWorkbenchPart part) { + if (part instanceof ISaveablesLifecycleListener) + return (ISaveablesLifecycleListener) part; + + Object adapted = part.getAdapter(ISaveablesLifecycleListener.class); + if (adapted instanceof ISaveablesLifecycleListener) + return (ISaveablesLifecycleListener) adapted; + + adapted = Platform.getAdapterManager().loadAdapter(part, + ISaveablesLifecycleListener.class.getName()); + if (adapted instanceof ISaveablesLifecycleListener) + return (ISaveablesLifecycleListener) adapted; + + return (ISaveablesLifecycleListener) part.getSite().getService( + ISaveablesLifecycleListener.class); + } + + /** + * When the document of the local file is connected, register this saveable. + */ + private void registerSaveable() { + ICompareContainer container = editorInput.getContainer(); + IWorkbenchPart part = container.getWorkbenchPart(); + if (part != null) { + ISaveablesLifecycleListener lifecycleListener = getSaveablesLifecycleListener(part); + // Remove this saveable from the lifecycle listener + lifecycleListener.handleLifecycleEvent(new SaveablesLifecycleEvent( + part, SaveablesLifecycleEvent.POST_CLOSE, + new Saveable[] { this }, false)); + // Now fix the hashing so it uses the fConnected fDocument + IDocument document = (IDocument) getAdapter(IDocument.class); + if (document != null) { + this.document = document; + } + // Finally, add this saveable back to the listener + lifecycleListener.handleLifecycleEvent(new SaveablesLifecycleEvent( + part, SaveablesLifecycleEvent.POST_OPEN, + new Saveable[] { this }, false)); + } + } + + /* + * (non-Javadoc) + * @see org.eclipse.tcf.te.tcf.filesystem.internal.compare.EditableSharedDocumentAdapter.ISharedDocumentAdapterListener#handleDocumentConnected() + */ + @Override + public void handleDocumentConnected() { + if (connected) + return; + connected = true; + registerSaveable(); + fileElement.setDocumentListener(null); + } + + @Override + public void handleDocumentDeleted() { + // Ignore + } + + @Override + public void handleDocumentDisconnected() { + // Ignore + } + + @Override + public void handleDocumentFlushed() { + // Ignore + } + + @Override + public void handleDocumentSaved() { + // Ignore + } + + /* + * (non-Javadoc) + * @see org.eclipse.compare.IContentChangeListener#contentChanged(org.eclipse.compare.IContentChangeNotifier) + */ + @Override + public void contentChanged(IContentChangeNotifier source) { + if (!saving) { + try { + performSave(new NullProgressMonitor()); + } catch (CoreException e) { + e.printStackTrace(); + } + } + } + + /** + * {@inheritDoc} + */ + @Override + public void doSave(IProgressMonitor monitor) throws CoreException { + if (isDirty()) { + performSave(monitor); + setDirty(false); + } + } + + /** + * Revert any changes in the buffer back to the last saved action. + * + * @param monitor + * a progress monitor on <code>null</code> if progress feedback + * is not required + */ + public void doRevert(IProgressMonitor monitor) { + if (!isDirty()) + return; + fileElement.discardBuffer(); + setDirty(false); + } + + /** + * Add a property change listener. Adding a listener that is already + * registered has no effect. + * + * @param listener + * the listener + */ + public void addPropertyListener(IPropertyListener listener) { + listeners.add(listener); + } + + /** + * Remove a property change listener. Removing a listener that is not + * registered has no effect. + * + * @param listener + * the listener + */ + public void removePropertyListener(IPropertyListener listener) { + listeners.remove(listener); + } + + /** + * Fire a property change event for this buffer. + * + * @param property + * the property that changed + */ + protected void firePropertyChange(final int property) { + Object[] allListeners = listeners.getListeners(); + for (int i = 0; i < allListeners.length; i++) { + final Object object = allListeners[i]; + SafeRunner.run(new SafeRunnable() { + @Override + public void handleException(Throwable e) { + // Ignore exception + } + @Override + public void run() throws Exception { + ((IPropertyListener) object).propertyChanged( + LocalFileSaveable.this, property); + } + }); + } + } +} diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/compare/LocalTypedElement.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/compare/LocalTypedElement.java index 3ee85cce6..825a66743 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/compare/LocalTypedElement.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/compare/LocalTypedElement.java @@ -1,307 +1,307 @@ -/*******************************************************************************
- * 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 java.io.BufferedInputStream;
-import java.io.BufferedOutputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-
-import org.eclipse.compare.IEditableContent;
-import org.eclipse.compare.ISharedDocumentAdapter;
-import org.eclipse.compare.ITypedElement;
-import org.eclipse.core.filesystem.EFS;
-import org.eclipse.core.filesystem.IFileStore;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IAdaptable;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.osgi.util.NLS;
-import org.eclipse.tcf.te.tcf.filesystem.core.internal.utils.CacheManager;
-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.tcf.filesystem.ui.internal.compare.EditableSharedDocumentAdapter.ISharedDocumentAdapterListener;
-import org.eclipse.tcf.te.tcf.filesystem.ui.nls.Messages;
-import org.eclipse.ui.IEditorInput;
-import org.eclipse.ui.ide.FileStoreEditorInput;
-
-/**
- * A <code>LocalTypedElement</code> extends <code>MergeTypedElement</code> and
- * wraps an <code>FSTreeNode</code> so that it can be used as the left element
- * of a <code>MergeEditorInput</code>. It implements the interface
- * <code>IEditableContent</code> so that it is editable.
- */
-public class LocalTypedElement extends MergeTypedElement implements
- IEditableContent, IAdaptable, ISharedDocumentAdapterListener {
- // If the current edited file is dirty.
- private boolean dirty;
- // The shared document adapter
- private EditableSharedDocumentAdapter documentAdapter;
- // The shared document listener.
- private ISharedDocumentAdapterListener documentListener;
-
- /**
- * Creates a <code>LocalTypedElement</code> for the given resource.
- *
- * @param resource
- * the resource
- */
- public LocalTypedElement(FSTreeNode node) {
- super(node);
- setContent(getContent());
- dirty = false;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
- */
- @Override
- public Object getAdapter(Class adapter) {
- if (adapter == ISharedDocumentAdapter.class) {
- if (documentAdapter == null)
- documentAdapter = new EditableSharedDocumentAdapter(this);
- return documentAdapter;
- }
- return Platform.getAdapterManager().getAdapter(this, adapter);
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.compare.BufferedContent#setContent(byte[])
- */
- @Override
- public void setContent(byte[] contents) {
- dirty = true;
- super.setContent(contents);
- }
-
- /**
- * Set the document listener.
- *
- * @param documentListener
- * the document listener.
- */
- public void setDocumentListener(
- ISharedDocumentAdapterListener documentListener) {
- this.documentListener = documentListener;
- }
-
- /**
- * Return an input stream that opens that locally cached file to provide the
- * content.
- *
- * @return a buffered input stream containing the contents of this file
- * @exception CoreException
- * if the contents of this storage could not be accessed
- */
- @Override
- protected InputStream createStream() throws CoreException {
- try {
- IPath cachePath = CacheManager.getCachePath(node);
- File cacheFile = cachePath.toFile();
- return new BufferedInputStream(new FileInputStream(cacheFile));
- } catch (FileNotFoundException e) {
- IStatus error = new Status(IStatus.ERROR,
- UIPlugin.getUniqueIdentifier(), e.getMessage(), e);
- throw new CoreException(error);
- }
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.compare.IEditableContent#isEditable()
- */
- @Override
- public boolean isEditable() {
- return true;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.compare.IEditableContent#replace(org.eclipse.compare.ITypedElement, org.eclipse.compare.ITypedElement)
- */
- @Override
- public ITypedElement replace(ITypedElement dest, ITypedElement src) {
- return dest;
- }
-
- /**
- * Save the shared document for this element. The save can only be performed
- * if the element is connected to a shared document. If the element is not
- * connected, <code>false</code> is returned.
- *
- * @param overwrite
- * indicates whether overwrite should be performed while saving
- * the given element if necessary
- * @param monitor
- * a progress monitor
- * @throws CoreException
- */
- public boolean store2Document(IProgressMonitor monitor)
- throws CoreException {
- if (isConnected()) {
- IEditorInput input = documentAdapter.getDocumentKey(this);
- documentAdapter.saveDocument(input, monitor);
- return true;
- }
- return false;
- }
-
- /**
- * Judges whether the content has been changed.
- *
- * @return
- */
- public boolean isDirty() {
- return dirty
- || (documentAdapter != null && documentAdapter
- .hasBufferedContents());
- }
-
- /**
- * Set the dirty action.
- *
- * @param dirty
- * The dirty action.
- */
- public void setDirty(boolean dirty) {
- this.dirty = dirty;
- }
-
- /**
- * If the document adapter has been connected.
- *
- * @return true if it is not null and connected.
- */
- public boolean isConnected() {
- return documentAdapter != null && documentAdapter.isConnected();
- }
-
- /**
- * Return the path to the local file of this node. It is used to compute its
- * hash code and as the title of the comparison editor.
- */
- @Override
- public String toString() {
- File cacheFile = CacheManager.getCacheFile(node);
- return cacheFile.toString();
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.tcf.te.tcf.filesystem.internal.compare.EditableSharedDocumentAdapter.ISharedDocumentAdapterListener#handleDocumentConnected()
- */
- @Override
- public void handleDocumentConnected() {
- if (documentListener != null)
- documentListener.handleDocumentConnected();
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.tcf.te.tcf.filesystem.internal.compare.EditableSharedDocumentAdapter.ISharedDocumentAdapterListener#handleDocumentDeleted()
- */
- @Override
- public void handleDocumentDeleted() {
- if (documentListener != null)
- documentListener.handleDocumentDeleted();
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.tcf.te.tcf.filesystem.internal.compare.EditableSharedDocumentAdapter.ISharedDocumentAdapterListener#handleDocumentDisconnected()
- */
- @Override
- public void handleDocumentDisconnected() {
- if (documentListener != null)
- documentListener.handleDocumentDisconnected();
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.tcf.te.tcf.filesystem.internal.compare.EditableSharedDocumentAdapter.ISharedDocumentAdapterListener#handleDocumentFlushed()
- */
- @Override
- public void handleDocumentFlushed() {
- fireContentChanged();
- if (documentListener != null)
- documentListener.handleDocumentFlushed();
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.tcf.te.tcf.filesystem.internal.compare.EditableSharedDocumentAdapter.ISharedDocumentAdapterListener#handleDocumentSaved()
- */
- @Override
- public void handleDocumentSaved() {
- if (documentListener != null)
- documentListener.handleDocumentSaved();
- }
-
- /**
- * Get an editor input for this file.
- *
- * @return The editor input.
- */
- public IEditorInput getEditorInput() {
- IPath path = CacheManager.getCachePath(node);
- IFileStore fileStore = EFS.getLocalFileSystem().getStore(path);
- return new FileStoreEditorInput(fileStore);
- }
-
- /**
- * Save to its local file when the document has not been connected yet.
- *
- * @param monitor
- * The monitor that reports the progress.
- */
- public void store2Cache(IProgressMonitor monitor) throws CoreException {
- File cacheFile = CacheManager.getCacheFile(node);
- monitor.beginTask(NLS.bind(Messages.LocalTypedElement_SavingFile, cacheFile.getName()), 100);
- InputStream is = getContents();
- BufferedOutputStream bos = null;
- try {
- long total = cacheFile.length();
- bos = new BufferedOutputStream(new FileOutputStream(cacheFile));
- byte[] data = new byte[10 * 1024];
- int length;
- long current = 0;
- int currProgress = 0;
- while ((length = is.read(data)) > 0) {
- bos.write(data, 0, length);
- bos.flush();
- current += length;
- int progress = (int) (current * 100 / total);
- if (currProgress != progress) {
- monitor.worked(progress - currProgress);
- currProgress = progress;
- }
- }
- setDirty(false);
- } catch (IOException e) {
- throw new CoreException(new Status(IStatus.ERROR,
- UIPlugin.getUniqueIdentifier(), e.getMessage(), e));
- } finally {
- if (is != null)
- try {
- is.close();
- } catch (IOException ex) {
- }
- if (bos != null) {
- try {
- bos.close();
- } catch (Exception e) {
- }
- }
- // Notify the local file element that the document has changed.
- fireContentChanged();
- }
- }
-}
+/******************************************************************************* + * Copyright (c) 2011, 2014 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 java.io.BufferedInputStream; +import java.io.BufferedOutputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; + +import org.eclipse.compare.IEditableContent; +import org.eclipse.compare.ISharedDocumentAdapter; +import org.eclipse.compare.ITypedElement; +import org.eclipse.core.filesystem.EFS; +import org.eclipse.core.filesystem.IFileStore; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Platform; +import org.eclipse.core.runtime.Status; +import org.eclipse.osgi.util.NLS; +import org.eclipse.tcf.te.tcf.filesystem.core.internal.utils.CacheManager; +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.tcf.filesystem.ui.internal.compare.EditableSharedDocumentAdapter.ISharedDocumentAdapterListener; +import org.eclipse.tcf.te.tcf.filesystem.ui.nls.Messages; +import org.eclipse.ui.IEditorInput; +import org.eclipse.ui.ide.FileStoreEditorInput; + +/** + * A <code>LocalTypedElement</code> extends <code>MergeTypedElement</code> and + * wraps an <code>FSTreeNode</code> so that it can be used as the left element + * of a <code>MergeEditorInput</code>. It implements the interface + * <code>IEditableContent</code> so that it is editable. + */ +public class LocalTypedElement extends MergeTypedElement implements + IEditableContent, IAdaptable, ISharedDocumentAdapterListener { + // If the current edited file is dirty. + private boolean dirty; + // The shared document adapter + private EditableSharedDocumentAdapter documentAdapter; + // The shared document listener. + private ISharedDocumentAdapterListener documentListener; + + /** + * Creates a <code>LocalTypedElement</code> for the given resource. + * + * @param resource + * the resource + */ + public LocalTypedElement(FSTreeNode node) { + super(node); + setContent(getContent()); + dirty = false; + } + + /* (non-Javadoc) + * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class) + */ + @Override + public Object getAdapter(Class adapter) { + if (adapter == ISharedDocumentAdapter.class) { + if (documentAdapter == null) + documentAdapter = new EditableSharedDocumentAdapter(this); + return documentAdapter; + } + return Platform.getAdapterManager().getAdapter(this, adapter); + } + + /* (non-Javadoc) + * @see org.eclipse.compare.BufferedContent#setContent(byte[]) + */ + @Override + public void setContent(byte[] contents) { + dirty = true; + super.setContent(contents); + } + + /** + * Set the document listener. + * + * @param documentListener + * the document listener. + */ + public void setDocumentListener( + ISharedDocumentAdapterListener documentListener) { + this.documentListener = documentListener; + } + + /** + * Return an input stream that opens that locally cached file to provide the + * content. + * + * @return a buffered input stream containing the contents of this file + * @exception CoreException + * if the contents of this storage could not be accessed + */ + @Override + protected InputStream createStream() throws CoreException { + try { + IPath cachePath = CacheManager.getCachePath(node); + File cacheFile = cachePath.toFile(); + return new BufferedInputStream(new FileInputStream(cacheFile)); + } catch (FileNotFoundException e) { + IStatus error = new Status(IStatus.ERROR, + UIPlugin.getUniqueIdentifier(), e.getMessage(), e); + throw new CoreException(error); + } + } + + /* (non-Javadoc) + * @see org.eclipse.compare.IEditableContent#isEditable() + */ + @Override + public boolean isEditable() { + return true; + } + + /* (non-Javadoc) + * @see org.eclipse.compare.IEditableContent#replace(org.eclipse.compare.ITypedElement, org.eclipse.compare.ITypedElement) + */ + @Override + public ITypedElement replace(ITypedElement dest, ITypedElement src) { + return dest; + } + + /** + * Save the shared document for this element. The save can only be performed + * if the element is connected to a shared document. If the element is not + * connected, <code>false</code> is returned. + * + * @param overwrite + * indicates whether overwrite should be performed while saving + * the given element if necessary + * @param monitor + * a progress monitor + * @throws CoreException + */ + public boolean store2Document(IProgressMonitor monitor) + throws CoreException { + if (isConnected()) { + IEditorInput input = documentAdapter.getDocumentKey(this); + documentAdapter.saveDocument(input, monitor); + return true; + } + return false; + } + + /** + * Judges whether the content has been changed. + * + * @return + */ + public boolean isDirty() { + return dirty + || (documentAdapter != null && documentAdapter + .hasBufferedContents()); + } + + /** + * Set the dirty action. + * + * @param dirty + * The dirty action. + */ + public void setDirty(boolean dirty) { + this.dirty = dirty; + } + + /** + * If the document adapter has been connected. + * + * @return true if it is not null and connected. + */ + public boolean isConnected() { + return documentAdapter != null && documentAdapter.isConnected(); + } + + /** + * Return the path to the local file of this node. It is used to compute its + * hash code and as the title of the comparison editor. + */ + @Override + public String toString() { + File cacheFile = CacheManager.getCacheFile(node); + return cacheFile.toString(); + } + + /* (non-Javadoc) + * @see org.eclipse.tcf.te.tcf.filesystem.internal.compare.EditableSharedDocumentAdapter.ISharedDocumentAdapterListener#handleDocumentConnected() + */ + @Override + public void handleDocumentConnected() { + if (documentListener != null) + documentListener.handleDocumentConnected(); + } + + /* (non-Javadoc) + * @see org.eclipse.tcf.te.tcf.filesystem.internal.compare.EditableSharedDocumentAdapter.ISharedDocumentAdapterListener#handleDocumentDeleted() + */ + @Override + public void handleDocumentDeleted() { + if (documentListener != null) + documentListener.handleDocumentDeleted(); + } + + /* (non-Javadoc) + * @see org.eclipse.tcf.te.tcf.filesystem.internal.compare.EditableSharedDocumentAdapter.ISharedDocumentAdapterListener#handleDocumentDisconnected() + */ + @Override + public void handleDocumentDisconnected() { + if (documentListener != null) + documentListener.handleDocumentDisconnected(); + } + + /* (non-Javadoc) + * @see org.eclipse.tcf.te.tcf.filesystem.internal.compare.EditableSharedDocumentAdapter.ISharedDocumentAdapterListener#handleDocumentFlushed() + */ + @Override + public void handleDocumentFlushed() { + fireContentChanged(); + if (documentListener != null) + documentListener.handleDocumentFlushed(); + } + + /* (non-Javadoc) + * @see org.eclipse.tcf.te.tcf.filesystem.internal.compare.EditableSharedDocumentAdapter.ISharedDocumentAdapterListener#handleDocumentSaved() + */ + @Override + public void handleDocumentSaved() { + if (documentListener != null) + documentListener.handleDocumentSaved(); + } + + /** + * Get an editor input for this file. + * + * @return The editor input. + */ + public IEditorInput getEditorInput() { + IPath path = CacheManager.getCachePath(node); + IFileStore fileStore = EFS.getLocalFileSystem().getStore(path); + return new FileStoreEditorInput(fileStore); + } + + /** + * Save to its local file when the document has not been connected yet. + * + * @param monitor + * The monitor that reports the progress. + */ + public void store2Cache(IProgressMonitor monitor) throws CoreException { + File cacheFile = CacheManager.getCacheFile(node); + monitor.beginTask(NLS.bind(Messages.LocalTypedElement_SavingFile, cacheFile.getName()), 100); + InputStream is = getContents(); + BufferedOutputStream bos = null; + try { + long total = cacheFile.length(); + bos = new BufferedOutputStream(new FileOutputStream(cacheFile)); + byte[] data = new byte[10 * 1024]; + int length; + long current = 0; + int currProgress = 0; + while ((length = is.read(data)) > 0) { + bos.write(data, 0, length); + bos.flush(); + current += length; + int progress = (int) (current * 100 / total); + if (currProgress != progress) { + monitor.worked(progress - currProgress); + currProgress = progress; + } + } + setDirty(false); + } catch (IOException e) { + throw new CoreException(new Status(IStatus.ERROR, + UIPlugin.getUniqueIdentifier(), e.getMessage(), e)); + } finally { + if (is != null) + try { + is.close(); + } catch (IOException ex) { + } + if (bos != null) { + try { + bos.close(); + } catch (Exception e) { + } + } + // Notify the local file element that the document has changed. + fireContentChanged(); + } + } +} diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/compare/MergeEditorInput.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/compare/MergeEditorInput.java index b7efbfb56..65f8c5846 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/compare/MergeEditorInput.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/compare/MergeEditorInput.java @@ -1,419 +1,419 @@ -/*******************************************************************************
- * 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 java.lang.reflect.InvocationTargetException;
-
-import org.eclipse.compare.CompareConfiguration;
-import org.eclipse.compare.CompareEditorInput;
-import org.eclipse.compare.IPropertyChangeNotifier;
-import org.eclipse.compare.structuremergeviewer.Differencer;
-import org.eclipse.compare.structuremergeviewer.ICompareInput;
-import org.eclipse.compare.structuremergeviewer.ICompareInputChangeListener;
-import org.eclipse.core.runtime.Assert;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.ListenerList;
-import org.eclipse.core.runtime.SafeRunner;
-import org.eclipse.jface.resource.ImageDescriptor;
-import org.eclipse.jface.util.SafeRunnable;
-import org.eclipse.jface.viewers.Viewer;
-import org.eclipse.osgi.util.NLS;
-import org.eclipse.osgi.util.TextProcessor;
-import org.eclipse.swt.events.DisposeEvent;
-import org.eclipse.swt.events.DisposeListener;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.tcf.te.tcf.filesystem.ui.activator.UIPlugin;
-import org.eclipse.tcf.te.tcf.filesystem.ui.internal.ImageConsts;
-import org.eclipse.tcf.te.tcf.filesystem.ui.nls.Messages;
-import org.eclipse.ui.IEditorPart;
-import org.eclipse.ui.IPropertyListener;
-import org.eclipse.ui.ISaveablesSource;
-import org.eclipse.ui.IWorkbenchPage;
-import org.eclipse.ui.IWorkbenchPartConstants;
-import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.Saveable;
-/**
- * A <code>MergeEditorInput</code> is the input of a compare editor used to
- * compare the local file and the remote file in a Target Explorer file system.
- */
-public class MergeEditorInput extends CompareEditorInput implements
- ISaveablesSource, IPropertyListener, ICompareInputChangeListener {
-
- // The left element is a local file which can be editable.
- private LocalTypedElement left;
- // The right element is the remote file which is read only.
- private RemoteTypedElement right;
-
- // The active page of the current workbench.
- private final IWorkbenchPage page;
-
- // The current input change listener list.
- private final ListenerList inputChangeListeners = new ListenerList(ListenerList.IDENTITY);
- // The current saveable for the left element, i.e., the local file.
- private LocalFileSaveable saveable;
-
- /**
- * Creates a new MergeEditorInput.
- *
- * @param left
- * @param right
- * @param page
- */
- public MergeEditorInput(LocalTypedElement left, RemoteTypedElement right, IWorkbenchPage page) {
- super(new CompareConfiguration());
- this.page = page;
- this.left = left;
- this.right = right;
- configureCompare();
- }
-
- /**
- * Configure the compare configuration using the left
- * and right elements. Set the left and right label.
- * Set the editable status.
- */
- protected void configureCompare() {
- CompareConfiguration cc = getCompareConfiguration();
- cc.setLeftEditable(true);
- cc.setRightEditable(false);
-
- String name = TextProcessor.process(left.getName());
- String label = NLS.bind(Messages.MergeEditorInput_LocalFile, name);
- cc.setLeftLabel(label);
-
- name = TextProcessor.process(right.toString());
- label = NLS.bind(Messages.MergeEditorInput_RemoteFile, name);
- cc.setRightLabel(label);
- }
-
- /**
- * Returns <code>true</code> if the other object is of simulator
- * <code>MergeEditorInput</code> and both of their corresponding fLeft and
- * fRight objects are identical. The content is not considered.
- */
- @Override
- public boolean equals(Object obj) {
- if (obj == this)
- return true;
- if (obj instanceof MergeEditorInput) {
- MergeEditorInput other = (MergeEditorInput) obj;
- return other.left.equals(left) && other.right.equals(right);
- }
- return false;
- }
-
- /**
- * Override hashCode to provide identical value when
- * two MergeEditorInputs are equal to each other.
- */
- @Override
- public int hashCode() {
- return left.hashCode() + right.hashCode();
- }
-
- /**
- * Prepare the compare input of this editor input. This method is not
- * intended to be overridden of extended by subclasses (but is not final for
- * backwards compatibility reasons). The implementation of this method in
- * this class delegates the creation of the compare input to the
- * {@link #prepareCompareInput(IProgressMonitor)} method which subclasses
- * must implement.
- *
- * @see org.eclipse.compare.CompareEditorInput#prepareInput(org.eclipse.core.runtime.IProgressMonitor)
- */
- @Override
- protected Object prepareInput(IProgressMonitor monitor)
- throws InvocationTargetException, InterruptedException {
- right.cacheContents(monitor);
- MergeInput input = new MergeInput(left, right);
- setTitle(input.getName());
- return input;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.compare.CompareEditorInput#getToolTipText()
- */
- @Override
- public String getToolTipText() {
- return NLS.bind(Messages.MergeEditorInput_CompareLeftAndRight, left, right);
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.compare.CompareEditorInput#getTitle()
- */
- @Override
- public String getTitle() {
- return NLS.bind(Messages.MergeEditorInput_CompareWithLocalCache, left.getName());
- }
-
- /**
- * Override the super method to provide clear typed input.
- */
- @Override
- public MergeInput getCompareResult() {
- return (MergeInput) super.getCompareResult();
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.compare.CompareEditorInput#handleDispose()
- */
- @Override
- protected void handleDispose() {
- super.handleDispose();
- ICompareInput compareInput = getCompareResult();
- if (compareInput != null)
- compareInput.removeCompareInputChangeListener(this);
- if(getCompareResult()!=null){
- getSaveable().removePropertyListener(this);
- getSaveable().dispose();
- }
- left.discardBuffer();
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.compare.CompareEditorInput#contentsCreated()
- */
- @Override
- protected void contentsCreated() {
- super.contentsCreated();
- if (getCompareResult() != null) {
- getCompareResult().addCompareInputChangeListener(this);
- getSaveable().addPropertyListener(this);
- setDirty(getSaveable().isDirty());
- }
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.ui.IPropertyListener#propertyChanged(java.lang.Object, int)
- */
- @Override
- public void propertyChanged(Object source, int propId) {
- if (propId == IWorkbenchPartConstants.PROP_DIRTY && getCompareResult()!=null) {
- setDirty(getSaveable().isDirty());
- }
- }
-
- /**
- * Close the editor if it is not dirty. If it is still dirty, let the
- * content merge viewer handle the compare input change.
- *
- * @param checkForUnsavedChanges
- * whether to check for unsaved changes
- * @return <code>true</code> if the editor was closed (note that the close
- * may be asynchronous)
- */
- protected boolean closeEditor(boolean checkForUnsavedChanges) {
- if (isSaveNeeded() && checkForUnsavedChanges) {
- return false;
- }
- final IWorkbenchPage page = getPage();
- if (page == null)
- return false;
-
- Runnable runnable = new Runnable() {
- @Override
- public void run() {
- Shell shell = page.getWorkbenchWindow().getShell();
- if (shell == null)
- return;
-
- IEditorPart part = page.findEditor(MergeEditorInput.this);
- getPage().closeEditor(part, false);
- }
- };
- if (Display.getCurrent() != null) {
- runnable.run();
- } else {
- Shell shell = page.getWorkbenchWindow().getShell();
- if (shell == null)
- return false;
- Display display = shell.getDisplay();
- display.asyncExec(runnable);
- }
- return true;
- }
-
- /**
- * Get the current active page.
- * @return the workbench page.
- */
- IWorkbenchPage getPage() {
- if (page == null)
- return PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
- return page;
- }
-
- /**
- * Propagate the input change event to the compare input change listener list.
- */
- /* default */void propogateInputChange() {
- if (!inputChangeListeners.isEmpty()) {
- Object[] allListeners = inputChangeListeners.getListeners();
- for (int i = 0; i < allListeners.length; i++) {
- final ICompareInputChangeListener listener = (ICompareInputChangeListener) allListeners[i];
- SafeRunner.run(new SafeRunnable() {
- @Override
- public void handleException(Throwable e) {
- // Ignore exception
- }
- @Override
- public void run() throws Exception {
- listener.compareInputChanged(getCompareResult());
- }
- });
- }
- }
- }
-
- /**
- * Get the fSaveable that provides the save behavior for this compare editor
- * input. The {@link #createSaveable()} is called to create the fSaveable if
- * it does not yet exist. This method cannot be called until after the input
- * is prepared (i.e. until after the {@link #run(IProgressMonitor)} method
- * is called which will in turn will invoke
- * {@link #prepareCompareInput(IProgressMonitor)}.
- *
- * @return fSaveable that provides the save behavior for this compare editor
- * input.
- */
- public LocalFileSaveable getSaveable() {
- if (saveable == null) {
- Assert.isNotNull(getCompareResult());
- saveable = new LocalFileSaveable(getCompareResult(), this, left);
- }
- return saveable;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.ui.ISaveablesSource#getActiveSaveables()
- */
- @Override
- public Saveable[] getActiveSaveables() {
- if (getCompareResult() == null)
- return new Saveable[0];
- return new Saveable[] { getSaveable() };
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.ui.ISaveablesSource#getSaveables()
- */
- @Override
- public Saveable[] getSaveables() {
- return getActiveSaveables();
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.compare.CompareEditorInput#addCompareInputChangeListener(org.eclipse.compare.structuremergeviewer.ICompareInput, org.eclipse.compare.structuremergeviewer.ICompareInputChangeListener)
- */
- @Override
- public void addCompareInputChangeListener(ICompareInput input,
- ICompareInputChangeListener listener) {
- if (input == getCompareResult()) {
- inputChangeListeners.add(listener);
- } else {
- super.addCompareInputChangeListener(input, listener);
- }
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.compare.CompareEditorInput#removeCompareInputChangeListener(org.eclipse.compare.structuremergeviewer.ICompareInput, org.eclipse.compare.structuremergeviewer.ICompareInputChangeListener)
- */
- @Override
- public void removeCompareInputChangeListener(ICompareInput input,
- ICompareInputChangeListener listener) {
- if (input == getCompareResult()) {
- inputChangeListeners.remove(listener);
- } else {
- super.removeCompareInputChangeListener(input, listener);
- }
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.compare.CompareEditorInput#getTitleImage()
- */
- @Override
- public Image getTitleImage() {
- return UIPlugin.getImage(ImageConsts.COMPARE_EDITOR);
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.compare.CompareEditorInput#getImageDescriptor()
- */
- @Override
- public ImageDescriptor getImageDescriptor() {
- return UIPlugin.getImageDescriptor(ImageConsts.COMPARE_EDITOR);
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.compare.CompareEditorInput#findContentViewer(org.eclipse.jface.viewers.Viewer, org.eclipse.compare.structuremergeviewer.ICompareInput, org.eclipse.swt.widgets.Composite)
- */
- @Override
- public Viewer findContentViewer(Viewer oldViewer, ICompareInput input,
- Composite parent) {
- Viewer newViewer = super.findContentViewer(oldViewer, input, parent);
- boolean isNewViewer = newViewer != oldViewer;
- if (isNewViewer && newViewer instanceof IPropertyChangeNotifier && getCompareResult()!=null) {
- // Register the model for change events if appropriate
- final IPropertyChangeNotifier dsp = (IPropertyChangeNotifier) newViewer;
- dsp.addPropertyChangeListener(getSaveable());
- Control c = newViewer.getControl();
- c.addDisposeListener(new DisposeListener() {
- @Override
- public void widgetDisposed(DisposeEvent e) {
- dsp.removePropertyChangeListener(getSaveable());
- }
- });
- }
- return newViewer;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.compare.CompareEditorInput#canRunAsJob()
- */
- @Override
- public boolean canRunAsJob() {
- return true;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.compare.CompareEditorInput#isDirty()
- */
- @Override
- public boolean isDirty() {
- if (saveable != null)
- return saveable.isDirty();
- return super.isDirty();
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.compare.structuremergeviewer.ICompareInputChangeListener#compareInputChanged(org.eclipse.compare.structuremergeviewer.ICompareInput)
- */
- @Override
- public void compareInputChanged(ICompareInput source) {
- if (source == getCompareResult()) {
- boolean closed = false;
- if (source.getKind() == Differencer.NO_CHANGE) {
- closed = closeEditor(true);
- }
- if (!closed) {
- // The editor was closed either because the compare
- // input still has changes or because the editor input
- // is dirty. In either case, fire the changes
- // to the registered listeners
- propogateInputChange();
- }
- }
- }
-}
+/******************************************************************************* + * Copyright (c) 2011, 2014 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 java.lang.reflect.InvocationTargetException; + +import org.eclipse.compare.CompareConfiguration; +import org.eclipse.compare.CompareEditorInput; +import org.eclipse.compare.IPropertyChangeNotifier; +import org.eclipse.compare.structuremergeviewer.Differencer; +import org.eclipse.compare.structuremergeviewer.ICompareInput; +import org.eclipse.compare.structuremergeviewer.ICompareInputChangeListener; +import org.eclipse.core.runtime.Assert; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.ListenerList; +import org.eclipse.core.runtime.SafeRunner; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.util.SafeRunnable; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.osgi.util.NLS; +import org.eclipse.osgi.util.TextProcessor; +import org.eclipse.swt.events.DisposeEvent; +import org.eclipse.swt.events.DisposeListener; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.tcf.te.tcf.filesystem.ui.activator.UIPlugin; +import org.eclipse.tcf.te.tcf.filesystem.ui.internal.ImageConsts; +import org.eclipse.tcf.te.tcf.filesystem.ui.nls.Messages; +import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.IPropertyListener; +import org.eclipse.ui.ISaveablesSource; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.IWorkbenchPartConstants; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.Saveable; +/** + * A <code>MergeEditorInput</code> is the input of a compare editor used to + * compare the local file and the remote file in a Target Explorer file system. + */ +public class MergeEditorInput extends CompareEditorInput implements + ISaveablesSource, IPropertyListener, ICompareInputChangeListener { + + // The left element is a local file which can be editable. + private LocalTypedElement left; + // The right element is the remote file which is read only. + private RemoteTypedElement right; + + // The active page of the current workbench. + private final IWorkbenchPage page; + + // The current input change listener list. + private final ListenerList inputChangeListeners = new ListenerList(ListenerList.IDENTITY); + // The current saveable for the left element, i.e., the local file. + private LocalFileSaveable saveable; + + /** + * Creates a new MergeEditorInput. + * + * @param left + * @param right + * @param page + */ + public MergeEditorInput(LocalTypedElement left, RemoteTypedElement right, IWorkbenchPage page) { + super(new CompareConfiguration()); + this.page = page; + this.left = left; + this.right = right; + configureCompare(); + } + + /** + * Configure the compare configuration using the left + * and right elements. Set the left and right label. + * Set the editable status. + */ + protected void configureCompare() { + CompareConfiguration cc = getCompareConfiguration(); + cc.setLeftEditable(true); + cc.setRightEditable(false); + + String name = TextProcessor.process(left.getName()); + String label = NLS.bind(Messages.MergeEditorInput_LocalFile, name); + cc.setLeftLabel(label); + + name = TextProcessor.process(right.toString()); + label = NLS.bind(Messages.MergeEditorInput_RemoteFile, name); + cc.setRightLabel(label); + } + + /** + * Returns <code>true</code> if the other object is of simulator + * <code>MergeEditorInput</code> and both of their corresponding fLeft and + * fRight objects are identical. The content is not considered. + */ + @Override + public boolean equals(Object obj) { + if (obj == this) + return true; + if (obj instanceof MergeEditorInput) { + MergeEditorInput other = (MergeEditorInput) obj; + return other.left.equals(left) && other.right.equals(right); + } + return false; + } + + /** + * Override hashCode to provide identical value when + * two MergeEditorInputs are equal to each other. + */ + @Override + public int hashCode() { + return left.hashCode() + right.hashCode(); + } + + /** + * Prepare the compare input of this editor input. This method is not + * intended to be overridden of extended by subclasses (but is not final for + * backwards compatibility reasons). The implementation of this method in + * this class delegates the creation of the compare input to the + * {@link #prepareCompareInput(IProgressMonitor)} method which subclasses + * must implement. + * + * @see org.eclipse.compare.CompareEditorInput#prepareInput(org.eclipse.core.runtime.IProgressMonitor) + */ + @Override + protected Object prepareInput(IProgressMonitor monitor) + throws InvocationTargetException, InterruptedException { + right.cacheContents(monitor); + MergeInput input = new MergeInput(left, right); + setTitle(input.getName()); + return input; + } + + /* (non-Javadoc) + * @see org.eclipse.compare.CompareEditorInput#getToolTipText() + */ + @Override + public String getToolTipText() { + return NLS.bind(Messages.MergeEditorInput_CompareLeftAndRight, left, right); + } + + /* (non-Javadoc) + * @see org.eclipse.compare.CompareEditorInput#getTitle() + */ + @Override + public String getTitle() { + return NLS.bind(Messages.MergeEditorInput_CompareWithLocalCache, left.getName()); + } + + /** + * Override the super method to provide clear typed input. + */ + @Override + public MergeInput getCompareResult() { + return (MergeInput) super.getCompareResult(); + } + + /* (non-Javadoc) + * @see org.eclipse.compare.CompareEditorInput#handleDispose() + */ + @Override + protected void handleDispose() { + super.handleDispose(); + ICompareInput compareInput = getCompareResult(); + if (compareInput != null) + compareInput.removeCompareInputChangeListener(this); + if(getCompareResult()!=null){ + getSaveable().removePropertyListener(this); + getSaveable().dispose(); + } + left.discardBuffer(); + } + + /* (non-Javadoc) + * @see org.eclipse.compare.CompareEditorInput#contentsCreated() + */ + @Override + protected void contentsCreated() { + super.contentsCreated(); + if (getCompareResult() != null) { + getCompareResult().addCompareInputChangeListener(this); + getSaveable().addPropertyListener(this); + setDirty(getSaveable().isDirty()); + } + } + + /* (non-Javadoc) + * @see org.eclipse.ui.IPropertyListener#propertyChanged(java.lang.Object, int) + */ + @Override + public void propertyChanged(Object source, int propId) { + if (propId == IWorkbenchPartConstants.PROP_DIRTY && getCompareResult()!=null) { + setDirty(getSaveable().isDirty()); + } + } + + /** + * Close the editor if it is not dirty. If it is still dirty, let the + * content merge viewer handle the compare input change. + * + * @param checkForUnsavedChanges + * whether to check for unsaved changes + * @return <code>true</code> if the editor was closed (note that the close + * may be asynchronous) + */ + protected boolean closeEditor(boolean checkForUnsavedChanges) { + if (isSaveNeeded() && checkForUnsavedChanges) { + return false; + } + final IWorkbenchPage page = getPage(); + if (page == null) + return false; + + Runnable runnable = new Runnable() { + @Override + public void run() { + Shell shell = page.getWorkbenchWindow().getShell(); + if (shell == null) + return; + + IEditorPart part = page.findEditor(MergeEditorInput.this); + getPage().closeEditor(part, false); + } + }; + if (Display.getCurrent() != null) { + runnable.run(); + } else { + Shell shell = page.getWorkbenchWindow().getShell(); + if (shell == null) + return false; + Display display = shell.getDisplay(); + display.asyncExec(runnable); + } + return true; + } + + /** + * Get the current active page. + * @return the workbench page. + */ + IWorkbenchPage getPage() { + if (page == null) + return PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); + return page; + } + + /** + * Propagate the input change event to the compare input change listener list. + */ + /* default */void propogateInputChange() { + if (!inputChangeListeners.isEmpty()) { + Object[] allListeners = inputChangeListeners.getListeners(); + for (int i = 0; i < allListeners.length; i++) { + final ICompareInputChangeListener listener = (ICompareInputChangeListener) allListeners[i]; + SafeRunner.run(new SafeRunnable() { + @Override + public void handleException(Throwable e) { + // Ignore exception + } + @Override + public void run() throws Exception { + listener.compareInputChanged(getCompareResult()); + } + }); + } + } + } + + /** + * Get the fSaveable that provides the save behavior for this compare editor + * input. The {@link #createSaveable()} is called to create the fSaveable if + * it does not yet exist. This method cannot be called until after the input + * is prepared (i.e. until after the {@link #run(IProgressMonitor)} method + * is called which will in turn will invoke + * {@link #prepareCompareInput(IProgressMonitor)}. + * + * @return fSaveable that provides the save behavior for this compare editor + * input. + */ + public LocalFileSaveable getSaveable() { + if (saveable == null) { + Assert.isNotNull(getCompareResult()); + saveable = new LocalFileSaveable(getCompareResult(), this, left); + } + return saveable; + } + + /* (non-Javadoc) + * @see org.eclipse.ui.ISaveablesSource#getActiveSaveables() + */ + @Override + public Saveable[] getActiveSaveables() { + if (getCompareResult() == null) + return new Saveable[0]; + return new Saveable[] { getSaveable() }; + } + + /* (non-Javadoc) + * @see org.eclipse.ui.ISaveablesSource#getSaveables() + */ + @Override + public Saveable[] getSaveables() { + return getActiveSaveables(); + } + + /* (non-Javadoc) + * @see org.eclipse.compare.CompareEditorInput#addCompareInputChangeListener(org.eclipse.compare.structuremergeviewer.ICompareInput, org.eclipse.compare.structuremergeviewer.ICompareInputChangeListener) + */ + @Override + public void addCompareInputChangeListener(ICompareInput input, + ICompareInputChangeListener listener) { + if (input == getCompareResult()) { + inputChangeListeners.add(listener); + } else { + super.addCompareInputChangeListener(input, listener); + } + } + + /* (non-Javadoc) + * @see org.eclipse.compare.CompareEditorInput#removeCompareInputChangeListener(org.eclipse.compare.structuremergeviewer.ICompareInput, org.eclipse.compare.structuremergeviewer.ICompareInputChangeListener) + */ + @Override + public void removeCompareInputChangeListener(ICompareInput input, + ICompareInputChangeListener listener) { + if (input == getCompareResult()) { + inputChangeListeners.remove(listener); + } else { + super.removeCompareInputChangeListener(input, listener); + } + } + + /* (non-Javadoc) + * @see org.eclipse.compare.CompareEditorInput#getTitleImage() + */ + @Override + public Image getTitleImage() { + return UIPlugin.getImage(ImageConsts.COMPARE_EDITOR); + } + + /* (non-Javadoc) + * @see org.eclipse.compare.CompareEditorInput#getImageDescriptor() + */ + @Override + public ImageDescriptor getImageDescriptor() { + return UIPlugin.getImageDescriptor(ImageConsts.COMPARE_EDITOR); + } + + /* (non-Javadoc) + * @see org.eclipse.compare.CompareEditorInput#findContentViewer(org.eclipse.jface.viewers.Viewer, org.eclipse.compare.structuremergeviewer.ICompareInput, org.eclipse.swt.widgets.Composite) + */ + @Override + public Viewer findContentViewer(Viewer oldViewer, ICompareInput input, + Composite parent) { + Viewer newViewer = super.findContentViewer(oldViewer, input, parent); + boolean isNewViewer = newViewer != oldViewer; + if (isNewViewer && newViewer instanceof IPropertyChangeNotifier && getCompareResult()!=null) { + // Register the model for change events if appropriate + final IPropertyChangeNotifier dsp = (IPropertyChangeNotifier) newViewer; + dsp.addPropertyChangeListener(getSaveable()); + Control c = newViewer.getControl(); + c.addDisposeListener(new DisposeListener() { + @Override + public void widgetDisposed(DisposeEvent e) { + dsp.removePropertyChangeListener(getSaveable()); + } + }); + } + return newViewer; + } + + /* (non-Javadoc) + * @see org.eclipse.compare.CompareEditorInput#canRunAsJob() + */ + @Override + public boolean canRunAsJob() { + return true; + } + + /* (non-Javadoc) + * @see org.eclipse.compare.CompareEditorInput#isDirty() + */ + @Override + public boolean isDirty() { + if (saveable != null) + return saveable.isDirty(); + return super.isDirty(); + } + + /* (non-Javadoc) + * @see org.eclipse.compare.structuremergeviewer.ICompareInputChangeListener#compareInputChanged(org.eclipse.compare.structuremergeviewer.ICompareInput) + */ + @Override + public void compareInputChanged(ICompareInput source) { + if (source == getCompareResult()) { + boolean closed = false; + if (source.getKind() == Differencer.NO_CHANGE) { + closed = closeEditor(true); + } + if (!closed) { + // The editor was closed either because the compare + // input still has changes or because the editor input + // is dirty. In either case, fire the changes + // to the registered listeners + propogateInputChange(); + } + } + } +} diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/dnd/CommonDnD.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/dnd/CommonDnD.java index e56e8369a..2cf77ec4b 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/dnd/CommonDnD.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/dnd/CommonDnD.java @@ -1,408 +1,408 @@ -/*******************************************************************************
- * 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.internal.dnd;
-
-import java.io.File;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.jface.util.LocalSelectionTransfer;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.viewers.StructuredSelection;
-import org.eclipse.jface.viewers.TreeViewer;
-import org.eclipse.osgi.util.NLS;
-import org.eclipse.swt.dnd.DND;
-import org.eclipse.swt.dnd.DragSourceEvent;
-import org.eclipse.swt.dnd.FileTransfer;
-import org.eclipse.swt.dnd.TransferData;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.tcf.te.runtime.callback.Callback;
-import org.eclipse.tcf.te.runtime.interfaces.callback.ICallback;
-import org.eclipse.tcf.te.tcf.filesystem.core.interfaces.IConfirmCallback;
-import org.eclipse.tcf.te.tcf.filesystem.core.interfaces.IOperation;
-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.OpCopy;
-import org.eclipse.tcf.te.tcf.filesystem.core.internal.operations.OpMove;
-import org.eclipse.tcf.te.tcf.filesystem.core.internal.operations.OpRefresh;
-import org.eclipse.tcf.te.tcf.filesystem.core.internal.operations.OpUpload;
-import org.eclipse.tcf.te.tcf.filesystem.core.internal.utils.CacheManager;
-import org.eclipse.tcf.te.tcf.filesystem.core.model.FSModel;
-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.tcf.filesystem.ui.internal.ImageConsts;
-import org.eclipse.tcf.te.tcf.filesystem.ui.internal.handlers.MoveCopyCallback;
-import org.eclipse.tcf.te.tcf.filesystem.ui.internal.operations.UiExecutor;
-import org.eclipse.tcf.te.tcf.filesystem.ui.nls.Messages;
-import org.eclipse.ui.PlatformUI;
-/**
- * Common DnD operations shared by File Explorer and Target Explorer.
- */
-public class CommonDnD implements IConfirmCallback {
-
- /**
- * If the current selection is draggable.
- *
- * @param selection The currently selected nodes.
- * @return true if it is draggable.
- */
- public boolean isDraggable(IStructuredSelection selection) {
- if (selection.isEmpty()) {
- return false;
- }
- Object[] objects = selection.toArray();
- for (Object object : objects) {
- if (!isDraggableObject(object)) {
- return false;
- }
- }
- return true;
- }
-
- /**
- * If the specified object is a draggable element.
- *
- * @param object The object to be dragged.
- * @return true if it is draggable.
- */
- private boolean isDraggableObject(Object object) {
- if (object instanceof FSTreeNode) {
- FSTreeNode node = (FSTreeNode) object;
- return !node.isRoot() && (node.isWindowsNode() && !node.isReadOnly() || !node.isWindowsNode() && node.isWritable());
- }
- return false;
- }
-
- /**
- * Perform the drop operation over dragged files to the specified target folder.
- *
- * @param viewer the tree viewer to be refreshed after dragging.
- * @param files The files being dropped.
- * @param operations the current dnd operations.
- * @param target the target folder the files to be dropped to.
- * @return true if the dropping is successful.
- */
- public boolean dropFiles(TreeViewer viewer, String[] files, int operations, FSTreeNode target) {
- IOpExecutor executor = null;
- if ((operations & DND.DROP_MOVE) != 0) {
- String question;
- if (files.length == 1) {
- question = NLS.bind(Messages.FSDropTargetListener_MovingWarningSingle, files[0]);
- }
- else {
- question = NLS.bind(Messages.FSDropTargetListener_MovingWarningMultiple, Integer.valueOf(files.length));
- }
- Shell parent = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
- if (MessageDialog.openQuestion(parent, Messages.FSDropTargetListener_ConfirmMoveTitle, question)) {
- ICallback callback = getMoveCallback(viewer, files, target);
- executor = new UiExecutor(callback);
- }
- }
- else if ((operations & DND.DROP_COPY) != 0) {
- ICallback callback = getCopyCallback(viewer, files, target);
- executor = new UiExecutor(callback);
- }
- if (executor != null) {
- IStatus status = executor.execute(new OpUpload(files, target, this));
- return status != null && status.isOK();
- }
- return false;
- }
-
- /**
- * Get the callback that refresh and select the files being dragged when the dragging gesture is
- * copying.
- *
- * @param viewer the tree viewer to be refreshed after dragging.
- * @param files The files being dragged.
- * @param target The target folder to drag the files to.
- * @return callback that handles refreshing and selection.
- */
- private ICallback getCopyCallback(final TreeViewer viewer, final String[] files, final FSTreeNode target) {
- return new Callback() {
- @Override
- protected void internalDone(Object caller, IStatus status) {
- if (status.isOK()) {
- IOpExecutor executor = new JobExecutor(getSelectionCallback(viewer, files, target));
- executor.execute(new OpRefresh(target));
- }
- }
- };
- }
-
- /**
- * Get the callback that delete the dragged source files, refresh and select the files being
- * dragged when the dragging gesture is moving.
- *
- * @param viewer the tree viewer to be refreshed after dragging.
- * @param files The files being dragged.
- * @param target The target folder to drag the files to.
- * @return callback that handles deletion, refreshing and selection.
- */
- private ICallback getMoveCallback(final TreeViewer viewer, final String[] files, final FSTreeNode target) {
- return new Callback() {
- @Override
- protected void internalDone(Object caller, IStatus status) {
- if (status.isOK()) {
- boolean successful = true;
- for (String path : files) {
- File file = new File(path);
- successful &= file.delete();
- }
- if (successful) {
- FSTreeNode root = FSModel.getFSModel(target.peerNode).getRoot();
- IOpExecutor executor = new JobExecutor(getSelectionCallback(viewer, files, target));
- executor.execute(new OpRefresh(root));
- }
- }
- }
- };
- }
-
- /**
- * Get the callback that refresh the files being dragged after moving or copying.
- *
- * @param viewer the tree viewer to be refreshed after dragging.
- * @param paths The paths of the files being dragged.
- * @param target The target folder to drag the files to.
- * @return callback that handles refreshing and selection.
- */
- ICallback getSelectionCallback(final TreeViewer viewer, final String[] paths, final FSTreeNode target) {
- return new Callback() {
- @Override
- protected void internalDone(Object caller, IStatus status) {
- if(status.isOK()) {
- List<FSTreeNode> nodes = new ArrayList<FSTreeNode>();
- List<FSTreeNode> children = target.getChildren();
- for (String path : paths) {
- File file = new File(path);
- String name = file.getName();
- for (FSTreeNode child : children) {
- if (name.equals(child.name)) {
- nodes.add(child);
- break;
- }
- }
- }
- if (viewer != null) {
- updateViewer(viewer, target, nodes);
- }
- }
- }
- };
- }
-
- /**
- * Update the tree viewer after DnD and select the nodes that being dropped.
- *
- * @param viewer The tree viewer in which the DnD takes place.
- * @param target The target node that the drop operation happens.
- * @param nodes The nodes that are being dropped.
- */
- protected void updateViewer(final TreeViewer viewer, final FSTreeNode target, final List<FSTreeNode> nodes) {
- if (Display.getCurrent() != null) {
- viewer.refresh(target);
- IStructuredSelection selection = new StructuredSelection(nodes.toArray());
- viewer.setSelection(selection, true);
- }
- else {
- PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable(){
- @Override
- public void run() {
- updateViewer(viewer, target, nodes);
- }});
- }
- }
-
- /**
- * Perform the drop operation over dragged selection.
- *
- * @param aTarget the target Object to be moved to.
- * @param operations the current dnd operations.
- * @param selection The local selection being dropped.
- * @return true if the dropping is successful.
- */
- public boolean dropLocalSelection(FSTreeNode target, int operations, IStructuredSelection selection) {
- List<FSTreeNode> nodes = selection.toList();
- IOpExecutor executor = null;
- IOperation operation = null;
- if ((operations & DND.DROP_MOVE) != 0) {
- operation = new OpMove(nodes, target, new MoveCopyCallback());
- executor = new UiExecutor(new Callback(){
- @Override
- protected void internalDone(Object caller, IStatus status) {
- UIPlugin.getClipboard().clear();
- }
- });
- }
- else if ((operations & DND.DROP_COPY) != 0) {
- FSTreeNode dest = getCopyDestination(target, nodes);
- boolean cpPerm = UIPlugin.isCopyPermission();
- boolean cpOwn = UIPlugin.isCopyOwnership();
- operation = new OpCopy(nodes, dest, cpPerm, cpOwn, new MoveCopyCallback());
- executor = new UiExecutor();
- }
- if (operation != null && executor != null) {
- IStatus status = executor.execute(operation);
- return status != null && status.isOK();
- }
- return false;
- }
-
- /**
- * Return an appropriate destination directory for copying according to the specified hovered
- * node. If the hovered node is a file, then return its parent directory. If the hovered node is
- * a directory, then return its self if it is not a node being copied. Return its parent
- * directory if it is a node being copied.
- *
- * @param hovered
- * @param nodes
- * @return
- */
- private FSTreeNode getCopyDestination(FSTreeNode hovered, List<FSTreeNode> nodes) {
- if (hovered.isFile()) {
- return hovered.getParent();
- }
- else if (hovered.isDirectory()) {
- for (FSTreeNode node : nodes) {
- if (node == hovered) {
- return hovered.getParent();
- }
- }
- }
- return hovered;
- }
-
- /**
- * Validate dropping when the elements being dragged are files.
- *
- * @param target The target object.
- * @param operation The DnD operation.
- * @param transferType The transfered data simulator.
- * @return true if it is valid for dropping.
- */
- public boolean validateFilesDrop(Object target, int operation, TransferData transferType) {
- FileTransfer transfer = FileTransfer.getInstance();
- String[] elements = (String[]) transfer.nativeToJava(transferType);
- if (elements.length > 0) {
- boolean moving = (operation & DND.DROP_MOVE) != 0;
- boolean copying = (operation & DND.DROP_COPY) != 0;
- FSTreeNode hovered = (FSTreeNode) target;
- if (hovered.isFile() && copying) {
- hovered = hovered.getParent();
- }
- return hovered.isDirectory() && hovered.isWritable() && (moving || copying);
- }
- return false;
- }
-
- /**
- * Validate dropping when the elements being dragged are local selection.
- *
- * @param target The target object.
- * @param operation The DnD operation.
- * @param transferType The transfered data simulator.
- * @return true if it is valid for dropping.
- */
- public boolean validateLocalSelectionDrop(Object target, int operation, TransferData transferType) {
- FSTreeNode hovered = (FSTreeNode) target;
- LocalSelectionTransfer transfer = LocalSelectionTransfer.getTransfer();
- IStructuredSelection selection = (IStructuredSelection) transfer.getSelection();
- List<FSTreeNode> nodes = selection.toList();
- boolean moving = (operation & DND.DROP_MOVE) != 0;
- boolean copying = (operation & DND.DROP_COPY) != 0;
- if (hovered.isDirectory() && hovered.isWritable() && (moving || copying)) {
- FSTreeNode head = nodes.get(0);
- String hid = head.peerNode.getPeerId();
- String tid = hovered.peerNode.getPeerId();
- if (hid.equals(tid)) {
- for (FSTreeNode node : nodes) {
- if (moving && node == hovered || node.isAncestorOf(hovered)) {
- return false;
- }
- }
- return true;
- }
- }
- else if (hovered.isFile() && copying) {
- hovered = hovered.getParent();
- return validateLocalSelectionDrop(hovered, operation, transferType);
- }
- return false;
- }
-
- /*
- * (non-Javadoc)
- * @see org.eclipse.tcf.te.tcf.filesystem.interfaces.IConfirmCallback#requires(java.lang.Object)
- */
- @Override
- public boolean requires(Object object) {
- return true;
- }
-
- /*
- * (non-Javadoc)
- * @see org.eclipse.tcf.te.tcf.filesystem.interfaces.IConfirmCallback#confirms(java.lang.Object)
- */
- @Override
- public int confirms(Object object) {
- final int[] results = new int[1];
- final File file = (File) object;
- Display display = PlatformUI.getWorkbench().getDisplay();
- display.syncExec(new Runnable() {
- @Override
- public void run() {
- Shell parent = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
- String title = Messages.FSUpload_OverwriteTitle;
- String message = NLS.bind(Messages.FSUpload_OverwriteConfirmation, file.getName());
- final Image titleImage = UIPlugin.getImage(ImageConsts.DELETE_READONLY_CONFIRM);
- MessageDialog qDialog = new MessageDialog(parent, title, null, message,
- MessageDialog.QUESTION, new String[] {Messages.FSUpload_Yes,
- Messages.FSUpload_YesToAll, Messages.FSUpload_No, Messages.FSUpload_Cancel}, 0) {
- @Override
- public Image getQuestionImage() {
- return titleImage;
- }
- };
- results[0] = qDialog.open();
- }
- });
- return results[0];
- }
-
- /*
- * (non-Javadoc)
- * @see org.eclipse.swt.dnd.DragSourceListener#dragSetData(org.eclipse.swt.dnd.DragSourceEvent)
- */
- public boolean setDragData(DragSourceEvent anEvent) {
- if (LocalSelectionTransfer.getTransfer().isSupportedType(anEvent.dataType)) {
- anEvent.data = LocalSelectionTransfer.getTransfer().getSelection();
- return true;
- }
- else if (FileTransfer.getInstance().isSupportedType(anEvent.dataType)) {
- IStructuredSelection selection = (IStructuredSelection) LocalSelectionTransfer.getTransfer().getSelection();
- List<FSTreeNode> nodes = selection.toList();
- List<String> paths = new ArrayList<String>();
- for(FSTreeNode node : nodes) {
- File file = CacheManager.getCacheFile(node);
- if(file.exists()) {
- paths.add(file.getAbsolutePath());
- }
- }
- if (!paths.isEmpty()) anEvent.data = paths.toArray(new String[paths.size()]);
- return !paths.isEmpty();
- }
- return false;
- }
-}
+/******************************************************************************* + * Copyright (c) 2011, 2014 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.dnd; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.core.runtime.IStatus; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.jface.util.LocalSelectionTransfer; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.jface.viewers.TreeViewer; +import org.eclipse.osgi.util.NLS; +import org.eclipse.swt.dnd.DND; +import org.eclipse.swt.dnd.DragSourceEvent; +import org.eclipse.swt.dnd.FileTransfer; +import org.eclipse.swt.dnd.TransferData; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.tcf.te.runtime.callback.Callback; +import org.eclipse.tcf.te.runtime.interfaces.callback.ICallback; +import org.eclipse.tcf.te.tcf.filesystem.core.interfaces.IConfirmCallback; +import org.eclipse.tcf.te.tcf.filesystem.core.interfaces.IOperation; +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.OpCopy; +import org.eclipse.tcf.te.tcf.filesystem.core.internal.operations.OpMove; +import org.eclipse.tcf.te.tcf.filesystem.core.internal.operations.OpRefresh; +import org.eclipse.tcf.te.tcf.filesystem.core.internal.operations.OpUpload; +import org.eclipse.tcf.te.tcf.filesystem.core.internal.utils.CacheManager; +import org.eclipse.tcf.te.tcf.filesystem.core.model.FSModel; +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.tcf.filesystem.ui.internal.ImageConsts; +import org.eclipse.tcf.te.tcf.filesystem.ui.internal.handlers.MoveCopyCallback; +import org.eclipse.tcf.te.tcf.filesystem.ui.internal.operations.UiExecutor; +import org.eclipse.tcf.te.tcf.filesystem.ui.nls.Messages; +import org.eclipse.ui.PlatformUI; +/** + * Common DnD operations shared by File Explorer and Target Explorer. + */ +public class CommonDnD implements IConfirmCallback { + + /** + * If the current selection is draggable. + * + * @param selection The currently selected nodes. + * @return true if it is draggable. + */ + public boolean isDraggable(IStructuredSelection selection) { + if (selection.isEmpty()) { + return false; + } + Object[] objects = selection.toArray(); + for (Object object : objects) { + if (!isDraggableObject(object)) { + return false; + } + } + return true; + } + + /** + * If the specified object is a draggable element. + * + * @param object The object to be dragged. + * @return true if it is draggable. + */ + private boolean isDraggableObject(Object object) { + if (object instanceof FSTreeNode) { + FSTreeNode node = (FSTreeNode) object; + return !node.isRoot() && (node.isWindowsNode() && !node.isReadOnly() || !node.isWindowsNode() && node.isWritable()); + } + return false; + } + + /** + * Perform the drop operation over dragged files to the specified target folder. + * + * @param viewer the tree viewer to be refreshed after dragging. + * @param files The files being dropped. + * @param operations the current dnd operations. + * @param target the target folder the files to be dropped to. + * @return true if the dropping is successful. + */ + public boolean dropFiles(TreeViewer viewer, String[] files, int operations, FSTreeNode target) { + IOpExecutor executor = null; + if ((operations & DND.DROP_MOVE) != 0) { + String question; + if (files.length == 1) { + question = NLS.bind(Messages.FSDropTargetListener_MovingWarningSingle, files[0]); + } + else { + question = NLS.bind(Messages.FSDropTargetListener_MovingWarningMultiple, Integer.valueOf(files.length)); + } + Shell parent = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); + if (MessageDialog.openQuestion(parent, Messages.FSDropTargetListener_ConfirmMoveTitle, question)) { + ICallback callback = getMoveCallback(viewer, files, target); + executor = new UiExecutor(callback); + } + } + else if ((operations & DND.DROP_COPY) != 0) { + ICallback callback = getCopyCallback(viewer, files, target); + executor = new UiExecutor(callback); + } + if (executor != null) { + IStatus status = executor.execute(new OpUpload(files, target, this)); + return status != null && status.isOK(); + } + return false; + } + + /** + * Get the callback that refresh and select the files being dragged when the dragging gesture is + * copying. + * + * @param viewer the tree viewer to be refreshed after dragging. + * @param files The files being dragged. + * @param target The target folder to drag the files to. + * @return callback that handles refreshing and selection. + */ + private ICallback getCopyCallback(final TreeViewer viewer, final String[] files, final FSTreeNode target) { + return new Callback() { + @Override + protected void internalDone(Object caller, IStatus status) { + if (status.isOK()) { + IOpExecutor executor = new JobExecutor(getSelectionCallback(viewer, files, target)); + executor.execute(new OpRefresh(target)); + } + } + }; + } + + /** + * Get the callback that delete the dragged source files, refresh and select the files being + * dragged when the dragging gesture is moving. + * + * @param viewer the tree viewer to be refreshed after dragging. + * @param files The files being dragged. + * @param target The target folder to drag the files to. + * @return callback that handles deletion, refreshing and selection. + */ + private ICallback getMoveCallback(final TreeViewer viewer, final String[] files, final FSTreeNode target) { + return new Callback() { + @Override + protected void internalDone(Object caller, IStatus status) { + if (status.isOK()) { + boolean successful = true; + for (String path : files) { + File file = new File(path); + successful &= file.delete(); + } + if (successful) { + FSTreeNode root = FSModel.getFSModel(target.peerNode).getRoot(); + IOpExecutor executor = new JobExecutor(getSelectionCallback(viewer, files, target)); + executor.execute(new OpRefresh(root)); + } + } + } + }; + } + + /** + * Get the callback that refresh the files being dragged after moving or copying. + * + * @param viewer the tree viewer to be refreshed after dragging. + * @param paths The paths of the files being dragged. + * @param target The target folder to drag the files to. + * @return callback that handles refreshing and selection. + */ + ICallback getSelectionCallback(final TreeViewer viewer, final String[] paths, final FSTreeNode target) { + return new Callback() { + @Override + protected void internalDone(Object caller, IStatus status) { + if(status.isOK()) { + List<FSTreeNode> nodes = new ArrayList<FSTreeNode>(); + List<FSTreeNode> children = target.getChildren(); + for (String path : paths) { + File file = new File(path); + String name = file.getName(); + for (FSTreeNode child : children) { + if (name.equals(child.name)) { + nodes.add(child); + break; + } + } + } + if (viewer != null) { + updateViewer(viewer, target, nodes); + } + } + } + }; + } + + /** + * Update the tree viewer after DnD and select the nodes that being dropped. + * + * @param viewer The tree viewer in which the DnD takes place. + * @param target The target node that the drop operation happens. + * @param nodes The nodes that are being dropped. + */ + protected void updateViewer(final TreeViewer viewer, final FSTreeNode target, final List<FSTreeNode> nodes) { + if (Display.getCurrent() != null) { + viewer.refresh(target); + IStructuredSelection selection = new StructuredSelection(nodes.toArray()); + viewer.setSelection(selection, true); + } + else { + PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable(){ + @Override + public void run() { + updateViewer(viewer, target, nodes); + }}); + } + } + + /** + * Perform the drop operation over dragged selection. + * + * @param aTarget the target Object to be moved to. + * @param operations the current dnd operations. + * @param selection The local selection being dropped. + * @return true if the dropping is successful. + */ + public boolean dropLocalSelection(FSTreeNode target, int operations, IStructuredSelection selection) { + List<FSTreeNode> nodes = selection.toList(); + IOpExecutor executor = null; + IOperation operation = null; + if ((operations & DND.DROP_MOVE) != 0) { + operation = new OpMove(nodes, target, new MoveCopyCallback()); + executor = new UiExecutor(new Callback(){ + @Override + protected void internalDone(Object caller, IStatus status) { + UIPlugin.getClipboard().clear(); + } + }); + } + else if ((operations & DND.DROP_COPY) != 0) { + FSTreeNode dest = getCopyDestination(target, nodes); + boolean cpPerm = UIPlugin.isCopyPermission(); + boolean cpOwn = UIPlugin.isCopyOwnership(); + operation = new OpCopy(nodes, dest, cpPerm, cpOwn, new MoveCopyCallback()); + executor = new UiExecutor(); + } + if (operation != null && executor != null) { + IStatus status = executor.execute(operation); + return status != null && status.isOK(); + } + return false; + } + + /** + * Return an appropriate destination directory for copying according to the specified hovered + * node. If the hovered node is a file, then return its parent directory. If the hovered node is + * a directory, then return its self if it is not a node being copied. Return its parent + * directory if it is a node being copied. + * + * @param hovered + * @param nodes + * @return + */ + private FSTreeNode getCopyDestination(FSTreeNode hovered, List<FSTreeNode> nodes) { + if (hovered.isFile()) { + return hovered.getParent(); + } + else if (hovered.isDirectory()) { + for (FSTreeNode node : nodes) { + if (node == hovered) { + return hovered.getParent(); + } + } + } + return hovered; + } + + /** + * Validate dropping when the elements being dragged are files. + * + * @param target The target object. + * @param operation The DnD operation. + * @param transferType The transfered data simulator. + * @return true if it is valid for dropping. + */ + public boolean validateFilesDrop(Object target, int operation, TransferData transferType) { + FileTransfer transfer = FileTransfer.getInstance(); + String[] elements = (String[]) transfer.nativeToJava(transferType); + if (elements.length > 0) { + boolean moving = (operation & DND.DROP_MOVE) != 0; + boolean copying = (operation & DND.DROP_COPY) != 0; + FSTreeNode hovered = (FSTreeNode) target; + if (hovered.isFile() && copying) { + hovered = hovered.getParent(); + } + return hovered.isDirectory() && hovered.isWritable() && (moving || copying); + } + return false; + } + + /** + * Validate dropping when the elements being dragged are local selection. + * + * @param target The target object. + * @param operation The DnD operation. + * @param transferType The transfered data simulator. + * @return true if it is valid for dropping. + */ + public boolean validateLocalSelectionDrop(Object target, int operation, TransferData transferType) { + FSTreeNode hovered = (FSTreeNode) target; + LocalSelectionTransfer transfer = LocalSelectionTransfer.getTransfer(); + IStructuredSelection selection = (IStructuredSelection) transfer.getSelection(); + List<FSTreeNode> nodes = selection.toList(); + boolean moving = (operation & DND.DROP_MOVE) != 0; + boolean copying = (operation & DND.DROP_COPY) != 0; + if (hovered.isDirectory() && hovered.isWritable() && (moving || copying)) { + FSTreeNode head = nodes.get(0); + String hid = head.peerNode.getPeerId(); + String tid = hovered.peerNode.getPeerId(); + if (hid.equals(tid)) { + for (FSTreeNode node : nodes) { + if (moving && node == hovered || node.isAncestorOf(hovered)) { + return false; + } + } + return true; + } + } + else if (hovered.isFile() && copying) { + hovered = hovered.getParent(); + return validateLocalSelectionDrop(hovered, operation, transferType); + } + return false; + } + + /* + * (non-Javadoc) + * @see org.eclipse.tcf.te.tcf.filesystem.interfaces.IConfirmCallback#requires(java.lang.Object) + */ + @Override + public boolean requires(Object object) { + return true; + } + + /* + * (non-Javadoc) + * @see org.eclipse.tcf.te.tcf.filesystem.interfaces.IConfirmCallback#confirms(java.lang.Object) + */ + @Override + public int confirms(Object object) { + final int[] results = new int[1]; + final File file = (File) object; + Display display = PlatformUI.getWorkbench().getDisplay(); + display.syncExec(new Runnable() { + @Override + public void run() { + Shell parent = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); + String title = Messages.FSUpload_OverwriteTitle; + String message = NLS.bind(Messages.FSUpload_OverwriteConfirmation, file.getName()); + final Image titleImage = UIPlugin.getImage(ImageConsts.DELETE_READONLY_CONFIRM); + MessageDialog qDialog = new MessageDialog(parent, title, null, message, + MessageDialog.QUESTION, new String[] {Messages.FSUpload_Yes, + Messages.FSUpload_YesToAll, Messages.FSUpload_No, Messages.FSUpload_Cancel}, 0) { + @Override + public Image getQuestionImage() { + return titleImage; + } + }; + results[0] = qDialog.open(); + } + }); + return results[0]; + } + + /* + * (non-Javadoc) + * @see org.eclipse.swt.dnd.DragSourceListener#dragSetData(org.eclipse.swt.dnd.DragSourceEvent) + */ + public boolean setDragData(DragSourceEvent anEvent) { + if (LocalSelectionTransfer.getTransfer().isSupportedType(anEvent.dataType)) { + anEvent.data = LocalSelectionTransfer.getTransfer().getSelection(); + return true; + } + else if (FileTransfer.getInstance().isSupportedType(anEvent.dataType)) { + IStructuredSelection selection = (IStructuredSelection) LocalSelectionTransfer.getTransfer().getSelection(); + List<FSTreeNode> nodes = selection.toList(); + List<String> paths = new ArrayList<String>(); + for(FSTreeNode node : nodes) { + File file = CacheManager.getCacheFile(node); + if(file.exists()) { + paths.add(file.getAbsolutePath()); + } + } + if (!paths.isEmpty()) anEvent.data = paths.toArray(new String[paths.size()]); + return !paths.isEmpty(); + } + return false; + } +} diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/handlers/MoveFilesHandler.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/handlers/MoveFilesHandler.java index 9f8b01d22..d62a1d6b1 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/handlers/MoveFilesHandler.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/handlers/MoveFilesHandler.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011, 2012 Wind River Systems, Inc. and others. All rights reserved. + * Copyright (c) 2011, 2014 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 diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/handlers/NewNodeHandler.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/handlers/NewNodeHandler.java index 245d11d3c..332f6dbbf 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/handlers/NewNodeHandler.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/handlers/NewNodeHandler.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011, 2012 Wind River Systems, Inc. and others. All rights reserved. + * Copyright (c) 2011, 2013 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 diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/handlers/OpenFileHandler.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/handlers/OpenFileHandler.java index 1687c171f..cb046f899 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/handlers/OpenFileHandler.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/handlers/OpenFileHandler.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011, 2012 Wind River Systems, Inc. and others. All rights reserved. + * Copyright (c) 2011, 2013 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 diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/handlers/OpenWithMenu.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/handlers/OpenWithMenu.java index 7bfc8a4f8..14c6679e1 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/handlers/OpenWithMenu.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/handlers/OpenWithMenu.java @@ -1,419 +1,419 @@ -/*******************************************************************************
- * 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:
- * William Chen (Wind River) [360494]Provide an "Open With" action in the pop
- * up menu of file system nodes of Target Explorer.
- *******************************************************************************/
-package org.eclipse.tcf.te.tcf.filesystem.ui.internal.handlers;
-
-import java.io.File;
-import java.text.Collator;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.Map;
-
-import org.eclipse.core.filesystem.EFS;
-import org.eclipse.core.filesystem.IFileStore;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.QualifiedName;
-import org.eclipse.core.runtime.content.IContentType;
-import org.eclipse.jface.action.ContributionItem;
-import org.eclipse.jface.resource.ImageDescriptor;
-import org.eclipse.jface.window.Window;
-import org.eclipse.osgi.util.NLS;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.widgets.Event;
-import org.eclipse.swt.widgets.Listener;
-import org.eclipse.swt.widgets.Menu;
-import org.eclipse.swt.widgets.MenuItem;
-import org.eclipse.tcf.te.tcf.filesystem.core.internal.operations.IOpExecutor;
-import org.eclipse.tcf.te.tcf.filesystem.core.internal.operations.OpCacheUpdate;
-import org.eclipse.tcf.te.tcf.filesystem.core.internal.utils.CacheManager;
-import org.eclipse.tcf.te.tcf.filesystem.core.internal.utils.ContentTypeHelper;
-import org.eclipse.tcf.te.tcf.filesystem.core.internal.utils.PersistenceManager;
-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.tcf.filesystem.ui.internal.operations.UiExecutor;
-import org.eclipse.tcf.te.tcf.filesystem.ui.nls.Messages;
-import org.eclipse.ui.IEditorDescriptor;
-import org.eclipse.ui.IEditorRegistry;
-import org.eclipse.ui.IWorkbenchPage;
-import org.eclipse.ui.PartInitException;
-import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.dialogs.EditorSelectionDialog;
-import org.eclipse.ui.ide.FileStoreEditorInput;
-import org.eclipse.ui.ide.IDE;
-
-/**
- * A menu for opening files in the target explorer.
- * <p>
- * An <code>OpenWithMenu</code> is used to populate a menu with "Open With" actions. One action is
- * added for each editor which is applicable to the selected file. If the user selects one of these
- * items, the corresponding editor is opened on the file.
- * </p>
- *
- * @since 3.7 - Copied and modified based on org.eclipse.ui.actions.OpenWithMenu to avoid
- * introducing org.eclipse.core.resources
- */
-public class OpenWithMenu extends ContributionItem {
- private static final String DEFAULT_TEXT_EDITOR = "org.eclipse.ui.DefaultTextEditor"; //$NON-NLS-1$
-
- /**
- * The id of this action.
- */
- public static final String ID = UIPlugin.getUniqueIdentifier() + ".OpenWithMenu";//$NON-NLS-1$
-
- /*
- * Compares the labels from two IEditorDescriptor objects
- */
- private static final Comparator<IEditorDescriptor> comparer = new Comparator<IEditorDescriptor>() {
- private Collator collator = Collator.getInstance();
-
- @Override
- public int compare(IEditorDescriptor arg0, IEditorDescriptor arg1) {
- String s1 = arg0.getLabel();
- String s2 = arg1.getLabel();
- return collator.compare(s1, s2);
- }
- };
- // The selected tree node.
- FSTreeNode node;
- // The current workbench page.
- IWorkbenchPage page;
- // The editor registry.
- IEditorRegistry registry;
-
- /**
- * Create an instance using the specified page and the specified FSTreeNode.
- *
- * @param page The page to open the editor.
- * @param node The FSTreeNode to be opened.
- */
- public OpenWithMenu(IWorkbenchPage page, FSTreeNode node) {
- super(ID);
- this.node = node;
- this.page = page;
- this.registry = PlatformUI.getWorkbench().getEditorRegistry();
- }
-
- /**
- * Returns an image to show for the corresponding editor descriptor.
- *
- * @param editorDesc the editor descriptor, or null for the system editor
- * @return the image or null
- */
- private Image getImage(IEditorDescriptor editorDesc) {
- ImageDescriptor imageDesc = getImageDescriptor(editorDesc);
- if (imageDesc == null) {
- return null;
- }
- return imageDesc.createImage();
- }
-
- /**
- * Returns the image descriptor for the given editor descriptor, or null if it has no image.
- */
- private ImageDescriptor getImageDescriptor(IEditorDescriptor editorDesc) {
- ImageDescriptor imageDesc = null;
- if (editorDesc == null) {
- imageDesc = registry.getImageDescriptor(node.name);
- // TODO: is this case valid, and if so, what are the implications for content-simulator
- // editor bindings?
- }
- else {
- imageDesc = editorDesc.getImageDescriptor();
- }
- if (imageDesc == null) {
- if (editorDesc != null && editorDesc.getId().equals(IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID)) {
- imageDesc = registry.getSystemExternalEditorImageDescriptor(node.name);
- }
- }
- return imageDesc;
- }
-
- /**
- * Creates the menu item for the editor descriptor.
- *
- * @param menu the menu to add the item to
- * @param descriptor the editor descriptor, or null for the system editor
- * @param preferredEditor the descriptor of the preferred editor, or <code>null</code>
- */
- private void createMenuItem(Menu menu, final IEditorDescriptor descriptor, final IEditorDescriptor preferredEditor) {
- final MenuItem menuItem = new MenuItem(menu, SWT.RADIO);
- boolean isPreferred = preferredEditor != null && descriptor.getId()
- .equals(preferredEditor.getId());
- menuItem.setSelection(isPreferred);
- menuItem.setText(descriptor.getLabel());
- Image image = getImage(descriptor);
- if (image != null) {
- menuItem.setImage(image);
- }
- Listener listener = new Listener() {
- @Override
- public void handleEvent(Event event) {
- switch (event.type) {
- case SWT.Selection:
- if (menuItem.getSelection()) {
- syncOpen(descriptor, false);
- }
- break;
- default:
- break;
- }
- }
- };
- menuItem.addListener(SWT.Selection, listener);
- }
-
- /**
- * Creates the Other... menu item
- *
- * @param menu the menu to add the item to
- */
- @SuppressWarnings("unused")
- private void createOtherMenuItem(final Menu menu) {
- new MenuItem(menu, SWT.SEPARATOR);
- final MenuItem menuItem = new MenuItem(menu, SWT.PUSH);
- menuItem.setText(Messages.OpenWithMenu_OpenWith);
- Listener listener = new Listener() {
- @Override
- public void handleEvent(Event event) {
- switch (event.type) {
- case SWT.Selection:
- EditorSelectionDialog dialog = new EditorSelectionDialog(menu.getShell());
- dialog.setMessage(NLS
- .bind(Messages.OpenWithMenu_ChooseEditorForOpening, node.name));
- if (dialog.open() == Window.OK) {
- IEditorDescriptor editor = dialog.getSelectedEditor();
- if (editor != null) {
- syncOpen(editor, editor.isOpenExternal());
- }
- }
- break;
- default:
- break;
- }
- }
- };
- menuItem.addListener(SWT.Selection, listener);
- }
-
- /**
- * Get the default editor for this FSTreeNode.
- *
- * @return The descriptor of the default editor.
- */
- private IEditorDescriptor getDefaultEditor() {
- // Try file specific editor.
- try {
- String editorID = PersistenceManager.getInstance().getPersistentProperties(node)
- .get(IDE.EDITOR_KEY);
- if (editorID != null) {
- IEditorDescriptor desc = registry.findEditor(editorID);
- if (desc != null) {
- return desc;
- }
- }
- }
- catch (Exception e) {
- // do nothing
- }
-
- IContentType contentType = null;
- contentType = ContentTypeHelper.getContentType(node);
- // Try lookup with filename
- return registry.getDefaultEditor(node.name, contentType);
- }
-
- /*
- * (non-Javadoc) Fills the menu with perspective items.
- */
- @SuppressWarnings("unused")
- @Override
- public void fill(Menu menu, int index) {
-
- IEditorDescriptor defaultEditor = registry.findEditor(DEFAULT_TEXT_EDITOR);
- IEditorDescriptor preferredEditor = getDefaultEditor();
-
- IEditorDescriptor[] editors = registry.getEditors(node.name, ContentTypeHelper.getContentType(node));
- Collections.sort(Arrays.asList(editors), comparer);
-
- boolean defaultFound = false;
-
- // Check that we don't add it twice. This is possible
- // if the same editor goes to two mappings.
- ArrayList<IEditorDescriptor> alreadyMapped = new ArrayList<IEditorDescriptor>();
-
- for (int i = 0; i < editors.length; i++) {
- IEditorDescriptor editor = editors[i];
- if (!alreadyMapped.contains(editor)) {
- createMenuItem(menu, editor, preferredEditor);
- if (defaultEditor != null && editor.getId().equals(defaultEditor.getId())) {
- defaultFound = true;
- }
- alreadyMapped.add(editor);
- }
- }
-
- // Only add a separator if there is something to separate
- if (editors.length > 0) {
- new MenuItem(menu, SWT.SEPARATOR);
- }
-
- // Add default editor. Check it if it is saved as the preference.
- if (!defaultFound && defaultEditor != null) {
- createMenuItem(menu, defaultEditor, preferredEditor);
- }
-
- // Add system editor (should never be null)
- IEditorDescriptor descriptor = registry
- .findEditor(IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID);
- createMenuItem(menu, descriptor, preferredEditor);
-
- createDefaultMenuItem(menu);
-
- // add Other... menu item
- createOtherMenuItem(menu);
- }
-
- /*
- * (non-Javadoc) Returns whether this menu is dynamic.
- */
- @Override
- public boolean isDynamic() {
- return true;
- }
-
- /**
- * Creates the menu item for clearing the current selection.
- *
- * @param menu the menu to add the item to
- * @param file the file being edited
- */
- private void createDefaultMenuItem(Menu menu) {
- final MenuItem menuItem = new MenuItem(menu, SWT.RADIO);
- menuItem.setSelection(getDefaultEditor() == null);
- menuItem.setText(Messages.OpenWithMenu_DefaultEditor);
-
- Listener listener = new Listener() {
- @Override
- public void handleEvent(Event event) {
- switch (event.type) {
- case SWT.Selection:
- if (menuItem.getSelection()) {
- PersistenceManager.getInstance().getPersistentProperties(node)
- .put(IDE.EDITOR_KEY, null);
- try {
- syncOpen(getEditorDescriptor(), false);
- }
- catch (PartInitException e) {
- e.printStackTrace();
- }
- }
- break;
- default:
- break;
- }
- }
- };
-
- menuItem.addListener(SWT.Selection, listener);
- }
-
- /**
- * Get an appropriate editor for the FSTreeNode. If the default editor is not found, it will
- * search the in-place editor, the external editor and finally the default text editor.
- *
- * @return An appropriate editor to open the node using "Default Editor".
- * @throws PartInitException
- */
- protected IEditorDescriptor getEditorDescriptor() throws PartInitException {
- IEditorDescriptor defaultDescriptor = getDefaultEditor();
- if (defaultDescriptor != null) {
- return defaultDescriptor;
- }
-
- IEditorDescriptor editorDesc = null;
-
- // next check the OS for in-place editor (OLE on Win32)
- if (registry.isSystemInPlaceEditorAvailable(node.name)) {
- editorDesc = registry.findEditor(IEditorRegistry.SYSTEM_INPLACE_EDITOR_ID);
- }
-
- // next check with the OS for an external editor
- if (editorDesc == null && registry.isSystemExternalEditorAvailable(node.name)) {
- editorDesc = registry.findEditor(IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID);
- }
-
- // next lookup the default text editor
- if (editorDesc == null) {
- editorDesc = registry.findEditor(DEFAULT_TEXT_EDITOR);
- }
-
- // if no valid editor found, bail out
- if (editorDesc == null) {
- throw new PartInitException(Messages.OpenWithMenu_NoEditorFound);
- }
-
- return editorDesc;
- }
-
- /**
- * Synchronize and open the file using the specified editor descriptor. If openUsingDescriptor
- * is true, it will try to use an external editor to open it if an eclipse editor is not
- * available.
- *
- * @param editorDescriptor The editor descriptor used to open the node.
- * @param openUsingDescriptor If an external editor should be used to open the node.
- */
- protected void syncOpen(IEditorDescriptor editorDescriptor, boolean openUsingDescriptor) {
- File file = CacheManager.getCacheFile(node);
- if (!file.exists()) {
- // If the file node's local cache does not exist yet, download it.
- IOpExecutor executor = new UiExecutor();
- IStatus status = executor.execute(new OpCacheUpdate(node));
- if (!status.isOK()) {
- return;
- }
- }
- openInEditor(editorDescriptor, openUsingDescriptor);
- }
-
- /**
- * Open the editor using the specified editor descriptor. If openUsingDescriptor is true, it
- * will try to use an external editor to open it if an eclipse editor is not available.
- *
- * @param editorDescriptor The editor descriptor used to open the node.
- * @param openUsingDescriptor If an external editor should be used to open the node.
- */
- private void openInEditor(IEditorDescriptor editorDescriptor, boolean openUsingDescriptor) {
- try {
- IPath path = CacheManager.getCachePath(node);
- IFileStore fileStore = EFS.getLocalFileSystem().getStore(path);
- FileStoreEditorInput input = new FileStoreEditorInput(fileStore);
- if (openUsingDescriptor) {
- String editorId = editorDescriptor.getId();
- page.openEditor(input, editorId, true, IWorkbenchPage.MATCH_INPUT | IWorkbenchPage.MATCH_ID);
- }
- else {
- String editorId = IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID;
- if (editorDescriptor != null) editorId = editorDescriptor.getId();
- page.openEditor(input, editorId, true, IWorkbenchPage.MATCH_INPUT | IWorkbenchPage.MATCH_ID);
- Map<QualifiedName, String> properties = PersistenceManager.getInstance()
- .getPersistentProperties(node);
- properties.put(IDE.EDITOR_KEY, editorId);
- }
- }
- catch (PartInitException e) {
- e.printStackTrace();
- }
- }
-}
+/******************************************************************************* + * Copyright (c) 2011, 2014 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: + * William Chen (Wind River) [360494]Provide an "Open With" action in the pop + * up menu of file system nodes of Target Explorer. + *******************************************************************************/ +package org.eclipse.tcf.te.tcf.filesystem.ui.internal.handlers; + +import java.io.File; +import java.text.Collator; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.Comparator; +import java.util.Map; + +import org.eclipse.core.filesystem.EFS; +import org.eclipse.core.filesystem.IFileStore; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.QualifiedName; +import org.eclipse.core.runtime.content.IContentType; +import org.eclipse.jface.action.ContributionItem; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.window.Window; +import org.eclipse.osgi.util.NLS; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Listener; +import org.eclipse.swt.widgets.Menu; +import org.eclipse.swt.widgets.MenuItem; +import org.eclipse.tcf.te.tcf.filesystem.core.internal.operations.IOpExecutor; +import org.eclipse.tcf.te.tcf.filesystem.core.internal.operations.OpCacheUpdate; +import org.eclipse.tcf.te.tcf.filesystem.core.internal.utils.CacheManager; +import org.eclipse.tcf.te.tcf.filesystem.core.internal.utils.ContentTypeHelper; +import org.eclipse.tcf.te.tcf.filesystem.core.internal.utils.PersistenceManager; +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.tcf.filesystem.ui.internal.operations.UiExecutor; +import org.eclipse.tcf.te.tcf.filesystem.ui.nls.Messages; +import org.eclipse.ui.IEditorDescriptor; +import org.eclipse.ui.IEditorRegistry; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.PartInitException; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.dialogs.EditorSelectionDialog; +import org.eclipse.ui.ide.FileStoreEditorInput; +import org.eclipse.ui.ide.IDE; + +/** + * A menu for opening files in the target explorer. + * <p> + * An <code>OpenWithMenu</code> is used to populate a menu with "Open With" actions. One action is + * added for each editor which is applicable to the selected file. If the user selects one of these + * items, the corresponding editor is opened on the file. + * </p> + * + * @since 3.7 - Copied and modified based on org.eclipse.ui.actions.OpenWithMenu to avoid + * introducing org.eclipse.core.resources + */ +public class OpenWithMenu extends ContributionItem { + private static final String DEFAULT_TEXT_EDITOR = "org.eclipse.ui.DefaultTextEditor"; //$NON-NLS-1$ + + /** + * The id of this action. + */ + public static final String ID = UIPlugin.getUniqueIdentifier() + ".OpenWithMenu";//$NON-NLS-1$ + + /* + * Compares the labels from two IEditorDescriptor objects + */ + private static final Comparator<IEditorDescriptor> comparer = new Comparator<IEditorDescriptor>() { + private Collator collator = Collator.getInstance(); + + @Override + public int compare(IEditorDescriptor arg0, IEditorDescriptor arg1) { + String s1 = arg0.getLabel(); + String s2 = arg1.getLabel(); + return collator.compare(s1, s2); + } + }; + // The selected tree node. + FSTreeNode node; + // The current workbench page. + IWorkbenchPage page; + // The editor registry. + IEditorRegistry registry; + + /** + * Create an instance using the specified page and the specified FSTreeNode. + * + * @param page The page to open the editor. + * @param node The FSTreeNode to be opened. + */ + public OpenWithMenu(IWorkbenchPage page, FSTreeNode node) { + super(ID); + this.node = node; + this.page = page; + this.registry = PlatformUI.getWorkbench().getEditorRegistry(); + } + + /** + * Returns an image to show for the corresponding editor descriptor. + * + * @param editorDesc the editor descriptor, or null for the system editor + * @return the image or null + */ + private Image getImage(IEditorDescriptor editorDesc) { + ImageDescriptor imageDesc = getImageDescriptor(editorDesc); + if (imageDesc == null) { + return null; + } + return imageDesc.createImage(); + } + + /** + * Returns the image descriptor for the given editor descriptor, or null if it has no image. + */ + private ImageDescriptor getImageDescriptor(IEditorDescriptor editorDesc) { + ImageDescriptor imageDesc = null; + if (editorDesc == null) { + imageDesc = registry.getImageDescriptor(node.name); + // TODO: is this case valid, and if so, what are the implications for content-simulator + // editor bindings? + } + else { + imageDesc = editorDesc.getImageDescriptor(); + } + if (imageDesc == null) { + if (editorDesc != null && editorDesc.getId().equals(IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID)) { + imageDesc = registry.getSystemExternalEditorImageDescriptor(node.name); + } + } + return imageDesc; + } + + /** + * Creates the menu item for the editor descriptor. + * + * @param menu the menu to add the item to + * @param descriptor the editor descriptor, or null for the system editor + * @param preferredEditor the descriptor of the preferred editor, or <code>null</code> + */ + private void createMenuItem(Menu menu, final IEditorDescriptor descriptor, final IEditorDescriptor preferredEditor) { + final MenuItem menuItem = new MenuItem(menu, SWT.RADIO); + boolean isPreferred = preferredEditor != null && descriptor.getId() + .equals(preferredEditor.getId()); + menuItem.setSelection(isPreferred); + menuItem.setText(descriptor.getLabel()); + Image image = getImage(descriptor); + if (image != null) { + menuItem.setImage(image); + } + Listener listener = new Listener() { + @Override + public void handleEvent(Event event) { + switch (event.type) { + case SWT.Selection: + if (menuItem.getSelection()) { + syncOpen(descriptor, false); + } + break; + default: + break; + } + } + }; + menuItem.addListener(SWT.Selection, listener); + } + + /** + * Creates the Other... menu item + * + * @param menu the menu to add the item to + */ + @SuppressWarnings("unused") + private void createOtherMenuItem(final Menu menu) { + new MenuItem(menu, SWT.SEPARATOR); + final MenuItem menuItem = new MenuItem(menu, SWT.PUSH); + menuItem.setText(Messages.OpenWithMenu_OpenWith); + Listener listener = new Listener() { + @Override + public void handleEvent(Event event) { + switch (event.type) { + case SWT.Selection: + EditorSelectionDialog dialog = new EditorSelectionDialog(menu.getShell()); + dialog.setMessage(NLS + .bind(Messages.OpenWithMenu_ChooseEditorForOpening, node.name)); + if (dialog.open() == Window.OK) { + IEditorDescriptor editor = dialog.getSelectedEditor(); + if (editor != null) { + syncOpen(editor, editor.isOpenExternal()); + } + } + break; + default: + break; + } + } + }; + menuItem.addListener(SWT.Selection, listener); + } + + /** + * Get the default editor for this FSTreeNode. + * + * @return The descriptor of the default editor. + */ + private IEditorDescriptor getDefaultEditor() { + // Try file specific editor. + try { + String editorID = PersistenceManager.getInstance().getPersistentProperties(node) + .get(IDE.EDITOR_KEY); + if (editorID != null) { + IEditorDescriptor desc = registry.findEditor(editorID); + if (desc != null) { + return desc; + } + } + } + catch (Exception e) { + // do nothing + } + + IContentType contentType = null; + contentType = ContentTypeHelper.getContentType(node); + // Try lookup with filename + return registry.getDefaultEditor(node.name, contentType); + } + + /* + * (non-Javadoc) Fills the menu with perspective items. + */ + @SuppressWarnings("unused") + @Override + public void fill(Menu menu, int index) { + + IEditorDescriptor defaultEditor = registry.findEditor(DEFAULT_TEXT_EDITOR); + IEditorDescriptor preferredEditor = getDefaultEditor(); + + IEditorDescriptor[] editors = registry.getEditors(node.name, ContentTypeHelper.getContentType(node)); + Collections.sort(Arrays.asList(editors), comparer); + + boolean defaultFound = false; + + // Check that we don't add it twice. This is possible + // if the same editor goes to two mappings. + ArrayList<IEditorDescriptor> alreadyMapped = new ArrayList<IEditorDescriptor>(); + + for (int i = 0; i < editors.length; i++) { + IEditorDescriptor editor = editors[i]; + if (!alreadyMapped.contains(editor)) { + createMenuItem(menu, editor, preferredEditor); + if (defaultEditor != null && editor.getId().equals(defaultEditor.getId())) { + defaultFound = true; + } + alreadyMapped.add(editor); + } + } + + // Only add a separator if there is something to separate + if (editors.length > 0) { + new MenuItem(menu, SWT.SEPARATOR); + } + + // Add default editor. Check it if it is saved as the preference. + if (!defaultFound && defaultEditor != null) { + createMenuItem(menu, defaultEditor, preferredEditor); + } + + // Add system editor (should never be null) + IEditorDescriptor descriptor = registry + .findEditor(IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID); + createMenuItem(menu, descriptor, preferredEditor); + + createDefaultMenuItem(menu); + + // add Other... menu item + createOtherMenuItem(menu); + } + + /* + * (non-Javadoc) Returns whether this menu is dynamic. + */ + @Override + public boolean isDynamic() { + return true; + } + + /** + * Creates the menu item for clearing the current selection. + * + * @param menu the menu to add the item to + * @param file the file being edited + */ + private void createDefaultMenuItem(Menu menu) { + final MenuItem menuItem = new MenuItem(menu, SWT.RADIO); + menuItem.setSelection(getDefaultEditor() == null); + menuItem.setText(Messages.OpenWithMenu_DefaultEditor); + + Listener listener = new Listener() { + @Override + public void handleEvent(Event event) { + switch (event.type) { + case SWT.Selection: + if (menuItem.getSelection()) { + PersistenceManager.getInstance().getPersistentProperties(node) + .put(IDE.EDITOR_KEY, null); + try { + syncOpen(getEditorDescriptor(), false); + } + catch (PartInitException e) { + e.printStackTrace(); + } + } + break; + default: + break; + } + } + }; + + menuItem.addListener(SWT.Selection, listener); + } + + /** + * Get an appropriate editor for the FSTreeNode. If the default editor is not found, it will + * search the in-place editor, the external editor and finally the default text editor. + * + * @return An appropriate editor to open the node using "Default Editor". + * @throws PartInitException + */ + protected IEditorDescriptor getEditorDescriptor() throws PartInitException { + IEditorDescriptor defaultDescriptor = getDefaultEditor(); + if (defaultDescriptor != null) { + return defaultDescriptor; + } + + IEditorDescriptor editorDesc = null; + + // next check the OS for in-place editor (OLE on Win32) + if (registry.isSystemInPlaceEditorAvailable(node.name)) { + editorDesc = registry.findEditor(IEditorRegistry.SYSTEM_INPLACE_EDITOR_ID); + } + + // next check with the OS for an external editor + if (editorDesc == null && registry.isSystemExternalEditorAvailable(node.name)) { + editorDesc = registry.findEditor(IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID); + } + + // next lookup the default text editor + if (editorDesc == null) { + editorDesc = registry.findEditor(DEFAULT_TEXT_EDITOR); + } + + // if no valid editor found, bail out + if (editorDesc == null) { + throw new PartInitException(Messages.OpenWithMenu_NoEditorFound); + } + + return editorDesc; + } + + /** + * Synchronize and open the file using the specified editor descriptor. If openUsingDescriptor + * is true, it will try to use an external editor to open it if an eclipse editor is not + * available. + * + * @param editorDescriptor The editor descriptor used to open the node. + * @param openUsingDescriptor If an external editor should be used to open the node. + */ + protected void syncOpen(IEditorDescriptor editorDescriptor, boolean openUsingDescriptor) { + File file = CacheManager.getCacheFile(node); + if (!file.exists()) { + // If the file node's local cache does not exist yet, download it. + IOpExecutor executor = new UiExecutor(); + IStatus status = executor.execute(new OpCacheUpdate(node)); + if (!status.isOK()) { + return; + } + } + openInEditor(editorDescriptor, openUsingDescriptor); + } + + /** + * Open the editor using the specified editor descriptor. If openUsingDescriptor is true, it + * will try to use an external editor to open it if an eclipse editor is not available. + * + * @param editorDescriptor The editor descriptor used to open the node. + * @param openUsingDescriptor If an external editor should be used to open the node. + */ + private void openInEditor(IEditorDescriptor editorDescriptor, boolean openUsingDescriptor) { + try { + IPath path = CacheManager.getCachePath(node); + IFileStore fileStore = EFS.getLocalFileSystem().getStore(path); + FileStoreEditorInput input = new FileStoreEditorInput(fileStore); + if (openUsingDescriptor) { + String editorId = editorDescriptor.getId(); + page.openEditor(input, editorId, true, IWorkbenchPage.MATCH_INPUT | IWorkbenchPage.MATCH_ID); + } + else { + String editorId = IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID; + if (editorDescriptor != null) editorId = editorDescriptor.getId(); + page.openEditor(input, editorId, true, IWorkbenchPage.MATCH_INPUT | IWorkbenchPage.MATCH_ID); + Map<QualifiedName, String> properties = PersistenceManager.getInstance() + .getPersistentProperties(node); + properties.put(IDE.EDITOR_KEY, editorId); + } + } + catch (PartInitException e) { + e.printStackTrace(); + } + } +} diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/handlers/RefreshViewerHandler.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/handlers/RefreshViewerHandler.java index 2cbd52133..1ec29d0cc 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/handlers/RefreshViewerHandler.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/handlers/RefreshViewerHandler.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011, 2012 Wind River Systems, Inc. and others. All rights reserved. + * Copyright (c) 2011, 2014 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 diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/pages/FSExplorerEditorPage.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/pages/FSExplorerEditorPage.java index 81cb41916..a80875e6e 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/pages/FSExplorerEditorPage.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/pages/FSExplorerEditorPage.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011, 2012 Wind River Systems, Inc. and others. All rights reserved. + * Copyright (c) 2011, 2014 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 diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/search/FSGeneralSearchable.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/search/FSGeneralSearchable.java index c261bb746..e8c3976ce 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/search/FSGeneralSearchable.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/search/FSGeneralSearchable.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011, 2012 Wind River Systems, Inc. and others. All rights reserved. + * Copyright (c) 2011, 2013 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 diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/search/FSModifiedSearchable.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/search/FSModifiedSearchable.java index 8667ab195..df7113707 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/search/FSModifiedSearchable.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/search/FSModifiedSearchable.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011, 2012 Wind River Systems, Inc. and others. All rights reserved. + * Copyright (c) 2011, 2013 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 diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/search/FSSizeSearchable.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/search/FSSizeSearchable.java index 01abb34cb..fbd42c2ce 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/search/FSSizeSearchable.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/search/FSSizeSearchable.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011, 2012 Wind River Systems, Inc. and others. All rights reserved. + * Copyright (c) 2011, 2013 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 diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/search/FSTreeNodeMatcher.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/search/FSTreeNodeMatcher.java index d7ae57dd1..3d2c80d9a 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/search/FSTreeNodeMatcher.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/search/FSTreeNodeMatcher.java @@ -1,79 +1,79 @@ -/*******************************************************************************
- * 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.search;
-
-import org.eclipse.tcf.te.tcf.filesystem.core.model.FSTreeNode;
-import org.eclipse.tcf.te.ui.interfaces.ISearchMatcher;
-import org.eclipse.tcf.te.ui.utils.StringMatcher;
-/**
- * The ISearchMatcher implementation for FSTreeNode.
- */
-public class FSTreeNodeMatcher implements ISearchMatcher {
- // Whether it is case sensitive
- private boolean fCaseSensitive;
- // Whether it is precise matching.
- private boolean fMatchPrecise;
- // The string matcher used for matching.
- private StringMatcher fStringMatcher;
- // The current selected target simulator index.
- private int fTargetType;
- // The current target names.
- private String fTargetName;
- // The flag if system files should be included
- private boolean fIncludeSystem;
- // The flag if hidden files should be included
- private boolean fIncludeHidden;
-
- /**
- * Constructor with different option parameters.
- *
- * @param caseSensitive Option of case sensitive
- * @param matchPrecise Option of precise matching
- * @param targetType Option of the target simulator
- * @param targetName Option of the target name
- * @param includeSystem Option if system files be included
- * @param includeHidden Option if hidden files be included
- */
- public FSTreeNodeMatcher(boolean caseSensitive, boolean matchPrecise,
- int targetType, String targetName, boolean includeSystem, boolean includeHidden) {
- fCaseSensitive = caseSensitive;
- fTargetName = targetName;
- fMatchPrecise = matchPrecise;
- if (!fMatchPrecise) {
- fStringMatcher = new StringMatcher(fTargetName, !fCaseSensitive, false);
- }
- fTargetType = targetType;
- fIncludeSystem = includeSystem;
- fIncludeHidden = includeHidden;
- }
-
- /*
- * (non-Javadoc)
- * @see org.eclipse.tcf.te.ui.interfaces.ISearchMatcher#match(java.lang.Object)
- */
- @Override
- public boolean match(Object context) {
- if (context == null) return false;
- if (context instanceof FSTreeNode) {
- FSTreeNode node = (FSTreeNode) context;
- if(fTargetType == 1 && !node.isFile() || fTargetType == 2 && !node.isDirectory()) return false;
- if(!fIncludeSystem && node.isSystem()) return false;
- if(!fIncludeHidden && node.isHidden()) return false;
- String text = node.name;
- if (text != null) {
- if (fMatchPrecise) {
- return fCaseSensitive ? text.equals(fTargetName) : text.equalsIgnoreCase(fTargetName);
- }
- return fStringMatcher.match(text);
- }
- }
- return false;
- }
-}
+/******************************************************************************* + * Copyright (c) 2012, 2014 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.search; + +import org.eclipse.tcf.te.tcf.filesystem.core.model.FSTreeNode; +import org.eclipse.tcf.te.ui.interfaces.ISearchMatcher; +import org.eclipse.tcf.te.ui.utils.StringMatcher; +/** + * The ISearchMatcher implementation for FSTreeNode. + */ +public class FSTreeNodeMatcher implements ISearchMatcher { + // Whether it is case sensitive + private boolean fCaseSensitive; + // Whether it is precise matching. + private boolean fMatchPrecise; + // The string matcher used for matching. + private StringMatcher fStringMatcher; + // The current selected target simulator index. + private int fTargetType; + // The current target names. + private String fTargetName; + // The flag if system files should be included + private boolean fIncludeSystem; + // The flag if hidden files should be included + private boolean fIncludeHidden; + + /** + * Constructor with different option parameters. + * + * @param caseSensitive Option of case sensitive + * @param matchPrecise Option of precise matching + * @param targetType Option of the target simulator + * @param targetName Option of the target name + * @param includeSystem Option if system files be included + * @param includeHidden Option if hidden files be included + */ + public FSTreeNodeMatcher(boolean caseSensitive, boolean matchPrecise, + int targetType, String targetName, boolean includeSystem, boolean includeHidden) { + fCaseSensitive = caseSensitive; + fTargetName = targetName; + fMatchPrecise = matchPrecise; + if (!fMatchPrecise) { + fStringMatcher = new StringMatcher(fTargetName, !fCaseSensitive, false); + } + fTargetType = targetType; + fIncludeSystem = includeSystem; + fIncludeHidden = includeHidden; + } + + /* + * (non-Javadoc) + * @see org.eclipse.tcf.te.ui.interfaces.ISearchMatcher#match(java.lang.Object) + */ + @Override + public boolean match(Object context) { + if (context == null) return false; + if (context instanceof FSTreeNode) { + FSTreeNode node = (FSTreeNode) context; + if(fTargetType == 1 && !node.isFile() || fTargetType == 2 && !node.isDirectory()) return false; + if(!fIncludeSystem && node.isSystem()) return false; + if(!fIncludeHidden && node.isHidden()) return false; + String text = node.name; + if (text != null) { + if (fMatchPrecise) { + return fCaseSensitive ? text.equals(fTargetName) : text.equalsIgnoreCase(fTargetName); + } + return fStringMatcher.match(text); + } + } + return false; + } +} diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/search/FSTreeNodeSearchable.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/search/FSTreeNodeSearchable.java index 79b9b0fba..b75fb2e0c 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/search/FSTreeNodeSearchable.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/search/FSTreeNodeSearchable.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011, 2012 Wind River Systems, Inc. and others. All rights reserved. + * Copyright (c) 2011, 2013 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 diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/tabbed/BasicFolderSection.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/tabbed/BasicFolderSection.java index 9336a1e0c..1090cc316 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/tabbed/BasicFolderSection.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/tabbed/BasicFolderSection.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011, 2012 Wind River Systems, Inc. and others. All rights reserved. + * Copyright (c) 2011, 2014 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 diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/tabbed/LinuxPermissionsSection.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/tabbed/LinuxPermissionsSection.java index f95012413..2178562eb 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/tabbed/LinuxPermissionsSection.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/tabbed/LinuxPermissionsSection.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011, 2012 Wind River Systems, Inc. and others. All rights reserved. + * Copyright (c) 2011, 2014 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 diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/tabbed/WindowsAttributesCESection.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/tabbed/WindowsAttributesCESection.java index 852bda7d4..1c73246b9 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/tabbed/WindowsAttributesCESection.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/tabbed/WindowsAttributesCESection.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011, 2012 Wind River Systems, Inc. and others. All rights reserved. + * Copyright (c) 2011, 2014 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 diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/tabbed/WindowsAttributesSection.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/tabbed/WindowsAttributesSection.java index cda8af8b4..dfc7a701c 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/tabbed/WindowsAttributesSection.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/tabbed/WindowsAttributesSection.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011, 2012 Wind River Systems, Inc. and others. All rights reserved. + * Copyright (c) 2011, 2014 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 diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/tabbed/WindowsFolderAISection.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/tabbed/WindowsFolderAISection.java index 0ed1f1b0a..703f33ed9 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/tabbed/WindowsFolderAISection.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/tabbed/WindowsFolderAISection.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011, 2012 Wind River Systems, Inc. and others. All rights reserved. + * Copyright (c) 2011, 2014 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 diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/wizards/NewNodeWizard.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/wizards/NewNodeWizard.java index 68a106cd9..60920629f 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/wizards/NewNodeWizard.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/wizards/NewNodeWizard.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011, 2012 Wind River Systems, Inc. and others. All rights reserved. + * Copyright (c) 2011, 2014 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 diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/wizards/NewNodeWizardPage.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/wizards/NewNodeWizardPage.java index 7eb07a21a..7179beddc 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/wizards/NewNodeWizardPage.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/wizards/NewNodeWizardPage.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011, 2012 Wind River Systems, Inc. and others. All rights reserved. + * Copyright (c) 2011, 2014 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 diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/wizards/TargetPatternFilter.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/wizards/TargetPatternFilter.java index be97de72f..82baf5e34 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/wizards/TargetPatternFilter.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/wizards/TargetPatternFilter.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2012 IBM Corporation and others. + * Copyright (c) 2005, 2014 IBM Corporation 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 diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/wizards/TargetSelectionPage.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/wizards/TargetSelectionPage.java index 45ab09ecb..d3b268055 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/wizards/TargetSelectionPage.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/wizards/TargetSelectionPage.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011, 2012 Wind River Systems, Inc. and others. All rights reserved. + * Copyright (c) 2011, 2014 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 diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/nls/Messages.properties b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/nls/Messages.properties index d112de073..0430f0e76 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/nls/Messages.properties +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/nls/Messages.properties @@ -1,5 +1,5 @@ ############################################################################### -# Copyright (c) 2012 Wind River Systems, Inc. and others. All rights reserved. +# Copyright (c) 2012, 2013 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 |