01: /**
02: *
03: */package newprocess.diagram.cust.annotations.actions;
04:
05: import newprocess.diagram.cust.annotations.commands.WriteCommand;
06: import newprocess.diagram.cust.annotations.dialogs.ElementChooserDialog;
07: import newprocess.diagram.cust.annotations.utils.URIConvertUtil;
08:
09: import org.eclipse.core.resources.IFile;
10: import org.eclipse.gef.EditPart;
11: import org.eclipse.gmf.runtime.diagram.ui.editpolicies.DecorationEditPolicy;
12: import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles;
13: import org.eclipse.jface.action.Action;
14: import org.eclipse.jface.resource.ImageDescriptor;
15: import org.eclipse.swt.widgets.Shell;
16: import org.eclipse.ui.PlatformUI;
17:
18: /**
19: * @author sh
20: *
21: */
22: public class LinkToAction extends Action {
23: private EditPart selectedEditPart = null;
24: private String projectName = null;
25:
26: /**
27: * Constructor
28: */
29: public LinkToAction(String text, ImageDescriptor imageDescriptor,
30: EditPart selectedEditPart, String projectName) {
31: super (text, imageDescriptor);
32: this .selectedEditPart = selectedEditPart;
33: this .projectName = projectName;
34: }
35:
36: /**
37: * runs the action an opens the Workspace selection dialog
38: */
39: @Override
40: public void run() {
41: super .run();
42:
43: // open the Workspace Selection Dialog
44: Shell shell = PlatformUI.getWorkbench()
45: .getActiveWorkbenchWindow().getShell();
46: ElementChooserDialog chooserDia = new ElementChooserDialog(
47: shell);
48: chooserDia.open();
49:
50: // opens the selection dialog and fetch the project/file
51: String project = chooserDia.getSelectedProject();
52: IFile file = chooserDia.getSelectedFile();
53: if ((project == null) || (file == null)
54: || (projectName == null))
55: return;
56:
57: // get the relative path for the created file
58: URIConvertUtil uriUtil = new URIConvertUtil();
59: String path = uriUtil
60: .getPathForFile(file, projectName, project);
61:
62: // Write the Annotation to the model
63: WriteCommand writeCommand = new WriteCommand();
64: writeCommand.executeWriteCommand(selectedEditPart, path);
65:
66: // notify the decorator
67: Object editPolicy = selectedEditPart
68: .getEditPolicy(EditPolicyRoles.DECORATION_ROLE);
69: if (editPolicy instanceof DecorationEditPolicy) {
70: ((DecorationEditPolicy) editPolicy).refresh();
71: }
72: }
73: }
|