Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te')
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/handler/AbstractEditorCommandHandler.java85
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/handler/AbstractStepperCommandHandler.java9
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/handler/ConnectableCommandHandler.java9
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/nls/Messages.java3
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/nls/Messages.properties4
5 files changed, 100 insertions, 10 deletions
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/handler/AbstractEditorCommandHandler.java b/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/handler/AbstractEditorCommandHandler.java
new file mode 100644
index 000000000..50b30870f
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/handler/AbstractEditorCommandHandler.java
@@ -0,0 +1,85 @@
+/*******************************************************************************
+ * Copyright (c) 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
+ *
+ * Contributors:
+ * Wind River Systems - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.tcf.te.ui.handler;
+
+import java.util.Map;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IExecutableExtension;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.tcf.te.ui.jface.dialogs.OptionalMessageDialog;
+import org.eclipse.tcf.te.ui.nls.Messages;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.handlers.HandlerUtil;
+import org.eclipse.ui.part.EditorPart;
+
+/**
+ * Connectable command handler implementation.
+ */
+public abstract class AbstractEditorCommandHandler extends AbstractHandler implements IExecutableExtension {
+
+ protected static final String PARAM_HANDLE_DIRTY = "handleDirty"; //$NON-NLS-1$
+
+ protected boolean handleDirty = false;
+
+ /* (non-Javadoc)
+ * @see com.windriver.te.tcf.ui.handler.AbstractAgentCommandHandler#execute(org.eclipse.core.commands.ExecutionEvent)
+ */
+ @Override
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+
+ if (handleDirty(event)) {
+ IWorkbenchPart part = HandlerUtil.getActivePart(event);
+ if (part instanceof EditorPart) {
+ if (((EditorPart)part).isDirty()) {
+ int result = OptionalMessageDialog.openYesNoCancelDialog(
+ HandlerUtil.getActiveShell(event),
+ Messages.AbstractEditorCommandHandler_saveDialog_title,
+ NLS.bind(Messages.AbstractEditorCommandHandler_saveDialog_message, ((EditorPart)part).getTitle()),
+ null, null);
+ switch (result) {
+ case IDialogConstants.YES_ID:
+ ((EditorPart)part).doSave(null);
+ break;
+ case IDialogConstants.CANCEL_ID:
+ return null;
+ }
+ }
+ }
+ }
+
+ return internalExecute(event);
+ }
+
+ protected abstract Object internalExecute(ExecutionEvent event) throws ExecutionException;
+
+ protected boolean handleDirty(ExecutionEvent event) {
+ return handleDirty;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.core.runtime.IExecutableExtension#setInitializationData(org.eclipse.core.runtime.IConfigurationElement, java.lang.String, java.lang.Object)
+ */
+ @Override
+ public void setInitializationData(IConfigurationElement config, String propertyName, Object data) throws CoreException {
+ if (data instanceof Map) {
+ Map<?,?> dataMap = (Map<?,?>)data;
+ if (dataMap.get(PARAM_HANDLE_DIRTY) instanceof String) {
+ String value = dataMap.get(PARAM_HANDLE_DIRTY).toString().trim();
+ this.handleDirty = Boolean.parseBoolean(value);
+ }
+ }
+ }
+}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/handler/AbstractStepperCommandHandler.java b/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/handler/AbstractStepperCommandHandler.java
index a243cbb65..afefc5ffd 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/handler/AbstractStepperCommandHandler.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/handler/AbstractStepperCommandHandler.java
@@ -14,13 +14,11 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;
-import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
-import org.eclipse.core.runtime.IExecutableExtension;
import org.eclipse.core.runtime.Platform;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
@@ -43,7 +41,7 @@ import org.eclipse.ui.part.EditorPart;
/**
* Stepper command handler implementation.
*/
-public abstract class AbstractStepperCommandHandler extends AbstractHandler implements IExecutableExtension {
+public abstract class AbstractStepperCommandHandler extends AbstractEditorCommandHandler {
protected String operation = null;
protected String adaptTo = null;
@@ -54,10 +52,10 @@ public abstract class AbstractStepperCommandHandler extends AbstractHandler impl
public static final String PART_ID_PROJECT_VIEW = "org.eclipse.ui.navigator.ProjectExplorer"; //$NON-NLS-1$
/* (non-Javadoc)
- * @see com.windriver.te.tcf.ui.handler.AbstractAgentCommandHandler#execute(org.eclipse.core.commands.ExecutionEvent)
+ * @see org.eclipse.tcf.te.ui.handler.AbstractEditorCommandHandler#internalExecute(org.eclipse.core.commands.ExecutionEvent)
*/
@Override
- public Object execute(ExecutionEvent event) throws ExecutionException {
+ protected Object internalExecute(ExecutionEvent event) throws ExecutionException {
Assert.isNotNull(operation);
IPropertiesContainer data = getData(event);
@@ -166,6 +164,7 @@ public abstract class AbstractStepperCommandHandler extends AbstractHandler impl
*/
@Override
public void setInitializationData(IConfigurationElement config, String propertyName, Object data) throws CoreException {
+ super.setInitializationData(config, propertyName, data);
if (data instanceof Map) {
Map<?,?> dataMap = (Map<?,?>)data;
if (dataMap.get("operation") instanceof String) { //$NON-NLS-1$
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/handler/ConnectableCommandHandler.java b/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/handler/ConnectableCommandHandler.java
index dca89b68d..bfda04ef6 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/handler/ConnectableCommandHandler.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/handler/ConnectableCommandHandler.java
@@ -12,13 +12,11 @@ package org.eclipse.tcf.te.ui.handler;
import java.util.Iterator;
import java.util.Map;
-import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
-import org.eclipse.core.runtime.IExecutableExtension;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.tcf.te.core.interfaces.IConnectable;
@@ -28,17 +26,17 @@ import org.eclipse.ui.handlers.HandlerUtil;
/**
* Connectable command handler implementation.
*/
-public class ConnectableCommandHandler extends AbstractHandler implements IExecutableExtension {
+public class ConnectableCommandHandler extends AbstractEditorCommandHandler {
protected static final String PARAM_ACTION = "action"; //$NON-NLS-1$
protected int action = IConnectable.STATE_UNKNOWN;
/* (non-Javadoc)
- * @see com.windriver.te.tcf.ui.handler.AbstractAgentCommandHandler#execute(org.eclipse.core.commands.ExecutionEvent)
+ * @see org.eclipse.tcf.te.ui.handler.AbstractEditorCommandHandler#internalExecute(org.eclipse.core.commands.ExecutionEvent)
*/
@Override
- public Object execute(ExecutionEvent event) throws ExecutionException {
+ public Object internalExecute(ExecutionEvent event) throws ExecutionException {
Assert.isTrue(action >= 0);
ISelection selection = HandlerUtil.getCurrentSelection(event);
@@ -64,6 +62,7 @@ public class ConnectableCommandHandler extends AbstractHandler implements IExecu
*/
@Override
public void setInitializationData(IConfigurationElement config, String propertyName, Object data) throws CoreException {
+ super.setInitializationData(config, propertyName, data);
if (data instanceof Map) {
Map<?,?> dataMap = (Map<?,?>)data;
if (dataMap.get(PARAM_ACTION) instanceof String) {
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/nls/Messages.java b/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/nls/Messages.java
index eab2a3372..225246559 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/nls/Messages.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/nls/Messages.java
@@ -95,4 +95,7 @@ public class Messages extends NLS {
public static String ViewerStateManager_MkdirFailed;
public static String TriggerCommandEventListener_error_executionFailed;
+
+ public static String AbstractEditorCommandHandler_saveDialog_title;
+ public static String AbstractEditorCommandHandler_saveDialog_message;
}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/nls/Messages.properties b/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/nls/Messages.properties
index 7b1e12783..e4da7aa6a 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/nls/Messages.properties
+++ b/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/nls/Messages.properties
@@ -85,3 +85,7 @@ ViewerStateManager_MkdirFailed=Making the directory for viewerstate.xml failed\!
TriggerCommandEventListener_error_executionFailed=Failed to execute command {0}.
+# ***** Handler *****
+
+AbstractEditorCommandHandler_saveDialog_title=Save Resource
+AbstractEditorCommandHandler_saveDialog_message=''{0}'' has been modified. Save changes?

Back to the top