1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 /***
19 * <p>Title: WSMO Studio</p>
20 * <p>Description: Semantic Web Service Editor</p>
21 * <p>Copyright: Copyright (c) 2004-2006</p>
22 * <p>Company: OntoText Lab. / SIRMA </p>
23 */
24
25 package org.wsmostudio.ui;
26
27 import org.eclipse.core.resources.IProject;
28 import org.eclipse.core.runtime.*;
29 import org.eclipse.jface.action.IAction;
30 import org.eclipse.jface.dialogs.*;
31 import org.eclipse.jface.viewers.*;
32 import org.eclipse.ui.*;
33 import org.wsmostudio.runtime.*;
34
35 public class ProjectNamespaceAction implements IObjectActionDelegate {
36
37 public static final QualifiedName PROJECT_NAMESPACE_NAME = new QualifiedName("WS", "project_namespace_name");
38 private IProject selected = null;
39 private IWorkbenchPart uiPart = null;
40
41 public ProjectNamespaceAction() {
42 }
43
44 public void setActivePart(IAction action, IWorkbenchPart targetPart) {
45 this.uiPart = targetPart;
46 }
47
48 public void run(IAction action) {
49 if (false == selected.isAccessible()) {
50 MessageDialog.openError(
51 this.uiPart.getSite().getShell(),
52 "Project Not Accessible",
53 "The selected project ("
54 + this.selected.getName()
55 +") in either closed or it does not exist!");
56 return;
57 }
58 String projectNS = null;
59 try {
60 projectNS = selected.getPersistentProperty(PROJECT_NAMESPACE_NAME);
61 if (projectNS == null) {
62 projectNS = "";
63 }
64 }
65 catch(CoreException coreEx) {
66 LogManager.logError(coreEx);
67 }
68 InputDialog iDialog = new InputDialog(this.uiPart.getSite().getShell(),
69 "Project Default Namespace",
70 "Namespace URI : ",
71 projectNS,
72 new IInputValidator() {
73 public String isValid(String input) {
74 if (input.trim().length() == 0) {
75 return null;
76 }
77 try {
78 WSMORuntime.getRuntime().getWsmoFactory().createIRI(input);
79 }
80 catch(Throwable ex) {
81 return ex.getMessage();
82 }
83 return null;
84 }
85 });
86 if (iDialog.open() != Dialog.OK) {
87 return;
88 }
89 String newNS = iDialog.getValue();
90 if (newNS.equals(projectNS)) {
91 return;
92 }
93 try {
94 selected.setPersistentProperty(PROJECT_NAMESPACE_NAME, newNS);
95 }
96 catch(CoreException coreEx) {
97 LogManager.logError(coreEx);
98 }
99 }
100
101 public void selectionChanged(IAction action, ISelection selection) {
102
103 if (selection.isEmpty()
104 || false == selection instanceof IStructuredSelection) {
105 this.selected = null;
106 return;
107 }
108 IStructuredSelection sSel = (IStructuredSelection)selection;
109 if (sSel.size() != 1
110 || false == sSel.getFirstElement() instanceof IProject) {
111 this.selected = null;
112 }
113 this.selected = (IProject)sSel.getFirstElement();
114 }
115
116 }
117
118
119
120
121
122
123
124