01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
03: */
04: package org.terracotta.dso.views;
05:
06: import org.eclipse.jdt.internal.ui.util.SelectionUtil;
07: import org.eclipse.jface.action.Action;
08: import org.eclipse.jface.dialogs.InputDialog;
09: import org.eclipse.jface.dialogs.MessageDialog;
10: import org.eclipse.jface.viewers.ISelection;
11: import org.eclipse.jface.viewers.ISelectionProvider;
12: import org.eclipse.jface.window.Window;
13: import org.eclipse.swt.widgets.Shell;
14: import org.eclipse.ui.actions.ActionContext;
15: import org.terracotta.dso.actions.ActionUtil;
16:
17: public class EditLockExpressionAction extends Action {
18: ConfigViewPart fPart;
19:
20: EditLockExpressionAction(ConfigViewPart part) {
21: super ("Edit expression...");
22: fPart = part;
23: }
24:
25: public void run() {
26: LockWrapper wrapper = (LockWrapper) SelectionUtil
27: .getSingleElement(getSelection());
28: Shell shell = ActionUtil.findSelectedEditorPart().getSite()
29: .getShell();
30: String title = "Lock expression pattern";
31: String dialogMessage = "Specify lock expression";
32: String initialValue = wrapper.toString();
33:
34: InputDialog dialog = new InputDialog(shell, title,
35: dialogMessage, initialValue, null);
36: if (dialog.open() == Window.OK) {
37: String expr = dialog.getValue();
38:
39: if (expr != null && (expr = expr.trim()) != null
40: && expr.length() > 0) {
41: fPart.setLockExpression(expr);
42: } else if (MessageDialog.openQuestion(shell, title,
43: "Remove lock '" + wrapper.getMethodExpression()
44: + "'?")) {
45: fPart.removeSelectedItem();
46: }
47: }
48: }
49:
50: public void setContext(ActionContext context) {
51: /**/
52: }
53:
54: public boolean canActionBeAdded() {
55: Object element = SelectionUtil.getSingleElement(getSelection());
56: return element instanceof LockWrapper;
57: }
58:
59: private ISelection getSelection() {
60: ISelectionProvider provider = fPart.getSite()
61: .getSelectionProvider();
62:
63: if (provider != null) {
64: return provider.getSelection();
65: }
66:
67: return null;
68: }
69: }
|