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.*;
28 import org.eclipse.core.runtime.CoreException;
29 import org.eclipse.jface.action.IAction;
30 import org.eclipse.jface.resource.JFaceResources;
31 import org.eclipse.jface.viewers.ISelection;
32 import org.eclipse.swt.SWT;
33 import org.eclipse.swt.events.*;
34 import org.eclipse.swt.graphics.*;
35 import org.eclipse.swt.layout.*;
36 import org.eclipse.swt.widgets.*;
37 import org.eclipse.ui.*;
38 import org.wsmostudio.runtime.*;
39 import org.wsmostudio.runtime.io.WorkspaceIOManager;
40
41 public class ClearProblemsAction implements IViewActionDelegate {
42
43 private boolean[] cleanMask = new boolean[] { false, false, false };
44 private Shell shell, parentShell;
45
46 public void init(IViewPart view) {
47 this.parentShell = view.getSite().getShell();
48 }
49
50 public void run(IAction action) {
51
52 shell = new Shell(parentShell, SWT.DIALOG_TRIM | SWT.RESIZE | SWT.SYSTEM_MODAL);
53 shell.setLayout(new GridLayout(1, false));
54 Group topGroup = new Group(shell, SWT.NONE);
55 topGroup.setLayoutData(new GridData(GridData.FILL_BOTH));
56 topGroup.setText("Select Items to Remove");
57 topGroup.setLayout(new GridLayout(1, false));
58
59 Button button = new Button(topGroup, SWT.CHECK);
60 button.setText("Error Messages");
61 button.setSelection(false);
62 button.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_RED));
63 button.addSelectionListener(new SelectionAdapter() {
64 public void widgetSelected(SelectionEvent e) {
65 cleanMask[0] = ((Button)e.widget).getSelection();
66 }
67 });
68
69 button = new Button(topGroup, SWT.CHECK);
70 button.setText("Warning Messages");
71 button.setSelection(false);
72 button.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_YELLOW));
73 button.addSelectionListener(new SelectionAdapter() {
74 public void widgetSelected(SelectionEvent e) {
75 cleanMask[1] = ((Button)e.widget).getSelection();
76 }
77 });
78
79 button = new Button(topGroup, SWT.CHECK);
80 button.setText("Info Messages");
81 button.setSelection(false);
82 button.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_BLUE));
83 button.addSelectionListener(new SelectionAdapter() {
84 public void widgetSelected(SelectionEvent e) {
85 cleanMask[2] = ((Button)e.widget).getSelection();
86 }
87 });
88
89 createControlArea(shell);
90
91 Image icon = JFaceResources.getImageRegistry().get(WsmoImageRegistry.DEFAULT_WINDOW_ICON);
92 shell.setImage(icon);
93 shell.setText("Clear Errors");
94 shell.pack();
95
96 Point pLocation = parentShell.getLocation();
97 Point pSize = parentShell.getSize();
98 shell.setLocation(pLocation.x + pSize.x / 2 - shell.getSize().x / 2,
99 pLocation.y + pSize.y / 2 - shell.getSize().y / 2);
100 shell.open();
101
102 }
103
104 public void selectionChanged(IAction action, ISelection selection) {
105 }
106
107 private void createControlArea(Composite mainContainer) {
108 Composite buttons = new Composite(mainContainer, SWT.NONE);
109 buttons.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END));
110 FillLayout layout = new FillLayout(SWT.HORIZONTAL);
111 layout.spacing = 3;
112 buttons.setLayout(layout);
113
114 Button okButton = new Button(buttons, SWT.PUSH);
115 okButton.setText("Clear");
116 okButton.addSelectionListener(new SelectionAdapter() {
117 public void widgetSelected(SelectionEvent e) {
118 clearWorkspace();
119 WorkspaceIOManager.refreshResourceNavigator();
120 shell.dispose();
121 }
122 });
123 shell.setDefaultButton(okButton);
124
125 Button noButton = new Button(buttons, SWT.PUSH);
126 noButton.setText("Cancel");
127 noButton.addSelectionListener(new SelectionAdapter() {
128 public void widgetSelected(SelectionEvent e) {
129 shell.dispose();
130 }
131 });
132
133 }
134
135 private void clearWorkspace() {
136 if (cleanMask[0] == false
137 && cleanMask[1] == false
138 && cleanMask[2] == false) {
139 return;
140 }
141 IProject[] projectList = ResourcesPlugin.getWorkspace().getRoot().getProjects();
142 for (int i = 0; i < projectList.length; i++) {
143 clearPath(projectList[i]);
144 }
145 }
146
147 private void clearPath(IContainer directory) {
148 IResource[] entries = null;
149 try {
150 entries = directory.members();
151 }
152 catch(CoreException coreEx) {
153 return;
154 }
155 if (entries == null) {
156 return;
157 }
158 for (int i = 0; i < entries.length; i++) {
159 if (entries[i] instanceof IFile
160 && "wsml".equalsIgnoreCase(((IFile)entries[i]).getFileExtension())) {
161 cleanFileResource((IFile)entries[i]);
162 }
163 else if (entries[i] instanceof IContainer) {
164 clearPath((IContainer)entries[i]);
165 }
166 }
167 }
168
169 private void cleanFileResource(IFile iFile) {
170 try {
171 IMarker[] markers = iFile.findMarkers("org.wsmostudio.runtime.wsmlmarker",
172 true,
173 IResource.DEPTH_INFINITE);
174 if (markers == null) {
175 return;
176 }
177 for(int i = 0; i < markers.length; i++) {
178 int severity = markers[i].getAttribute(IMarker.SEVERITY, IMarker.SEVERITY_INFO);
179 if (cleanMask[0] && severity == IMarker.SEVERITY_ERROR
180 || cleanMask[1] && severity == IMarker.SEVERITY_WARNING
181 || cleanMask[2] && severity == IMarker.SEVERITY_INFO) {
182 markers[i].delete();
183 }
184 }
185 }
186 catch(CoreException coreEx) {
187 LogManager.logError(coreEx);
188 }
189 }
190
191 }
192
193
194
195
196
197
198
199
200
201
202
203
204
205