KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > terracotta > dso > views > EditIncludePatternAction


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4 package org.terracotta.dso.views;
5
6 import org.eclipse.jdt.internal.ui.util.SelectionUtil;
7 import org.eclipse.jface.action.Action;
8 import org.eclipse.jface.dialogs.InputDialog;
9 import org.eclipse.jface.viewers.ISelection;
10 import org.eclipse.jface.viewers.ISelectionProvider;
11 import org.eclipse.jface.window.Window;
12 import org.eclipse.swt.widgets.Shell;
13 import org.eclipse.ui.actions.ActionContext;
14 import org.terracotta.dso.actions.ActionUtil;
15
16 public class EditIncludePatternAction extends Action {
17   ConfigViewPart fPart;
18   
19   EditIncludePatternAction(ConfigViewPart part) {
20     super("Edit expression...");
21     fPart = part;
22   }
23   
24   public void run() {
25     IncludeWrapper wrapper = (IncludeWrapper)SelectionUtil.getSingleElement(getSelection());
26     Shell shell = ActionUtil.findSelectedEditorPart().getSite().getShell();
27     String JavaDoc title = "Include expression";
28     String JavaDoc dialogMessage = "Specify include expression";
29     String JavaDoc initialValue = wrapper.toString();
30     
31     InputDialog dialog = new InputDialog(shell, title, dialogMessage, initialValue, null);
32     if(dialog.open() == Window.OK) {
33       fPart.setIncludeExpression(dialog.getValue());
34     }
35   }
36
37   public void setContext(ActionContext context) {
38     /**/
39   }
40
41   public boolean canActionBeAdded() {
42     Object JavaDoc element = SelectionUtil.getSingleElement(getSelection());
43     return element instanceof IncludeWrapper;
44   }
45   
46   private ISelection getSelection() {
47     ISelectionProvider provider = fPart.getSite().getSelectionProvider();
48
49     if(provider != null) {
50       return provider.getSelection();
51     }
52
53     return null;
54   }
55 }
56
Popular Tags