Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUwe Stieber2012-06-12 10:25:37 +0000
committerUwe Stieber2012-06-12 10:25:37 +0000
commit71eee2b7ebc416b87e94fbb3096dbf1e14f065c0 (patch)
tree2fa36dddf76207718e7714824829cc907c18a6ff /target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui
parentc8849a6edcaf861506749be4094d1920c7f1d71c (diff)
downloadorg.eclipse.tcf-71eee2b7ebc416b87e94fbb3096dbf1e14f065c0.tar.gz
org.eclipse.tcf-71eee2b7ebc416b87e94fbb3096dbf1e14f065c0.tar.xz
org.eclipse.tcf-71eee2b7ebc416b87e94fbb3096dbf1e14f065c0.zip
Target Explorer: AbstractWizard remembers workbench and selection instance provided on init
Diffstat (limited to 'target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui')
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/wizards/NewNodeWizard.java502
1 files changed, 250 insertions, 252 deletions
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 520c85d3f..6d9d1031b 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,252 +1,250 @@
-/*******************************************************************************
- * 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.wizards;
-
-import java.lang.reflect.InvocationTargetException;
-
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.jface.operation.IRunnableWithProgress;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.viewers.StructuredSelection;
-import org.eclipse.jface.viewers.TreeViewer;
-import org.eclipse.tcf.protocol.Protocol;
-import org.eclipse.tcf.te.tcf.filesystem.core.internal.operations.OpCreate;
-import org.eclipse.tcf.te.tcf.filesystem.core.model.FSTreeNode;
-import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerModel;
-import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerModelProperties;
-import org.eclipse.tcf.te.ui.views.editor.pages.TreeViewerExplorerEditorPage;
-import org.eclipse.tcf.te.ui.wizards.AbstractWizard;
-import org.eclipse.ui.INewWizard;
-import org.eclipse.ui.IWorkbench;
-import org.eclipse.ui.IWorkbenchPage;
-import org.eclipse.ui.IWorkbenchPart;
-import org.eclipse.ui.IWorkbenchWindow;
-import org.eclipse.ui.forms.editor.FormEditor;
-import org.eclipse.ui.forms.editor.IFormPage;
-import org.eclipse.ui.navigator.CommonNavigator;
-
-/**
- * The base wizard class to create a new file/folder in the file system of Target Explorer.
- */
-public abstract class NewNodeWizard extends AbstractWizard implements INewWizard {
- // The folder in which the new node is created.
- private FSTreeNode folder;
- // The target peer where the new node is created.
- private IPeerModel peer;
- // The wizard page used to create the new node.
- private NewNodeWizardPage newPage;
- // The workbench
- private IWorkbench workbench;
-
- /**
- * Create an instance.
- */
- public NewNodeWizard() {
- setNeedsProgressMonitor(true);
- }
-
- /*
- * (non-Javadoc)
- * @see org.eclipse.ui.IWorkbenchWizard#init(org.eclipse.ui.IWorkbench, org.eclipse.jface.viewers.IStructuredSelection)
- */
- @Override
- public void init(IWorkbench workbench, IStructuredSelection selection) {
- this.workbench = workbench;
- // Set the window title
- setWindowTitle(getTitle());
- if (!selection.isEmpty()) {
- Object element = selection.getFirstElement();
- if (element instanceof FSTreeNode) {
- folder = (FSTreeNode) element;
- if (folder.isFile()) {
- // If the selected is a file, then create the node in the parent folder.
- folder = folder.getParent();
- }
- peer = folder.peerNode;
- }
- else if (element instanceof IPeerModel) {
- if(hasFileSystem((IPeerModel) element)) {
- peer = (IPeerModel) element;
- }
- }
- }
- }
-
- /**
- * Test if the specified target peer has a file system service.
- *
- * @param peer The target peer.
- * @return true if it has a file system service.
- */
- public boolean hasFileSystem(final IPeerModel peer) {
- if(Protocol.isDispatchThread()) {
- String services = null;
- services = peer.getStringProperty(IPeerModelProperties.PROP_REMOTE_SERVICES);
- if (services != null) {
- // Lookup each service individually
- for (String service : services.split(",")) { //$NON-NLS-1$
- if (service != null && service.trim().equals("FileSystem")) { //$NON-NLS-1$
- return true;
- }
- }
- }
- return false;
- }
- final boolean[] result = new boolean[1];
- Protocol.invokeAndWait(new Runnable(){
- @Override
- public void run() {
- result[0] = hasFileSystem(peer);
- }});
- return result[0];
- }
-
- /*
- * (non-Javadoc)
- * @see org.eclipse.jface.wizard.Wizard#addPages()
- */
- @Override
- public void addPages() {
- if (peer == null) {
- addPage(new TargetSelectionPage());
- }
- addPage(newPage = createWizardPage());
- }
-
- /*
- * (non-Javadoc)
- * @see org.eclipse.jface.wizard.Wizard#performFinish()
- */
- @Override
- public boolean performFinish() {
- if (newPage != null) {
- // Save the value so that next time it is used as the default input.
- newPage.saveWidgetValues();
- // Get the new name and create the node.
- String name = newPage.getNodeName();
- FSTreeNode dest = newPage.getInputDir();
- final OpCreate create = getCreateOp(dest, name);
- IRunnableWithProgress runnable = new IRunnableWithProgress() {
- @Override
- public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
- create.run(monitor);
- }};
- try {
- getContainer().run(false, false, runnable);
- final FSTreeNode newNode = create.getNode();
- getShell().getDisplay().asyncExec(new Runnable(){
- @Override
- public void run() {
- selectNewNode(newNode);
- }});
- return true;
- }
- catch (InvocationTargetException e) {
- newPage.setErrorMessage(e.getMessage());
- }
- catch (InterruptedException e) {
- }
- }
- return false;
- }
-
- /**
- * Select the specified node in the selection provider.
- *
- * @param node The node to be selected.
- */
- void selectNewNode(FSTreeNode node) {
- TreeViewer viewer = getFocusedViewer();
- if(viewer != null) {
- viewer.refresh(folder);
- ISelection selection = new StructuredSelection(node);
- viewer.setSelection(selection, true);
- }
- }
-
- /**
- * Get currently focused tree viewer.
- *
- * @return currently focused tree viewer or null.
- */
- TreeViewer getFocusedViewer() {
- IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
- if (window != null) {
- IWorkbenchPage page = window.getActivePage();
- if (page != null) {
- IWorkbenchPart part = page.getActivePart();
- if (part instanceof FormEditor) {
- FormEditor formEditor = (FormEditor) part;
- IFormPage formPage = formEditor.getActivePageInstance();
- if (formPage instanceof TreeViewerExplorerEditorPage) {
- TreeViewerExplorerEditorPage viewerPage = (TreeViewerExplorerEditorPage) formPage;
- return (TreeViewer) viewerPage.getTreeControl().getViewer();
- }
- } else if (part instanceof CommonNavigator) {
- CommonNavigator navigator = (CommonNavigator) part;
- return navigator.getCommonViewer();
- }
- }
- }
- return null;
- }
-
- /**
- * Create a wizard page to create a new node.
- *
- * @return The new wizard page.
- */
- protected abstract NewNodeWizardPage createWizardPage();
-
- /**
- * Create a Create operation instance using the specified folder and the new name.
- *
- * @param folder The folder in which the new node is created.
- * @param name The name of the new node.
- * @return a FSCreate instance to do the creation.
- */
- protected abstract OpCreate getCreateOp(FSTreeNode folder, String name);
-
- /**
- * The wizard's title to be used.
- *
- * @return The wizard's title to be used.
- */
- protected abstract String getTitle();
-
- /**
- * Get the current target peer selected.
- *
- * @return The target peer selected.
- */
- public IPeerModel getPeer(){
- return peer;
- }
-
- /**
- * Set the currently selected target peer.
- *
- * @param peer The newly selected target peer.
- */
- public void setPeer(IPeerModel peer) {
- this.peer = peer;
- newPage.setPeer(peer);
- }
-
- /**
- * Get the current selected folder.
- *
- * @return the current selected folder.
- */
- public FSTreeNode getFolder() {
- return folder;
- }
-}
+/*******************************************************************************
+ * 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.wizards;
+
+import java.lang.reflect.InvocationTargetException;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jface.operation.IRunnableWithProgress;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.tcf.protocol.Protocol;
+import org.eclipse.tcf.te.tcf.filesystem.core.internal.operations.OpCreate;
+import org.eclipse.tcf.te.tcf.filesystem.core.model.FSTreeNode;
+import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerModel;
+import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerModelProperties;
+import org.eclipse.tcf.te.ui.views.editor.pages.TreeViewerExplorerEditorPage;
+import org.eclipse.tcf.te.ui.wizards.AbstractWizard;
+import org.eclipse.ui.INewWizard;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.forms.editor.FormEditor;
+import org.eclipse.ui.forms.editor.IFormPage;
+import org.eclipse.ui.navigator.CommonNavigator;
+
+/**
+ * The base wizard class to create a new file/folder in the file system of Target Explorer.
+ */
+public abstract class NewNodeWizard extends AbstractWizard implements INewWizard {
+ // The folder in which the new node is created.
+ private FSTreeNode folder;
+ // The target peer where the new node is created.
+ private IPeerModel peer;
+ // The wizard page used to create the new node.
+ private NewNodeWizardPage newPage;
+
+ /**
+ * Create an instance.
+ */
+ public NewNodeWizard() {
+ setNeedsProgressMonitor(true);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.ui.IWorkbenchWizard#init(org.eclipse.ui.IWorkbench, org.eclipse.jface.viewers.IStructuredSelection)
+ */
+ @Override
+ public void init(IWorkbench workbench, IStructuredSelection selection) {
+ super.init(workbench, selection);
+ // Set the window title
+ setWindowTitle(getTitle());
+ if (!selection.isEmpty()) {
+ Object element = selection.getFirstElement();
+ if (element instanceof FSTreeNode) {
+ folder = (FSTreeNode) element;
+ if (folder.isFile()) {
+ // If the selected is a file, then create the node in the parent folder.
+ folder = folder.getParent();
+ }
+ peer = folder.peerNode;
+ }
+ else if (element instanceof IPeerModel) {
+ if(hasFileSystem((IPeerModel) element)) {
+ peer = (IPeerModel) element;
+ }
+ }
+ }
+ }
+
+ /**
+ * Test if the specified target peer has a file system service.
+ *
+ * @param peer The target peer.
+ * @return true if it has a file system service.
+ */
+ public boolean hasFileSystem(final IPeerModel peer) {
+ if(Protocol.isDispatchThread()) {
+ String services = null;
+ services = peer.getStringProperty(IPeerModelProperties.PROP_REMOTE_SERVICES);
+ if (services != null) {
+ // Lookup each service individually
+ for (String service : services.split(",")) { //$NON-NLS-1$
+ if (service != null && service.trim().equals("FileSystem")) { //$NON-NLS-1$
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+ final boolean[] result = new boolean[1];
+ Protocol.invokeAndWait(new Runnable(){
+ @Override
+ public void run() {
+ result[0] = hasFileSystem(peer);
+ }});
+ return result[0];
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.jface.wizard.Wizard#addPages()
+ */
+ @Override
+ public void addPages() {
+ if (peer == null) {
+ addPage(new TargetSelectionPage());
+ }
+ addPage(newPage = createWizardPage());
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.jface.wizard.Wizard#performFinish()
+ */
+ @Override
+ public boolean performFinish() {
+ if (newPage != null) {
+ // Save the value so that next time it is used as the default input.
+ newPage.saveWidgetValues();
+ // Get the new name and create the node.
+ String name = newPage.getNodeName();
+ FSTreeNode dest = newPage.getInputDir();
+ final OpCreate create = getCreateOp(dest, name);
+ IRunnableWithProgress runnable = new IRunnableWithProgress() {
+ @Override
+ public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
+ create.run(monitor);
+ }};
+ try {
+ getContainer().run(false, false, runnable);
+ final FSTreeNode newNode = create.getNode();
+ getShell().getDisplay().asyncExec(new Runnable(){
+ @Override
+ public void run() {
+ selectNewNode(newNode);
+ }});
+ return true;
+ }
+ catch (InvocationTargetException e) {
+ newPage.setErrorMessage(e.getMessage());
+ }
+ catch (InterruptedException e) {
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Select the specified node in the selection provider.
+ *
+ * @param node The node to be selected.
+ */
+ void selectNewNode(FSTreeNode node) {
+ TreeViewer viewer = getFocusedViewer();
+ if(viewer != null) {
+ viewer.refresh(folder);
+ ISelection selection = new StructuredSelection(node);
+ viewer.setSelection(selection, true);
+ }
+ }
+
+ /**
+ * Get currently focused tree viewer.
+ *
+ * @return currently focused tree viewer or null.
+ */
+ TreeViewer getFocusedViewer() {
+ IWorkbenchWindow window = getWorkbench() != null ? getWorkbench().getActiveWorkbenchWindow() : null;
+ if (window != null) {
+ IWorkbenchPage page = window.getActivePage();
+ if (page != null) {
+ IWorkbenchPart part = page.getActivePart();
+ if (part instanceof FormEditor) {
+ FormEditor formEditor = (FormEditor) part;
+ IFormPage formPage = formEditor.getActivePageInstance();
+ if (formPage instanceof TreeViewerExplorerEditorPage) {
+ TreeViewerExplorerEditorPage viewerPage = (TreeViewerExplorerEditorPage) formPage;
+ return (TreeViewer) viewerPage.getTreeControl().getViewer();
+ }
+ } else if (part instanceof CommonNavigator) {
+ CommonNavigator navigator = (CommonNavigator) part;
+ return navigator.getCommonViewer();
+ }
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Create a wizard page to create a new node.
+ *
+ * @return The new wizard page.
+ */
+ protected abstract NewNodeWizardPage createWizardPage();
+
+ /**
+ * Create a Create operation instance using the specified folder and the new name.
+ *
+ * @param folder The folder in which the new node is created.
+ * @param name The name of the new node.
+ * @return a FSCreate instance to do the creation.
+ */
+ protected abstract OpCreate getCreateOp(FSTreeNode folder, String name);
+
+ /**
+ * The wizard's title to be used.
+ *
+ * @return The wizard's title to be used.
+ */
+ protected abstract String getTitle();
+
+ /**
+ * Get the current target peer selected.
+ *
+ * @return The target peer selected.
+ */
+ public IPeerModel getPeer(){
+ return peer;
+ }
+
+ /**
+ * Set the currently selected target peer.
+ *
+ * @param peer The newly selected target peer.
+ */
+ public void setPeer(IPeerModel peer) {
+ this.peer = peer;
+ newPage.setPeer(peer);
+ }
+
+ /**
+ * Get the current selected folder.
+ *
+ * @return the current selected folder.
+ */
+ public FSTreeNode getFolder() {
+ return folder;
+ }
+}

Back to the top