Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUwe Stieber2011-12-16 04:32:05 -0500
committerUwe Stieber2011-12-16 04:32:05 -0500
commit5aa5dfc7ff8e0c83524b6e0553767194d0742f1c (patch)
treeaac725d2bf705aab8f044be15c0e6f130f12d889 /target_explorer/plugins/org.eclipse.tcf.te.tcf.ui.views
parentda70cd9b8c31a12eca0969fa1bbf657e1945360a (diff)
downloadorg.eclipse.tcf-5aa5dfc7ff8e0c83524b6e0553767194d0742f1c.tar.gz
org.eclipse.tcf-5aa5dfc7ff8e0c83524b6e0553767194d0742f1c.tar.xz
org.eclipse.tcf-5aa5dfc7ff8e0c83524b6e0553767194d0742f1c.zip
Target Explorer: Add open/save/saveas actions to Script Pad
Diffstat (limited to 'target_explorer/plugins/org.eclipse.tcf.te.tcf.ui.views')
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.ui.views/META-INF/MANIFEST.MF1
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.ui.views/plugin.properties12
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.ui.views/plugin.xml46
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.ui.views/src/org/eclipse/tcf/te/tcf/ui/views/help/IContextHelpIds.java5
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.ui.views/src/org/eclipse/tcf/te/tcf/ui/views/nls/Messages.java4
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.ui.views/src/org/eclipse/tcf/te/tcf/ui/views/nls/Messages.properties4
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.ui.views/src/org/eclipse/tcf/te/tcf/ui/views/scriptpad/ScriptPad.java243
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.ui.views/src/org/eclipse/tcf/te/tcf/ui/views/scriptpad/actions/ClearAction.java85
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.ui.views/src/org/eclipse/tcf/te/tcf/ui/views/scriptpad/actions/OpenAction.java96
9 files changed, 489 insertions, 7 deletions
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui.views/META-INF/MANIFEST.MF b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui.views/META-INF/MANIFEST.MF
index 672ae489e..e18a49c70 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui.views/META-INF/MANIFEST.MF
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui.views/META-INF/MANIFEST.MF
@@ -11,6 +11,7 @@ Require-Bundle: org.eclipse.core.runtime;bundle-version="3.7.0",
org.eclipse.tcf.core;bundle-version="1.0.0",
org.eclipse.tcf.te.tcf.locator;bundle-version="1.0.0",
org.eclipse.tcf.te.runtime;bundle-version="1.0.0",
+ org.eclipse.tcf.te.runtime.statushandler;bundle-version="1.0.0",
org.eclipse.tcf.te.ui;bundle-version="1.0.0",
org.eclipse.tcf.te.ui.swt;bundle-version="1.0.0",
org.eclipse.tcf.te.tcf.core.scripting;bundle-version="1.0.0",
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui.views/plugin.properties b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui.views/plugin.properties
index 7e91df362..32c62740c 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui.views/plugin.properties
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui.views/plugin.properties
@@ -32,8 +32,20 @@ command.delete.tooltip=Delete
command.selectall.label=Select &All
command.selectall.tooltip=Select All
+command.save.label=&Save
+command.save.tooltip=Save
+
+command.saveas.label=Save &As...
+command.saveas.tooltip=Save As
+
PeersSubMenuAction.label=Peers
PeersSubMenuAction.tooltip=Select the peer to play the script on.
PlayAction.label=Play
PlayAction.tooltip=Play the script on the selected peer.
+
+OpenAction.label=Open
+OpenAction.tooltip=Opens a script.
+
+ClearAction.label=Clear
+ClearAction.tooltip=Clear the content and resets the opened file path.
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui.views/plugin.xml b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui.views/plugin.xml
index bc1543416..15276aa92 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui.views/plugin.xml
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui.views/plugin.xml
@@ -66,7 +66,8 @@
id="org.eclipse.tcf.te.tcf.ui.scriptpad.toolbar.peers"
label="%PeersSubMenuAction.label"
style="pulldown"
- toolbarPath="peers">
+ toolbarPath="peers"
+ tooltip="%PeersSubMenuAction.tooltip">
</action>
<action
@@ -75,7 +76,29 @@
id="org.eclipse.tcf.te.tcf.ui.scriptpad.toolbar.play"
label="%PlayAction.label"
style="push"
- toolbarPath="play">
+ toolbarPath="play"
+ tooltip="%PlayAction.tooltip">
+ </action>
+
+ <action
+ class="org.eclipse.tcf.te.tcf.ui.views.scriptpad.actions.OpenAction"
+ icon="platform:/plugin/org.eclipse.ui/icons/full/obj16/fldr_obj.gif"
+ id="org.eclipse.tcf.te.tcf.ui.scriptpad.toolbar.open"
+ label="%OpenAction.label"
+ style="push"
+ toolbarPath="open"
+ tooltip="%OpenAction.tooltip">
+ </action>
+
+ <action
+ class="org.eclipse.tcf.te.tcf.ui.views.scriptpad.actions.ClearAction"
+ disabledIcon="platform:/plugin/org.eclipse.ui/icons/full/dtool16/clear.gif"
+ icon="platform:/plugin/org.eclipse.ui/icons/full/etool16/clear.gif"
+ id="org.eclipse.tcf.te.tcf.ui.scriptpad.toolbar.clear"
+ label="%ClearAction.label"
+ style="push"
+ toolbarPath="clear"
+ tooltip="%ClearAction.tooltip">
</action>
</viewContribution>
</extension>
@@ -123,6 +146,25 @@
tooltip="%command.selectall.tooltip">
</command>
</menuContribution>
+
+ <menuContribution locationURI="toolbar:org.eclipse.tcf.te.tcf.ui.views.scriptpad?after=save">
+ <command
+ commandId="org.eclipse.ui.file.save"
+ disabledIcon="platform:/plugin/org.eclipse.ui/icons/full/dtool16/save_edit.gif"
+ icon="platform:/plugin/org.eclipse.ui/icons/full/etool16/save_edit.gif"
+ label="%command.save.label"
+ style="push"
+ tooltip="%command.save.tooltip">
+ </command>
+ <command
+ commandId="org.eclipse.ui.file.saveAs"
+ disabledIcon="platform:/plugin/org.eclipse.ui/icons/full/dtool16/saveas_edit.gif"
+ icon="platform:/plugin/org.eclipse.ui/icons/full/etool16/saveas_edit.gif"
+ label="%command.saveas.label"
+ style="push"
+ tooltip="%command.saveas.tooltip">
+ </command>
+ </menuContribution>
</extension>
<!-- Script Pad event listener contributions -->
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui.views/src/org/eclipse/tcf/te/tcf/ui/views/help/IContextHelpIds.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui.views/src/org/eclipse/tcf/te/tcf/ui/views/help/IContextHelpIds.java
index a308d61b7..b524c1919 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui.views/src/org/eclipse/tcf/te/tcf/ui/views/help/IContextHelpIds.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui.views/src/org/eclipse/tcf/te/tcf/ui/views/help/IContextHelpIds.java
@@ -25,4 +25,9 @@ public interface IContextHelpIds {
* Script Pad console view.
*/
public final static String SCRIPT_PAD_CONSOLE_VIEW = PREFIX + "ScriptPadConsoleView"; //$NON-NLS-1$
+
+ /**
+ * Script Pad error: open failed
+ */
+ public final static String SCRIPT_PAD_ERROR_OPEN_FILE = PREFIX + "ScriptPadErrorOpenFile"; //$NON-NLS-1$
}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui.views/src/org/eclipse/tcf/te/tcf/ui/views/nls/Messages.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui.views/src/org/eclipse/tcf/te/tcf/ui/views/nls/Messages.java
index 2df9768e6..7cd7327fc 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui.views/src/org/eclipse/tcf/te/tcf/ui/views/nls/Messages.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui.views/src/org/eclipse/tcf/te/tcf/ui/views/nls/Messages.java
@@ -30,4 +30,8 @@ public class Messages extends NLS {
// **** Declare externalized string id's down here *****
public static String Console_name;
+
+ public static String ScriptPad_error_title;
+ public static String ScriptPad_error_openFile;
+ public static String ScriptPad_error_saveFile;
}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui.views/src/org/eclipse/tcf/te/tcf/ui/views/nls/Messages.properties b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui.views/src/org/eclipse/tcf/te/tcf/ui/views/nls/Messages.properties
index 75b83b88b..7e3068eea 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui.views/src/org/eclipse/tcf/te/tcf/ui/views/nls/Messages.properties
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui.views/src/org/eclipse/tcf/te/tcf/ui/views/nls/Messages.properties
@@ -4,3 +4,7 @@
#
Console_name=Script Pad Console
+
+ScriptPad_error_title=Error
+ScriptPad_error_openFile=Failed to open file ''{0}''.\n\nPossible cause:\n{1}
+ScriptPad_error_saveFile=Failed to save file ''{0}''.\n\nPossible cause:\n{1}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui.views/src/org/eclipse/tcf/te/tcf/ui/views/scriptpad/ScriptPad.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui.views/src/org/eclipse/tcf/te/tcf/ui/views/scriptpad/ScriptPad.java
index 3ce3ca205..74bf8d34c 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui.views/src/org/eclipse/tcf/te/tcf/ui/views/scriptpad/ScriptPad.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui.views/src/org/eclipse/tcf/te/tcf/ui/views/scriptpad/ScriptPad.java
@@ -9,11 +9,21 @@
*******************************************************************************/
package org.eclipse.tcf.te.tcf.ui.views.scriptpad;
+import java.io.File;
+import java.io.FileReader;
+import java.io.FileWriter;
+import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.eclipse.core.runtime.Assert;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.action.GroupMarker;
import org.eclipse.jface.action.IMenuListener;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.IToolBarManager;
@@ -26,23 +36,39 @@ import org.eclipse.jface.viewers.ISelectionProvider;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CaretEvent;
import org.eclipse.swt.custom.CaretListener;
import org.eclipse.swt.custom.StyledText;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.FileDialog;
+import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Menu;
+import org.eclipse.tcf.te.runtime.interfaces.properties.IPropertiesContainer;
+import org.eclipse.tcf.te.runtime.properties.PropertiesContainer;
+import org.eclipse.tcf.te.runtime.statushandler.StatusHandlerManager;
+import org.eclipse.tcf.te.runtime.statushandler.interfaces.IStatusHandler;
+import org.eclipse.tcf.te.runtime.statushandler.interfaces.IStatusHandlerConstants;
import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerModel;
+import org.eclipse.tcf.te.tcf.ui.views.activator.UIPlugin;
+import org.eclipse.tcf.te.tcf.ui.views.help.IContextHelpIds;
+import org.eclipse.tcf.te.tcf.ui.views.nls.Messages;
import org.eclipse.tcf.te.tcf.ui.views.scriptpad.actions.CopyAction;
import org.eclipse.tcf.te.tcf.ui.views.scriptpad.actions.CutAction;
import org.eclipse.tcf.te.tcf.ui.views.scriptpad.actions.DeleteAction;
import org.eclipse.tcf.te.tcf.ui.views.scriptpad.actions.PasteAction;
import org.eclipse.tcf.te.tcf.ui.views.scriptpad.actions.SelectAllAction;
import org.eclipse.tcf.te.ui.swt.DisplayUtil;
+import org.eclipse.tcf.te.ui.swt.SWTControlUtil;
import org.eclipse.ui.IActionBars;
+import org.eclipse.ui.ISaveablePart;
import org.eclipse.ui.IWorkbenchActionConstants;
import org.eclipse.ui.IWorkbenchPartConstants;
import org.eclipse.ui.actions.ActionFactory;
@@ -51,8 +77,10 @@ import org.eclipse.ui.part.ViewPart;
/**
* Script Pad view implementation.
*/
-public class ScriptPad extends ViewPart implements ISelectionProvider, SelectionListener {
- // Reference to the Text widget used by the script pad
+public class ScriptPad extends ViewPart implements ISelectionProvider, SelectionListener, ISaveablePart {
+ // Reference to the header line
+ private Label head;
+ // Reference to the Text widget
private StyledText text;
// The list of registered selection changed listeners
@@ -68,6 +96,13 @@ public class ScriptPad extends ViewPart implements ISelectionProvider, Selection
/* default */ DeleteAction deleteHandler;
private SelectAllAction selectAllHandler;
+ // If the user loaded a script either via the "Open" action or DnD, remember the file name
+ // so the user can save it back.
+ private String fileLoaded = null;
+
+ // The dirty state
+ private boolean dirty = false;
+
/**
* Constructor.
*/
@@ -85,6 +120,7 @@ public class ScriptPad extends ViewPart implements ISelectionProvider, Selection
text.removeSelectionListener(this);
}
listeners.clear();
+ fileLoaded = null;
super.dispose();
}
@@ -93,8 +129,18 @@ public class ScriptPad extends ViewPart implements ISelectionProvider, Selection
*/
@Override
public void createPartControl(Composite parent) {
+ Composite panel = new Composite(parent, SWT.NONE);
+ GridLayout layout = new GridLayout();
+ layout.marginHeight = 0; layout.marginWidth = 0;
+ panel.setLayout(layout);
+ panel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+
+ // Create the head label
+ head = new Label(panel, SWT.HORIZONTAL);
+ head.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
+
// Create the StyledText widget
- text = new StyledText(parent, SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI);
+ text = new StyledText(panel, SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI);
text.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
text.setFont(JFaceResources.getTextFont());
text.addSelectionListener(this);
@@ -104,6 +150,12 @@ public class ScriptPad extends ViewPart implements ISelectionProvider, Selection
if (deleteHandler != null) deleteHandler.updateEnabledState();
}
});
+ text.addModifyListener(new ModifyListener() {
+ @Override
+ public void modifyText(ModifyEvent e) {
+ if (!isDirty()) markDirty(true);
+ }
+ });
// Register ourselves as selection provider
getViewSite().setSelectionProvider(this);
@@ -180,8 +232,15 @@ public class ScriptPad extends ViewPart implements ISelectionProvider, Selection
*/
private void createToolbar() {
IToolBarManager manager = getViewSite().getActionBars().getToolBarManager();
- manager.add(new Separator("peers")); //$NON-NLS-1$
- manager.add(new Separator("play")); //$NON-NLS-1$
+ manager.add(new Separator());
+ manager.add(new GroupMarker("open")); //$NON-NLS-1$
+ manager.add(new GroupMarker("save")); //$NON-NLS-1$
+ manager.add(new Separator());
+ manager.add(new GroupMarker("clear")); //$NON-NLS-1$
+ manager.add(new Separator());
+ manager.add(new GroupMarker("play")); //$NON-NLS-1$
+ manager.add(new Separator());
+ manager.add(new GroupMarker("peers")); //$NON-NLS-1$
manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
}
@@ -267,6 +326,18 @@ public class ScriptPad extends ViewPart implements ISelectionProvider, Selection
if (selectAllHandler != null) selectAllHandler.updateEnabledState();
}
+ /**
+ * Update the head label
+ */
+ protected void updateHeadLabel() {
+ if (fileLoaded == null) {
+ SWTControlUtil.setText(head, ""); //$NON-NLS-1$
+ } else {
+ IPath path = new Path(fileLoaded);
+ SWTControlUtil.setText(head, path.lastSegment() + " - " + path.removeLastSegments(1).toOSString()); //$NON-NLS-1$
+ }
+ }
+
/* (non-Javadoc)
* @see org.eclipse.swt.events.SelectionListener#widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent)
*/
@@ -319,4 +390,166 @@ public class ScriptPad extends ViewPart implements ISelectionProvider, Selection
public StyledText getStyledText() {
return text;
}
+
+ /**
+ * Sets the dirty state.
+ *
+ * @param dirty <code>True</code> to mark the view dirty, <code>false</code> otherwise.
+ */
+ public void markDirty(boolean dirty) {
+ if (this.dirty != dirty) {
+ this.dirty = dirty;
+ firePropertyChange(IWorkbenchPartConstants.PROP_DIRTY);
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.ISaveablePart#isDirty()
+ */
+ @Override
+ public boolean isDirty() {
+ return dirty;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.ISaveablePart#doSave(org.eclipse.core.runtime.IProgressMonitor)
+ */
+ @Override
+ public void doSave(IProgressMonitor monitor) {
+ if (fileLoaded != null) saveFile(fileLoaded);
+ else doSaveAs();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.ISaveablePart#doSaveAs()
+ */
+ @Override
+ public void doSaveAs() {
+ FileDialog dialog = new FileDialog(getViewSite().getShell(), SWT.SAVE);
+ dialog.setFilterExtensions(new String[] { "*.tcf", "*" }); //$NON-NLS-1$ //$NON-NLS-2$
+ dialog.setFilterPath(fileLoaded != null ? fileLoaded : System.getProperty("user.home")); //$NON-NLS-1$
+ String file = dialog.open();
+ if (file != null) {
+ saveFile(file);
+ // Save succeeded ?
+ if (!isDirty()) {
+ fileLoaded = file;
+ updateHeadLabel();
+ }
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.ISaveablePart#isSaveAsAllowed()
+ */
+ @Override
+ public boolean isSaveAsAllowed() {
+ return true;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.ISaveablePart#isSaveOnCloseNeeded()
+ */
+ @Override
+ public boolean isSaveOnCloseNeeded() {
+ return isDirty();
+ }
+
+ /**
+ * Clears all content and reset the loaded file path.
+ */
+ public void clear() {
+ this.fileLoaded = null;
+ updateHeadLabel();
+ if (text != null && !text.isDisposed()) text.setText(""); //$NON-NLS-1$
+ }
+
+ /**
+ * Opens the file.
+ *
+ * @param file The absolute file name of the script to load. Must not be <code>null</code>.
+ */
+ public void openFile(String file) {
+ Assert.isNotNull(file);
+
+ // The file name must be absolute and denote a readable file
+ File f = new File(file);
+ if (f.isAbsolute() && f.isFile() && f.canRead()) {
+ // Remember the file name
+ this.fileLoaded = file;
+ updateHeadLabel();
+ // Clear out the old text
+ text.setText(""); //$NON-NLS-1$
+
+ FileReader reader = null;
+ try {
+ reader = new FileReader(f);
+ StringBuilder buffer = new StringBuilder();
+ int c;
+ while ((c = reader.read()) != -1) {
+ buffer.append((char)c);
+ }
+ text.setText(buffer.toString());
+ markDirty(false);
+ } catch (Exception e) {
+ IStatus status = new Status(IStatus.ERROR, UIPlugin.getUniqueIdentifier(),
+ NLS.bind(Messages.ScriptPad_error_openFile, file, e.getLocalizedMessage()), e);
+
+ IStatusHandler[] handlers = StatusHandlerManager.getInstance().getHandler(this);
+ if (handlers.length > 0) {
+ IPropertiesContainer data = new PropertiesContainer();
+ data.setProperty(IStatusHandlerConstants.PROPERTY_TITLE, Messages.ScriptPad_error_title);
+ data.setProperty(IStatusHandlerConstants.PROPERTY_CONTEXT_HELP_ID, IContextHelpIds.SCRIPT_PAD_ERROR_OPEN_FILE);
+ data.setProperty(IStatusHandlerConstants.PROPERTY_CALLER, this);
+
+ handlers[0].handleStatus(status, data, null);
+ } else {
+ UIPlugin.getDefault().getLog().log(status);
+ }
+ } finally {
+ if (reader != null) try { reader.close(); } catch (IOException e) { /* ignored on purpose */ }
+ }
+ }
+ updateActionEnablements();
+ }
+
+ /**
+ * Saves the file.
+ *
+ * @param file The absolute file name to save the script to. Must not be <code>null</code>.
+ */
+ public void saveFile(String file) {
+ Assert.isNotNull(file);
+
+ // The file name must be absolute and denote a writable file
+ File f = new File(file);
+ if (f.isAbsolute() && ((f.exists() && f.isFile() && f.canWrite() || !f.exists()))) {
+ String content = text.getText();
+
+ FileWriter writer = null;
+ try {
+ writer = new FileWriter(f);
+ writer.write(content);
+ markDirty(false);
+ } catch (Exception e) {
+ IStatus status = new Status(IStatus.ERROR, UIPlugin.getUniqueIdentifier(),
+ NLS.bind(Messages.ScriptPad_error_saveFile, file, e.getLocalizedMessage()), e);
+
+ IStatusHandler[] handlers = StatusHandlerManager.getInstance().getHandler(this);
+ if (handlers.length > 0) {
+ IPropertiesContainer data = new PropertiesContainer();
+ data.setProperty(IStatusHandlerConstants.PROPERTY_TITLE, Messages.ScriptPad_error_title);
+ data.setProperty(IStatusHandlerConstants.PROPERTY_CONTEXT_HELP_ID, IContextHelpIds.SCRIPT_PAD_ERROR_OPEN_FILE);
+ data.setProperty(IStatusHandlerConstants.PROPERTY_CALLER, this);
+
+ handlers[0].handleStatus(status, data, null);
+ } else {
+ UIPlugin.getDefault().getLog().log(status);
+ }
+ } finally {
+ if (writer != null) try { writer.close(); } catch (IOException e) { /* ignored on purpose */ }
+ }
+ }
+ updateActionEnablements();
+ }
}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui.views/src/org/eclipse/tcf/te/tcf/ui/views/scriptpad/actions/ClearAction.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui.views/src/org/eclipse/tcf/te/tcf/ui/views/scriptpad/actions/ClearAction.java
new file mode 100644
index 000000000..11e96edfb
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui.views/src/org/eclipse/tcf/te/tcf/ui/views/scriptpad/actions/ClearAction.java
@@ -0,0 +1,85 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Wind River Systems, Inc. and others. All rights reserved.
+ * This program and the accompanying materials are made available under the terms
+ * of the Eclipse Public License v1.0 which accompanies this distribution, and is
+ * available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Wind River Systems - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.tcf.te.tcf.ui.views.scriptpad.actions;
+
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.tcf.te.tcf.ui.views.scriptpad.ScriptPad;
+import org.eclipse.ui.IActionDelegate2;
+import org.eclipse.ui.IViewActionDelegate;
+import org.eclipse.ui.IViewPart;
+
+/**
+ * Clear script action implementation.
+ */
+public class ClearAction extends Action implements IViewActionDelegate, IActionDelegate2 {
+ // Reference to the action proxy
+ /* default */ IAction actionProxy;
+ // Parent view part
+ /* default */ IViewPart view;
+
+ /**
+ * Constructor.
+ */
+ public ClearAction() {
+ super();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.IViewActionDelegate#init(org.eclipse.ui.IViewPart)
+ */
+ @Override
+ public void init(IViewPart view) {
+ this.view = view;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.IActionDelegate2#init(org.eclipse.jface.action.IAction)
+ */
+ @Override
+ public void init(IAction action) {
+ this.actionProxy = action;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
+ */
+ @Override
+ public void run(IAction action) {
+ if (view instanceof ScriptPad) {
+ ((ScriptPad)view).clear();
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.IActionDelegate2#runWithEvent(org.eclipse.jface.action.IAction, org.eclipse.swt.widgets.Event)
+ */
+ @Override
+ public void runWithEvent(IAction action, Event event) {
+ run(action);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection)
+ */
+ @Override
+ public void selectionChanged(IAction action, ISelection selection) {
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.IActionDelegate2#dispose()
+ */
+ @Override
+ public void dispose() {
+ }
+}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui.views/src/org/eclipse/tcf/te/tcf/ui/views/scriptpad/actions/OpenAction.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui.views/src/org/eclipse/tcf/te/tcf/ui/views/scriptpad/actions/OpenAction.java
new file mode 100644
index 000000000..45bacf2ed
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui.views/src/org/eclipse/tcf/te/tcf/ui/views/scriptpad/actions/OpenAction.java
@@ -0,0 +1,96 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Wind River Systems, Inc. and others. All rights reserved.
+ * This program and the accompanying materials are made available under the terms
+ * of the Eclipse Public License v1.0 which accompanies this distribution, and is
+ * available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Wind River Systems - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.tcf.te.tcf.ui.views.scriptpad.actions;
+
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.FileDialog;
+import org.eclipse.tcf.te.tcf.ui.views.scriptpad.ScriptPad;
+import org.eclipse.ui.IActionDelegate2;
+import org.eclipse.ui.IViewActionDelegate;
+import org.eclipse.ui.IViewPart;
+
+/**
+ * Open script action implementation.
+ */
+public class OpenAction extends Action implements IViewActionDelegate, IActionDelegate2 {
+ // Reference to the action proxy
+ /* default */ IAction actionProxy;
+ // Parent view part
+ /* default */ IViewPart view;
+
+ // Remember the last file path opened
+ private String lastFile = null;
+
+ /**
+ * Constructor.
+ */
+ public OpenAction() {
+ super();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.IViewActionDelegate#init(org.eclipse.ui.IViewPart)
+ */
+ @Override
+ public void init(IViewPart view) {
+ this.view = view;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.IActionDelegate2#init(org.eclipse.jface.action.IAction)
+ */
+ @Override
+ public void init(IAction action) {
+ this.actionProxy = action;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
+ */
+ @Override
+ public void run(IAction action) {
+ // Open a file open dialog
+ FileDialog dialog = new FileDialog(view.getViewSite().getShell(), SWT.OPEN);
+ dialog.setFilterExtensions(new String[] { "*.tcf", "*" }); //$NON-NLS-1$ //$NON-NLS-2$
+ dialog.setFilterPath(lastFile != null ? lastFile : System.getProperty("user.home")); //$NON-NLS-1$
+ String file = dialog.open();
+ if (file != null && view instanceof ScriptPad) {
+ lastFile = file;
+ ((ScriptPad)view).openFile(file);
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.IActionDelegate2#runWithEvent(org.eclipse.jface.action.IAction, org.eclipse.swt.widgets.Event)
+ */
+ @Override
+ public void runWithEvent(IAction action, Event event) {
+ run(action);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection)
+ */
+ @Override
+ public void selectionChanged(IAction action, ISelection selection) {
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.IActionDelegate2#dispose()
+ */
+ @Override
+ public void dispose() {
+ }
+}

Back to the top