Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 165565 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/tptp/monitoring/managedagent/provisional/helper/ManagedAgentCommandHelper.java (-8 / +13 lines)
Lines 188-206 Link Here
188
			_request = new CommandWrapper();
188
			_request = new CommandWrapper();
189
			_request.setOperationName(Constants.GET_MEMBERS_COMMAND);
189
			_request.setOperationName(Constants.GET_MEMBERS_COMMAND);
190
			_request.addParameter(""); //$NON-NLS-1$
190
			_request.addParameter(""); //$NON-NLS-1$
191
			Object[] memberRet = null;
191
			try{
192
			try{
192
				Object[] memberRet = execute(_request);
193
				memberRet = execute(_request);
193
				if(memberRet!=null && memberRet.length>0){
194
				// its a service group even if it doesn't have members right now
194
					membersData = (Hashtable) memberRet[0];
195
				// its a service group if this request goes through (.i.e. the operation exists)
195
					if(membersData!=null && membersData.size()!=0)
196
				isServiceGroup = true;
196
						isServiceGroup = true;				
197
				
197
				}
198
			}catch(Exception ex){
198
			}catch(Exception ex){
199
				// this means resources is not a service group
199
				// this means resource is not a service group
200
				System.out.println("This is not a service group."); //$NON-NLS-1$
200
				System.out.println("This is not a service group."); //$NON-NLS-1$
201
				isServiceGroup = false;
201
				isServiceGroup = false;
202
			}
202
			}
203
			
203
			
204
			if(isServiceGroup && memberRet!=null && memberRet.length>0){
205
				membersData = (Hashtable) memberRet[0];
206
			}
204
			
207
			
205
		}catch(ClassCastException ce){
208
		}catch(ClassCastException ce){
206
			ManagedAgentPlugin.getDefault().log(Messages.getString("ManagedAgentCommandHelper.MEX_FAILED.ERROR."), ce, IStatus.ERROR); //$NON-NLS-1$
209
			ManagedAgentPlugin.getDefault().log(Messages.getString("ManagedAgentCommandHelper.MEX_FAILED.ERROR."), ce, IStatus.ERROR); //$NON-NLS-1$
Lines 216-222 Link Here
216
		// not doing getMembers coz we already have it
219
		// not doing getMembers coz we already have it
217
		if(isServiceGroup){
220
		if(isServiceGroup){
218
			doServiceGroupModelPopulation(membersData);
221
			doServiceGroupModelPopulation(membersData);
219
			return;
222
			
223
			// do not return still need to collect as much metadata as possible
224
			// return;
220
		}
225
		}
221
		
226
		
222
		getRelationships();
227
		getRelationships();
(-)src/org/eclipse/tptp/monitoring/managedagent/ui/explorer/internal/ui/messages.properties (+6 lines)
Lines 25-27 Link Here
25
MAExplorerView.VALUE.UI.=Value
25
MAExplorerView.VALUE.UI.=Value
26
MAExplorerView.RESOURCE_TOPOLOGY.UI.=Resource Topology
26
MAExplorerView.RESOURCE_TOPOLOGY.UI.=Resource Topology
27
MAExplorerView.REFRESH_PROPS.UI.=Refresh Properties
27
MAExplorerView.REFRESH_PROPS.UI.=Refresh Properties
28
MAExplorerView.FILTER.UI.=Filter
29
30
31
#Props to indicate there are no resource matching the filter
32
MAExplorerView.FILTER.TITILE.UI.=Filter
33
MAExplorerView.FILTER.MESSAGE.UI.=No resource match the specified filter.
(-)src/org/eclipse/tptp/monitoring/managedagent/ui/explorer/internal/ui/MAExplorerView.java (-75 / +236 lines)
Lines 28-33 Link Here
28
import org.eclipse.jface.viewers.TableViewer;
28
import org.eclipse.jface.viewers.TableViewer;
29
import org.eclipse.jface.viewers.TextCellEditor;
29
import org.eclipse.jface.viewers.TextCellEditor;
30
import org.eclipse.jface.viewers.TreeViewer;
30
import org.eclipse.jface.viewers.TreeViewer;
31
import org.eclipse.jface.viewers.ViewerComparator;
31
import org.eclipse.swt.SWT;
32
import org.eclipse.swt.SWT;
32
import org.eclipse.swt.custom.CTabFolder;
33
import org.eclipse.swt.custom.CTabFolder;
33
import org.eclipse.swt.custom.CTabItem;
34
import org.eclipse.swt.custom.CTabItem;
Lines 35-59 Link Here
35
import org.eclipse.swt.events.ModifyListener;
36
import org.eclipse.swt.events.ModifyListener;
36
import org.eclipse.swt.events.SelectionAdapter;
37
import org.eclipse.swt.events.SelectionAdapter;
37
import org.eclipse.swt.events.SelectionEvent;
38
import org.eclipse.swt.events.SelectionEvent;
39
import org.eclipse.swt.graphics.Image;
40
import org.eclipse.swt.graphics.Point;
41
import org.eclipse.swt.graphics.Rectangle;
38
import org.eclipse.swt.layout.FillLayout;
42
import org.eclipse.swt.layout.FillLayout;
39
import org.eclipse.swt.layout.GridData;
43
import org.eclipse.swt.layout.GridData;
40
import org.eclipse.swt.layout.GridLayout;
44
import org.eclipse.swt.layout.GridLayout;
41
import org.eclipse.swt.widgets.Button;
45
import org.eclipse.swt.widgets.Button;
42
import org.eclipse.swt.widgets.Composite;
46
import org.eclipse.swt.widgets.Composite;
43
import org.eclipse.swt.widgets.Menu;
47
import org.eclipse.swt.widgets.Menu;
48
import org.eclipse.swt.widgets.MenuItem;
44
import org.eclipse.swt.widgets.Table;
49
import org.eclipse.swt.widgets.Table;
45
import org.eclipse.swt.widgets.TableColumn;
50
import org.eclipse.swt.widgets.TableColumn;
46
import org.eclipse.swt.widgets.TableItem;
51
import org.eclipse.swt.widgets.TableItem;
47
import org.eclipse.swt.widgets.Text;
52
import org.eclipse.swt.widgets.Text;
53
import org.eclipse.swt.widgets.ToolBar;
54
import org.eclipse.swt.widgets.ToolItem;
55
import org.eclipse.swt.widgets.Tree;
48
import org.eclipse.tptp.monitoring.managedagent.ui.explorer.internal.ManagedAgentUIPlugin;
56
import org.eclipse.tptp.monitoring.managedagent.ui.explorer.internal.ManagedAgentUIPlugin;
49
import org.eclipse.tptp.monitoring.managedagent.ui.explorer.internal.editor.PropertiesCellModifier;
57
import org.eclipse.tptp.monitoring.managedagent.ui.explorer.internal.editor.PropertiesCellModifier;
50
import org.eclipse.tptp.monitoring.managedagent.ui.explorer.internal.editor.PropertiesViewContentProvider;
58
import org.eclipse.tptp.monitoring.managedagent.ui.explorer.internal.editor.PropertiesViewContentProvider;
51
import org.eclipse.tptp.monitoring.managedagent.ui.explorer.internal.editor.PropertiesViewLabelProvider;
59
import org.eclipse.tptp.monitoring.managedagent.ui.explorer.internal.editor.PropertiesViewLabelProvider;
60
import org.eclipse.tptp.monitoring.managedagent.ui.explorer.internal.filter.Comparator;
61
import org.eclipse.tptp.monitoring.managedagent.ui.explorer.internal.filter.Filter;
62
import org.eclipse.tptp.monitoring.managedagent.ui.explorer.internal.filter.FilterDialog;
63
import org.eclipse.tptp.monitoring.managedagent.ui.explorer.internal.filter.MaxFilterPreference;
52
import org.eclipse.tptp.monitoring.managedagent.ui.explorer.internal.util.ImageUtil;
64
import org.eclipse.tptp.monitoring.managedagent.ui.explorer.internal.util.ImageUtil;
53
import org.eclipse.tptp.monitoring.managedagent.ui.explorer.provisional.controller.BrowserLabelProvider;
65
import org.eclipse.tptp.monitoring.managedagent.ui.explorer.provisional.controller.BrowserLabelProvider;
54
import org.eclipse.tptp.monitoring.managedagent.ui.explorer.provisional.controller.BrowserViewContentProvider;
66
import org.eclipse.tptp.monitoring.managedagent.ui.explorer.provisional.controller.BrowserViewContentProvider;
55
import org.eclipse.tptp.monitoring.managedagent.ui.explorer.provisional.controller.IBrowserNode;
67
import org.eclipse.tptp.monitoring.managedagent.ui.explorer.provisional.controller.IBrowserNode;
56
import org.eclipse.tptp.monitoring.managedagent.ui.explorer.provisional.controller.IViewContributor;
68
import org.eclipse.tptp.monitoring.managedagent.ui.explorer.provisional.controller.IViewContributor;
69
import org.eclipse.tptp.monitoring.managedagent.ui.explorer.provisional.controller.ManagedResourceNode;
57
import org.eclipse.ui.IWorkbenchActionConstants;
70
import org.eclipse.ui.IWorkbenchActionConstants;
58
import org.eclipse.ui.PlatformUI;
71
import org.eclipse.ui.PlatformUI;
59
import org.eclipse.ui.forms.widgets.FormToolkit;
72
import org.eclipse.ui.forms.widgets.FormToolkit;
Lines 102-112 Link Here
102
115
103
	private static MAExplorerView _default = null;
116
	private static MAExplorerView _default = null;
104
117
118
	private ViewerComparator _sorter;
119
120
	private boolean _sort = false;
121
122
	private Image _imgSort;
123
124
	private Image _imgFilter;
125
126
	private Image _imgUnSort;
127
128
	private MenuItem _miFilter;
129
105
	/**
130
	/**
106
	 * The constructor.
131
	 * The constructor.
107
	 */
132
	 */
108
	public MAExplorerView() {
133
	public MAExplorerView() {
109
		_default = this;
134
		_default = this;
135
		new MaxFilterPreference();
110
	}
136
	}
111
137
112
	public static MAExplorerView getDefault() {
138
	public static MAExplorerView getDefault() {
Lines 116-125 Link Here
116
		return _default;
142
		return _default;
117
	}
143
	}
118
144
119
	public TreeViewer getTopologyViewer(){
145
	public TreeViewer getTopologyViewer() {
120
		return _topologyViewer;
146
		return _topologyViewer;
121
	}
147
	}
122
	
148
123
	/**
149
	/**
124
	 * This is a callback that will allow us to create the viewer and initialize
150
	 * This is a callback that will allow us to create the viewer and initialize
125
	 * it.
151
	 * it.
Lines 155-236 Link Here
155
181
156
	private void layoutDetailsPanel(Composite parent) {
182
	private void layoutDetailsPanel(Composite parent) {
157
		createLabel(parent);
183
		createLabel(parent);
158
		
184
159
		//createTabFolder(parent);
185
		//createTabFolder(parent);
160
186
161
		createDetailsTextTab(parent);
187
		createDetailsTextTab(parent);
162
	}
188
	}
163
189
164
	private void createDetailsTextTab(Composite parent) {
190
	private void createDetailsTextTab(Composite parent) {
165
		_detailsText  = _toolkit.createText(parent, new String(), SWT.BORDER|SWT.H_SCROLL|SWT.V_SCROLL);
191
		_detailsText = _toolkit.createText(parent, new String(), SWT.BORDER
192
				| SWT.H_SCROLL | SWT.V_SCROLL);
166
193
167
		_propertiesViewer.addSelectionChangedListener(new ISelectionChangedListener() {
194
		_propertiesViewer
168
			public void selectionChanged(SelectionChangedEvent event) {					
195
				.addSelectionChangedListener(new ISelectionChangedListener() {
169
				TableItem[] tableSelection = _propertiesViewer.getTable().getSelection();
196
					public void selectionChanged(SelectionChangedEvent event) {
197
						TableItem[] tableSelection = _propertiesViewer
198
								.getTable().getSelection();
199
200
						if (tableSelection.length > 0) {
201
							if (_detailsObject != tableSelection[0]) {
202
								checkDetailsAndSave();
203
							}
204
							_detailsObject = tableSelection[0];
205
206
							PropertiesViewLabelProvider labelProvier = (PropertiesViewLabelProvider) _propertiesViewer
207
									.getLabelProvider();
208
							String text = labelProvier.getColumnText(
209
									_detailsObject.getData(), 1);
210
							if (text == null) {
211
								text = new String();
212
							}
213
214
							_detailsText.removeModifyListener(_modifyListener);
215
							_detailsText.setText(text);
216
							_detailsText.setEnabled(true);
217
							_detailsText.addModifyListener(_modifyListener);
218
						} else {
219
							checkDetailsAndSave();
220
							_detailsObject = null;
221
						}
222
						_applyButton.setEnabled(false);
223
					}
224
				});
170
225
171
				if(tableSelection.length > 0) {			
226
		_topologyViewer
172
					if(_detailsObject != tableSelection[0]) {
227
				.addSelectionChangedListener(new ISelectionChangedListener() {
228
					public void selectionChanged(SelectionChangedEvent event) {
173
						checkDetailsAndSave();
229
						checkDetailsAndSave();
174
					}
230
					}
175
					_detailsObject = tableSelection[0];
231
				});
176
					
232
177
					PropertiesViewLabelProvider labelProvier = (PropertiesViewLabelProvider) _propertiesViewer.getLabelProvider();
178
					String text = labelProvier.getColumnText(_detailsObject.getData(), 1);
179
					if(text == null) {
180
						text = new String();
181
					}
182
					
183
					_detailsText.removeModifyListener(_modifyListener);
184
					_detailsText.setText(text);		
185
					_detailsText.setEnabled(true);
186
					_detailsText.addModifyListener(_modifyListener);					
187
				} else {
188
					checkDetailsAndSave();
189
					_detailsObject = null;
190
				}
191
				_applyButton.setEnabled(false);
192
			}				
193
		});
194
		
195
		_topologyViewer.addSelectionChangedListener(new ISelectionChangedListener() {
196
			public void selectionChanged(SelectionChangedEvent event) {				
197
				checkDetailsAndSave();							
198
			}			
199
		});
200
		
201
		GridData gd = new GridData();
233
		GridData gd = new GridData();
202
		gd.grabExcessHorizontalSpace = true;
234
		gd.grabExcessHorizontalSpace = true;
203
		gd.grabExcessVerticalSpace = true;
235
		gd.grabExcessVerticalSpace = true;
204
		gd.horizontalAlignment = SWT.FILL;
236
		gd.horizontalAlignment = SWT.FILL;
205
		gd.verticalAlignment = SWT.FILL;
237
		gd.verticalAlignment = SWT.FILL;
206
		_detailsText.setLayoutData(gd);
238
		_detailsText.setLayoutData(gd);
207
		
239
208
		createApplyButton(parent);
240
		createApplyButton(parent);
209
	}
241
	}
210
242
211
	private void checkDetailsAndSave() {
243
	private void checkDetailsAndSave() {
212
		if(_applyButton.isEnabled()) {
244
		if (_applyButton.isEnabled()) {
213
			if(MessageDialog.openConfirm(_detailsText.getShell(), Messages.getString("MAExplorerView.DISCARD.UI."), Messages.getString("MAExplorerView.SAVE_QUESTION.UI."))) { //$NON-NLS-1$ //$NON-NLS-2$
245
			if (MessageDialog
246
					.openConfirm(
247
							_detailsText.getShell(),
248
							Messages.getString("MAExplorerView.DISCARD.UI."), Messages.getString("MAExplorerView.SAVE_QUESTION.UI."))) { //$NON-NLS-1$ //$NON-NLS-2$
214
				_propertiesViewer.getCellModifier().modify(_detailsObject,
249
				_propertiesViewer.getCellModifier().modify(_detailsObject,
215
						PropertiesCellModifier.VALUE_PROPERTY,
250
						PropertiesCellModifier.VALUE_PROPERTY,
216
						_detailsText.getText());			
251
						_detailsText.getText());
217
			}				
252
			}
218
		}
253
		}
219
		_detailsText.setEnabled(false);
254
		_detailsText.setEnabled(false);
220
		_detailsText.removeModifyListener(_modifyListener);
255
		_detailsText.removeModifyListener(_modifyListener);
221
		_detailsText.setText(new String());
256
		_detailsText.setText(new String());
222
		_applyButton.setEnabled(false);
257
		_applyButton.setEnabled(false);
223
	}	
258
	}
224
	
259
225
	private void createApplyButton(Composite parent) {
260
	private void createApplyButton(Composite parent) {
226
		_applyButton = _toolkit.createButton(parent, Messages.getString("MAExplorerView.APPLY.UI."), SWT.NONE); //$NON-NLS-1$
261
		_applyButton = _toolkit.createButton(parent, Messages
262
				.getString("MAExplorerView.APPLY.UI."), SWT.NONE); //$NON-NLS-1$
227
263
228
		_modifyListener = new ModifyListener() {
264
		_modifyListener = new ModifyListener() {
229
			public void modifyText(ModifyEvent e) {
265
			public void modifyText(ModifyEvent e) {
230
				_applyButton.setEnabled(true);		
266
				_applyButton.setEnabled(true);
231
			}			
267
			}
232
		};				
268
		};
233
		
269
234
		_applyButton.addSelectionListener(new SelectionAdapter() {
270
		_applyButton.addSelectionListener(new SelectionAdapter() {
235
			public void widgetSelected(SelectionEvent e) {
271
			public void widgetSelected(SelectionEvent e) {
236
				saveDetailsData();
272
				saveDetailsData();
Lines 245-264 Link Here
245
		_applyButton.setLayoutData(gd);
281
		_applyButton.setLayoutData(gd);
246
		_applyButton.setEnabled(false);
282
		_applyButton.setEnabled(false);
247
	}
283
	}
248
	
284
249
	private void saveDetailsData() {
285
	private void saveDetailsData() {
250
		_propertiesViewer.getCellModifier().modify(_detailsObject,
286
		_propertiesViewer.getCellModifier().modify(_detailsObject,
251
				PropertiesCellModifier.VALUE_PROPERTY,
287
				PropertiesCellModifier.VALUE_PROPERTY, _detailsText.getText());
252
				_detailsText.getText());
288
		_applyButton.setEnabled(false);
253
		_applyButton.setEnabled(false);		
254
	}
289
	}
255
290
256
	private void createTabFolder(Composite parent) {
291
	private void createTabFolder(Composite parent) {
257
		CTabFolder folder = new CTabFolder(parent, SWT.FLAT|SWT.TOP);
292
		CTabFolder folder = new CTabFolder(parent, SWT.FLAT | SWT.TOP);
258
		_toolkit.adapt(folder, true, true);
293
		_toolkit.adapt(folder, true, true);
259
		
294
260
		createTabs(folder);
295
		createTabs(folder);
261
	
296
262
		GridData gd = new GridData(GridData.FILL_HORIZONTAL);
297
		GridData gd = new GridData(GridData.FILL_HORIZONTAL);
263
		gd.heightHint = 0;
298
		gd.heightHint = 0;
264
		folder.setLayoutData(gd);
299
		folder.setLayoutData(gd);
Lines 267-273 Link Here
267
	private void createLabel(Composite parent) {
302
	private void createLabel(Composite parent) {
268
		Section label = _toolkit.createSection(parent, Section.TITLE_BAR);
303
		Section label = _toolkit.createSection(parent, Section.TITLE_BAR);
269
		label.setText(Messages.getString("MAExplorerView.VALUE_EDITOR.UI.")); //$NON-NLS-1$
304
		label.setText(Messages.getString("MAExplorerView.VALUE_EDITOR.UI.")); //$NON-NLS-1$
270
		
305
271
		GridData gd = new GridData();
306
		GridData gd = new GridData();
272
		gd.grabExcessHorizontalSpace = true;
307
		gd.grabExcessHorizontalSpace = true;
273
		gd.grabExcessVerticalSpace = false;
308
		gd.grabExcessVerticalSpace = false;
Lines 276-282 Link Here
276
	}
311
	}
277
312
278
	private void createTabs(CTabFolder folder) {
313
	private void createTabs(CTabFolder folder) {
279
		CTabItem item = new CTabItem(folder, SWT.NULL);		
314
		CTabItem item = new CTabItem(folder, SWT.NULL);
280
		item.setText(Messages.getString("MAExplorerView.SOURCE.UI.")); //$NON-NLS-1$
315
		item.setText(Messages.getString("MAExplorerView.SOURCE.UI.")); //$NON-NLS-1$
281
		item = new CTabItem(folder, SWT.NULL);
316
		item = new CTabItem(folder, SWT.NULL);
282
		item.setText(Messages.getString("MAExplorerView.DESIGN.UI.")); //$NON-NLS-1$
317
		item.setText(Messages.getString("MAExplorerView.DESIGN.UI.")); //$NON-NLS-1$
Lines 301-307 Link Here
301
		table.setData(FormToolkit.KEY_DRAW_BORDER, FormToolkit.TREE_BORDER);
336
		table.setData(FormToolkit.KEY_DRAW_BORDER, FormToolkit.TREE_BORDER);
302
337
303
		TableColumn propertyColumn = new TableColumn(table, SWT.LEFT);
338
		TableColumn propertyColumn = new TableColumn(table, SWT.LEFT);
304
		propertyColumn.setText(Messages.getString("MAExplorerView.PROPERTY.UI.")); //$NON-NLS-1$
339
		propertyColumn.setText(Messages
340
				.getString("MAExplorerView.PROPERTY.UI.")); //$NON-NLS-1$
305
		propertyColumn.setWidth(140);
341
		propertyColumn.setWidth(140);
306
		TableColumn valueColumn = new TableColumn(table, SWT.LEFT);
342
		TableColumn valueColumn = new TableColumn(table, SWT.LEFT);
307
		valueColumn.setText(Messages.getString("MAExplorerView.VALUE.UI.")); //$NON-NLS-1$
343
		valueColumn.setText(Messages.getString("MAExplorerView.VALUE.UI.")); //$NON-NLS-1$
Lines 318-336 Link Here
318
		gd.horizontalAlignment = SWT.FILL;
354
		gd.horizontalAlignment = SWT.FILL;
319
		gd.verticalAlignment = SWT.FILL;
355
		gd.verticalAlignment = SWT.FILL;
320
		table.setLayoutData(gd);
356
		table.setLayoutData(gd);
321
	
357
322
		createPropertiesEditors();
358
		createPropertiesEditors();
323
	}
359
	}
324
360
325
	private void createPropertiesEditors() {
361
	private void createPropertiesEditors() {
326
		CellEditor[] editors = new CellEditor[2];
362
		CellEditor[] editors = new CellEditor[2];
327
		editors[0] = new TextCellEditor(_propertiesViewer.getTable());
363
		editors[0] = new TextCellEditor(_propertiesViewer.getTable());
328
		editors[1] = new TextCellEditor(_propertiesViewer.getTable(), SWT.READ_ONLY);
364
		editors[1] = new TextCellEditor(_propertiesViewer.getTable(),
365
				SWT.READ_ONLY);
329
		_propertiesViewer.setCellEditors(editors);
366
		_propertiesViewer.setCellEditors(editors);
330
		_propertiesViewer.setCellModifier(new PropertiesCellModifier(_propertiesViewer));
367
		_propertiesViewer.setCellModifier(new PropertiesCellModifier(
331
		_propertiesViewer.setColumnProperties(new String[] {Messages.getString("MAExplorerView.PROPERTY.UI."),Messages.getString("MAExplorerView.VALUE.UI.")}); //$NON-NLS-1$ //$NON-NLS-2$
368
				_propertiesViewer));
369
		_propertiesViewer
370
				.setColumnProperties(new String[] {
371
						Messages.getString("MAExplorerView.PROPERTY.UI."), Messages.getString("MAExplorerView.VALUE.UI.") }); //$NON-NLS-1$ //$NON-NLS-2$
332
	}
372
	}
333
	
373
334
	private void layoutAgentTopologyTree() {
374
	private void layoutAgentTopologyTree() {
335
375
336
		Composite parent = _toolkit.createComposite(_form.getBody());
376
		Composite parent = _toolkit.createComposite(_form.getBody());
Lines 340-355 Link Here
340
		layout.marginHeight = DEFAULT_PADDING;
380
		layout.marginHeight = DEFAULT_PADDING;
341
		layout.marginWidth = DEFAULT_PADDING;
381
		layout.marginWidth = DEFAULT_PADDING;
342
		layout.numColumns = 1;
382
		layout.numColumns = 1;
343
		
383
344
		parent.setLayout(layout);
384
		parent.setLayout(layout);
345
385
346
		Section label = _toolkit.createSection(parent, Section.TITLE_BAR);
386
		Section label = _toolkit.createSection(parent, Section.TITLE_BAR);
347
		label.setText(Messages.getString("MAExplorerView.RESOURCE_TOPOLOGY.UI.")); //$NON-NLS-1$
387
		label.setText(Messages
388
				.getString("MAExplorerView.RESOURCE_TOPOLOGY.UI.")); //$NON-NLS-1$
348
		GridData gd = new GridData();
389
		GridData gd = new GridData();
349
		gd.grabExcessHorizontalSpace = true;
390
		gd.grabExcessHorizontalSpace = true;
350
		gd.grabExcessVerticalSpace = false;
391
		gd.grabExcessVerticalSpace = false;
351
		gd.horizontalAlignment = SWT.FILL;
392
		gd.horizontalAlignment = SWT.FILL;
352
		label.setLayoutData(gd);
393
		label.setLayoutData(gd);
394
		
395
		_sorter = new Comparator();
396
		addSortAndFilterToolBar(label);
353
397
354
		_topologyViewer = new TreeViewer(parent);
398
		_topologyViewer = new TreeViewer(parent);
355
399
Lines 383-393 Link Here
383
		getSite().setSelectionProvider(_topologyViewer);
427
		getSite().setSelectionProvider(_topologyViewer);
384
428
385
	}
429
	}
386
	
430
387
	private void hookupSelectionListeners(){
431
	private void hookupSelectionListeners() {
388
		ISelectionChangedListener[] listeners = ManagedAgentUIPlugin.getSelectionListeners();
432
		ISelectionChangedListener[] listeners = ManagedAgentUIPlugin
389
		if(listeners!=null){
433
				.getSelectionListeners();
390
			for(int i=0; i<listeners.length; i++){
434
		if (listeners != null) {
435
			for (int i = 0; i < listeners.length; i++) {
391
				_topologyViewer.addSelectionChangedListener(listeners[i]);
436
				_topologyViewer.addSelectionChangedListener(listeners[i]);
392
			}
437
			}
393
		}
438
		}
Lines 435-441 Link Here
435
		manager.add(new Separator());
480
		manager.add(new Separator());
436
481
437
		// Other plug-ins can contribute their actions here
482
		// Other plug-ins can contribute their actions here
438
		manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));	
483
		manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
439
	}
484
	}
440
485
441
	private void contributeToActionBars() {
486
	private void contributeToActionBars() {
Lines 449-464 Link Here
449
		_drillDownAdapter.addNavigationActions(manager);
494
		_drillDownAdapter.addNavigationActions(manager);
450
	}
495
	}
451
496
497
	private void addSortAndFilterToolBar(Section label) {
498
		Composite sfComp = _toolkit.createComposite(label);
499
		sfComp.setLayout(new FillLayout());
500
		ToolBar tb = new ToolBar(sfComp, SWT.NONE);
501
		ToolItem ti = new ToolItem(tb, SWT.DROP_DOWN);
502
		_imgSort = ImageUtil.getImage(ImageUtil.SORT_IMAGE);
503
		ti.setImage(_imgSort);
504
505
		_imgUnSort = ImageUtil.getImage(ImageUtil.UNSORT_IMAGE);
506
507
		Menu ddMenu = new Menu(ti.getParent().getShell(), SWT.NONE);
508
		_miFilter = new MenuItem(ddMenu, SWT.NONE);
509
		_imgFilter = ImageUtil.getImage(ImageUtil.FILTER_IMAGE);
510
		_miFilter.setImage(_imgFilter);
511
		_miFilter.setText(Messages.getString("MAExplorerView.FILTER.UI."));
512
513
		addMenuItemSelectionListener();
514
		addToolItemSelectionListener(ti, ddMenu);
515
516
		_toolkit.adapt(sfComp);
517
		label.setTextClient(sfComp);
518
	}
519
520
	private void addMenuItemSelectionListener() {
521
		_miFilter.addSelectionListener(new SelectionAdapter() {
522
			public void widgetSelected(SelectionEvent se) {
523
				Filter filter = new FilterDialog().showWindow();
524
				if (filter == null) {
525
					return;
526
				}
527
				
528
				IBrowserNode root = _topologyViewContentProvider.getRoot();
529
				
530
				// if this is a service group then we can apply this filter
531
				// note that we do not check if it has members coz it might be an empty service group at this point and more members might be added later
532
				
533
				System.out.println("root instanceof ManagedResourceNode = "+(root instanceof ManagedResourceNode));
534
				System.out.println(root.getClass());
535
				Object[] children = root.getChildren();
536
				
537
				// the first child is what we want
538
				IBrowserNode child = null;
539
				try{
540
					child = (IBrowserNode) children[0];
541
				}catch(ArrayIndexOutOfBoundsException ae){
542
					
543
				}
544
				if(child != null
545
						&& child instanceof ManagedResourceNode){
546
					((ManagedResourceNode)child).setFilter(filter);
547
				}
548
				
549
				// this filtering must not be done here - it should be done by the ManagedResourceNode in figuring  out which of its children to show
550
				/*
551
				Object[] children = root.getChildren();
552
				for (int i = 0; i < children.length; i++) {
553
					root.removeChild((IBrowserNode) children[i]);
554
				}
555
				FilterUtil.setFilter(filter);
556
				System.out.println("FILTER STRING: " + filter.toString());
557
				ManagedResource[] resources = FilterUtil.getManagedResources();
558
				if (resources == null || resources.length<0) {
559
					return;
560
				}
561
				_topologyViewContentProvider.setFilterMatch(false);
562
				
563
				boolean match = _topologyViewContentProvider.getFilterMatch();
564
				if (!match) {
565
					MessageDialog
566
							.openInformation(
567
									_topologyViewer.getControl().getShell(),
568
									Messages
569
											.getString("MAExplorerView.FILTER.TITILE.UI."),
570
									Messages
571
											.getString("MAExplorerView.FILTER.MESSAGE.UI."));
572
					_topologyViewer.setInput(null);
573
				}
574
				*/
575
			}
576
		});
577
	}
578
579
	private void addToolItemSelectionListener(ToolItem ti, final Menu ddMenu) {
580
		ti.addSelectionListener(new SelectionAdapter() {
581
			public void widgetSelected(SelectionEvent se) {
582
				ToolItem item = (ToolItem) se.widget;
583
				if (se.detail == SWT.ARROW) {
584
					// Determine where to put the dropdown list
585
					Rectangle rect = item.getBounds();
586
					Point pt = item.getParent().toDisplay(
587
							new Point(rect.x, rect.y));
588
					ddMenu.setLocation(pt.x, pt.y + rect.height);
589
					ddMenu.setVisible(true);
590
				} else {
591
					_sort = !_sort;
592
					if (_sort) {
593
						item.setImage(_imgUnSort);
594
						Tree tree = _topologyViewer.getTree();
595
						if (tree != null) {
596
							_topologyViewer.setComparator(_sorter);
597
						}
598
					} else {
599
						item.setImage(_imgSort);
600
						_topologyViewer.setComparator(null);
601
					}
602
				}
603
			}
604
		});
605
	}
606
452
	private void makeActions() {
607
	private void makeActions() {
453
		_refreshPropertiesAction = new Action() {
608
		_refreshPropertiesAction = new Action() {
454
			public void run() {
609
			public void run() {
455
				getViewerSelection().refresh();
610
				if(getViewerSelection()!=null){
456
				_propertiesViewer.refresh();
611
					getViewerSelection().refresh();
612
					_propertiesViewer.refresh();
613
				}else{
614
					// TODO figure out if we can refresh something else
615
				}
457
			}
616
			}
458
		};
617
		};
459
618
460
		_refreshPropertiesAction.setText(Messages.getString("MAExplorerView.REFRESH_PROPS.UI.")); //$NON-NLS-1$
619
		_refreshPropertiesAction.setText(Messages
461
		_refreshPropertiesAction.setToolTipText(Messages.getString("MAExplorerView.REFRESH_PROPS.UI.")); //$NON-NLS-1$
620
				.getString("MAExplorerView.REFRESH_PROPS.UI.")); //$NON-NLS-1$
621
		_refreshPropertiesAction.setToolTipText(Messages
622
				.getString("MAExplorerView.REFRESH_PROPS.UI.")); //$NON-NLS-1$
462
		_refreshPropertiesAction.setImageDescriptor(ImageUtil
623
		_refreshPropertiesAction.setImageDescriptor(ImageUtil
463
				.getDescriptor(ImageUtil.REFRESH_PROPERTIES));
624
				.getDescriptor(ImageUtil.REFRESH_PROPERTIES));
464
	}
625
	}
Lines 489-493 Link Here
489
		_toolkit.dispose();
650
		_toolkit.dispose();
490
		super.dispose();
651
		super.dispose();
491
	}
652
	}
492
	
653
493
}
654
}
(-)src/org/eclipse/tptp/monitoring/managedagent/ui/explorer/provisional/controller/ManagedResourceNode.java (-11 / +108 lines)
Lines 23-28 Link Here
23
import org.eclipse.jface.viewers.IDecoration;
23
import org.eclipse.jface.viewers.IDecoration;
24
import org.eclipse.swt.graphics.Image;
24
import org.eclipse.swt.graphics.Image;
25
import org.eclipse.tptp.monitoring.managedagent.provisional.ManagedAgentFactory;
25
import org.eclipse.tptp.monitoring.managedagent.provisional.ManagedAgentFactory;
26
import org.eclipse.tptp.monitoring.managedagent.provisional.helper.ManagedAgentCommandHelper;
26
import org.eclipse.tptp.monitoring.managedagent.provisional.model.ManagedResource;
27
import org.eclipse.tptp.monitoring.managedagent.provisional.model.ManagedResource;
27
import org.eclipse.tptp.monitoring.managedagent.provisional.model.Operation;
28
import org.eclipse.tptp.monitoring.managedagent.provisional.model.Operation;
28
import org.eclipse.tptp.monitoring.managedagent.provisional.model.Property;
29
import org.eclipse.tptp.monitoring.managedagent.provisional.model.Property;
Lines 31-37 Link Here
31
import org.eclipse.tptp.monitoring.managedagent.provisional.model.util.ModelUtils;
32
import org.eclipse.tptp.monitoring.managedagent.provisional.model.util.ModelUtils;
32
import org.eclipse.tptp.monitoring.managedagent.ui.explorer.internal.ActionManager;
33
import org.eclipse.tptp.monitoring.managedagent.ui.explorer.internal.ActionManager;
33
import org.eclipse.tptp.monitoring.managedagent.ui.explorer.internal.ManagedAgentUIPlugin;
34
import org.eclipse.tptp.monitoring.managedagent.ui.explorer.internal.ManagedAgentUIPlugin;
35
import org.eclipse.tptp.monitoring.managedagent.ui.explorer.internal.filter.Filter;
36
import org.eclipse.tptp.monitoring.managedagent.ui.explorer.internal.filter.FilterUtil;
34
import org.eclipse.tptp.monitoring.managedagent.ui.explorer.internal.util.ImageUtil;
37
import org.eclipse.tptp.monitoring.managedagent.ui.explorer.internal.util.ImageUtil;
38
import org.eclipse.tptp.monitoring.managedagent.ui.explorer.internal.util.TextUtils;
35
import org.eclipse.tptp.monitoring.managedagent.ui.explorer.provisional.ModelActionProvider;
39
import org.eclipse.tptp.monitoring.managedagent.ui.explorer.provisional.ModelActionProvider;
36
import org.eclipse.tptp.monitoring.managedagent.ui.launch.provisional.common.IConnectionHelper;
40
import org.eclipse.tptp.monitoring.managedagent.ui.launch.provisional.common.IConnectionHelper;
37
import org.eclipse.ui.ISharedImages;
41
import org.eclipse.ui.ISharedImages;
Lines 58-63 Link Here
58
	
62
	
59
	private static final String RELATIONSHIPS_NODE = Messages.getString("ManagedResourceNode.RELATIONSHIPS.UI."); //$NON-NLS-1$
63
	private static final String RELATIONSHIPS_NODE = Messages.getString("ManagedResourceNode.RELATIONSHIPS.UI."); //$NON-NLS-1$
60
	
64
	
65
	private static final String WSRF_SERVICE_GROUP_URI = "http://docs.oasis-open.org/wsrf/sg-2"; //$NON-NLS-1$
66
	
67
	private static final String SERVICE_GROUP_OP_NAME_TO_CHECK = "isMatch";
68
	
69
	private static final String SERVICE_GROUP_OP_PARAM_TO_CHECK = "";
70
	
71
	private static final String SERVICE_GROUP_PROP_NAME_TO_CHECK = "MembershipContentRule";
72
	
61
	ManagedResource _resource;
73
	ManagedResource _resource;
62
74
63
	private BrowserViewContentProvider _provider;
75
	private BrowserViewContentProvider _provider;
Lines 69-74 Link Here
69
	private Map _connProps = null;
81
	private Map _connProps = null;
70
82
71
	private String _agentId = null;
83
	private String _agentId = null;
84
	
85
	private Filter _filter = null;
86
	
87
	private ManagedAgentCommandHelper _agent = null;
72
88
73
	public ManagedResourceNode(BrowserViewContentProvider provider,
89
	public ManagedResourceNode(BrowserViewContentProvider provider,
74
			IBrowserNode parent, ManagedResource resource) {
90
			IBrowserNode parent, ManagedResource resource) {
Lines 77-82 Link Here
77
		_resource = resource;
93
		_resource = resource;
78
		_nodeObject = resource;
94
		_nodeObject = resource;
79
		_agentId = _resource.getId();
95
		_agentId = _resource.getId();
96
		_agent = ManagedAgentCommandHelper.getInstance(_agentId);
80
		_connProps = new Hashtable();
97
		_connProps = new Hashtable();
81
		checkNodeType();
98
		checkNodeType();
82
99
Lines 84-89 Link Here
84
101
85
		notifyProvider();
102
		notifyProvider();
86
	}
103
	}
104
	
105
	public void setFilter(Filter filter){
106
		_filter = filter;
107
	}
87
108
88
	public String getId() {
109
	public String getId() {
89
		return _agentId;
110
		return _agentId;
Lines 111-118 Link Here
111
132
112
	public String getName() {
133
	public String getName() {
113
		return _resource.getName();
134
		return _resource.getName();
135
		//return "ResName";
136
	}
137
	
138
	public void refresh(){
139
		_children = new ArrayList();
140
		try {
141
			_agent.getMembers();
142
		} catch (Exception e) {
143
			ManagedAgentUIPlugin
144
					.getDefault()
145
					.log(
146
							Messages
147
									.getString("Cannot update managed resource"), e, IStatus.ERROR); //$NON-NLS-1$
148
		}
149
		if(_isServiceGroup){
150
			performStructuralChanges();
151
		}
152
		super.refresh();
114
	}
153
	}
115
154
155
	protected void performStructuralChanges(){
156
		// TODO should we synchronize on FilterUtil or an instance of it
157
		List members = _resource.getMembers();
158
		if( _filter != null ){
159
			FilterUtil.setFilter(_filter);
160
			System.out.println("FILTER STRING: " + _filter.toString());
161
		}
162
163
		if (members != null && members.size() != 0) {
164
			Iterator i = _resource.getMembers().iterator();
165
			while (i.hasNext()) {
166
				ManagedResource member = (ManagedResource) i.next();
167
				
168
				// if this child member meets the filter criteria then add it to the view else don't
169
				if( _filter != null && ! FilterUtil.matchFilter(member) )
170
					continue;
171
				
172
				ManagedResourceNode memberNode = new ManagedResourceNode(_provider, this, member);
173
				addChild(memberNode);
174
			}
175
		}
176
	}
177
	
116
	private void loadMetadata() {
178
	private void loadMetadata() {
117
		try{
179
		try{
118
			String type = ModelUtils.extractFromConnProperties(_resource.getConnectionProperties(), 
180
			String type = ModelUtils.extractFromConnProperties(_resource.getConnectionProperties(), 
Lines 133-148 Link Here
133
195
134
		if (_isServiceGroup) {
196
		if (_isServiceGroup) {
135
			this._image = ImageUtil.getImage(ImageUtil.SG_NODE);
197
			this._image = ImageUtil.getImage(ImageUtil.SG_NODE);
136
			List members = _resource.getMembers();
198
			performStructuralChanges();
137
			if (members != null && members.size() != 0) {
138
				Iterator i = _resource.getMembers().iterator();
139
				while (i.hasNext()) {
140
					ManagedResource member = (ManagedResource) i.next();
141
					ManagedResourceNode memberNode = new ManagedResourceNode(
142
							_provider, this, member);
143
					addChild(memberNode);
144
				}
145
			}
146
		} else {
199
		} else {
147
			Iterator i = _resource.getProperties().iterator();
200
			Iterator i = _resource.getProperties().iterator();
148
201
Lines 322-328 Link Here
322
	}
375
	}
323
376
324
	private void checkServiceGroup() {
377
	private void checkServiceGroup() {
325
		_isServiceGroup = !_resource.getMembers().isEmpty();
378
		// TODO we already do this in the agent - do we have to do it again here???
379
		
380
		// check if there is an isMatch operation whose parameter is in the sg namespace (http://docs.oasis-open.org/wsrf/sg-2)
381
		/*
382
		Operation[] ops = (Operation[]) _resource.getOperations().toArray(new Operation[]{});
383
		_isServiceGroup = false;
384
		for(int i=0; i<ops.length; i++){
385
			OperationParameter[] params = (OperationParameter[]) ops[i].getArgument().
386
																	toArray(new OperationParameter[]{});
387
			
388
			String opName = params[i].getName(); 
389
				
390
			for(int j=0; j<params.length; j++){
391
				String paramName = params[j].getName();
392
				String qnameParts[] = TextUtils.deserializeFromString(paramName);
393
				String namespaceURI = qnameParts[0];
394
				String localPart = qnameParts[1];
395
				if( opName.indexOf(SERVICE_GROUP_OP_NAME_TO_CHECK) > -1
396
						&& namespaceURI.equals(SERVICE_GROUP_URI) 
397
						&& localPart.equals(SERVICE_GROUP_OP_PARAM_TO_CHECK)){
398
					_isServiceGroup = true;
399
					return;
400
				}
401
			}
402
		}*/
403
		
404
		// check if there is a specific property
405
		Property[] props = (Property[]) _resource.getProperties().toArray(new Property[]{});
406
		_isServiceGroup = false;
407
		for(int i=0; i<props.length; i++){
408
			String propNameStr = props[i].getName();
409
			String[] propQNameParts = TextUtils.deserializeFromString(propNameStr);
410
			String nsURI = propQNameParts[0];
411
			String localPart = propQNameParts[1];
412
			if(nsURI.equals(WSRF_SERVICE_GROUP_URI) 
413
					&& localPart.equals(SERVICE_GROUP_PROP_NAME_TO_CHECK)){
414
				_isServiceGroup=true;
415
				break;
416
			}
417
		}
418
		if(_isServiceGroup 
419
				&& _resource.getMembers().isEmpty()){
420
			ManagedAgentUIPlugin.getDefault().log("Service group is currently empty", null, IStatus.INFO); 
421
		}
422
		
326
		if (_isServiceGroup) {
423
		if (_isServiceGroup) {
327
			_image = PlatformUI.getWorkbench().getSharedImages().getImage(
424
			_image = PlatformUI.getWorkbench().getSharedImages().getImage(
328
					ISharedImages.IMG_OBJ_FOLDER);
425
					ISharedImages.IMG_OBJ_FOLDER);
(-)src/org/eclipse/tptp/monitoring/managedagent/ui/explorer/provisional/controller/BrowserViewContentProvider.java (-10 / +55 lines)
Lines 14-26 Link Here
14
import org.eclipse.emf.common.notify.Adapter;
14
import org.eclipse.emf.common.notify.Adapter;
15
import org.eclipse.emf.common.notify.Notification;
15
import org.eclipse.emf.common.notify.Notification;
16
import org.eclipse.emf.common.notify.Notifier;
16
import org.eclipse.emf.common.notify.Notifier;
17
import org.eclipse.jface.dialogs.MessageDialog;
17
import org.eclipse.jface.viewers.ITreeContentProvider;
18
import org.eclipse.jface.viewers.ITreeContentProvider;
18
import org.eclipse.jface.viewers.TreeViewer;
19
import org.eclipse.jface.viewers.TreeViewer;
19
import org.eclipse.jface.viewers.Viewer;
20
import org.eclipse.jface.viewers.Viewer;
20
import org.eclipse.tptp.monitoring.managedagent.provisional.helper.ManagedAgentCommandHelper;
21
import org.eclipse.tptp.monitoring.managedagent.provisional.helper.ManagedAgentCommandHelper;
22
import org.eclipse.tptp.monitoring.managedagent.provisional.model.ManagedResource;
21
import org.eclipse.tptp.monitoring.managedagent.ui.explorer.internal.ManagedAgentUIPlugin;
23
import org.eclipse.tptp.monitoring.managedagent.ui.explorer.internal.ManagedAgentUIPlugin;
22
import org.eclipse.tptp.monitoring.managedagent.ui.explorer.internal.adapters.IModelChangeAdapter;
24
import org.eclipse.tptp.monitoring.managedagent.ui.explorer.internal.adapters.IModelChangeAdapter;
23
import org.eclipse.tptp.monitoring.managedagent.ui.explorer.internal.adapters.PropertyChangeModelAdapter;
25
import org.eclipse.tptp.monitoring.managedagent.ui.explorer.internal.adapters.PropertyChangeModelAdapter;
26
import org.eclipse.tptp.monitoring.managedagent.ui.explorer.internal.filter.FilterUtil;
24
import org.eclipse.ui.IViewSite;
27
import org.eclipse.ui.IViewSite;
25
import org.eclipse.ui.PlatformUI;
28
import org.eclipse.ui.PlatformUI;
26
29
Lines 34-39 Link Here
34
	private IViewSite _viewSite;
37
	private IViewSite _viewSite;
35
38
36
	private Viewer _viewer;
39
	private Viewer _viewer;
40
	
41
	private boolean _filterMatch = false;
37
42
38
	public BrowserViewContentProvider(IViewSite viewSite) {
43
	public BrowserViewContentProvider(IViewSite viewSite) {
39
		_viewSite = viewSite;
44
		_viewSite = viewSite;
Lines 93-109 Link Here
93
		
98
		
94
		mac.getManagedResource().eAdapters().add(this);
99
		mac.getManagedResource().eAdapters().add(this);
95
		
100
		
96
		Object[] children = _root.getChildren();
101
		//Apply Filter Here. if this managed resource satisfies the filter, then add the node
97
		for(int i=0; i<children.length; i++){
102
		/*if(FilterUtil.getFilter() != null)
98
			_root.removeChild((IBrowserNode) children[i]);
103
		{
104
			ManagedResource mr = mac.getManagedResource();
105
			boolean match = FilterUtil.matchFilter(mr);
106
			System.out.println("RESOURCE NAME = " + mr.getName());
107
			if(match)
108
			{
109
				_root.addChild(new ManagedResourceNode(this, _root, mac.getManagedResource()));
110
				
111
				ManagedAgentUIPlugin.getDefault().setCurrentManagedResource(mac.getManagedResource());
112
				PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {
113
					public void run() {
114
						fireContentChanged(null);
115
					}
116
				});
117
				_viewer.setInput(_root);
118
				_filterMatch = true;
119
			}
99
		}
120
		}
100
		_root.addChild(new ManagedResourceNode(this, _root, mac.getManagedResource()));
121
		else
101
		ManagedAgentUIPlugin.getDefault().setCurrentManagedResource(mac.getManagedResource());
122
		{*/
102
		PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {
123
			Object[] children = _root.getChildren();
103
			public void run() {
124
			for(int i=0; i<children.length; i++){
104
				fireContentChanged(null);
125
				_root.removeChild((IBrowserNode) children[i]);
105
			}
126
			}
106
		});
127
			
128
			_root.addChild(new ManagedResourceNode(this, _root, mac.getManagedResource()));
129
			
130
			ManagedAgentUIPlugin.getDefault().setCurrentManagedResource(mac.getManagedResource());
131
			PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {
132
				public void run() {
133
					fireContentChanged(null);
134
				}
135
			});
136
			_viewer.setInput(_root);
137
		/*}*/
107
	}
138
	}
108
139
109
	public void refresh() {
140
	public void refresh() {
Lines 130-135 Link Here
130
161
131
	public void setTarget(Notifier newTarget) {
162
	public void setTarget(Notifier newTarget) {
132
		// TODO Auto-generated method stub
163
		// TODO Auto-generated method stub
133
		
164
	}
165
	
166
	public boolean getFilterMatch()
167
	{
168
		return this._filterMatch;
169
	}
170
	
171
	public void setFilterMatch(boolean match)
172
	{
173
		this._filterMatch = match;
174
	}
175
	
176
	public IBrowserNode getRoot()
177
	{
178
		return _root;
134
	}
179
	}
135
}
180
}
(-)src/org/eclipse/tptp/monitoring/managedagent/ui/explorer/internal/util/ImageUtil.java (+5 lines)
Lines 69-74 Link Here
69
	
69
	
70
	public static final String RELATED_RESOURCE_NODE = BASE_DIR + OBJ_DIR + "relatedResource_obj.gif"; //$NON-NLS-1$
70
	public static final String RELATED_RESOURCE_NODE = BASE_DIR + OBJ_DIR + "relatedResource_obj.gif"; //$NON-NLS-1$
71
	
71
	
72
	public static final String SORT_IMAGE = BASE_DIR + OBJ_DIR + "sort.gif";
73
	
74
	public static final String UNSORT_IMAGE = BASE_DIR + OBJ_DIR + "unsort.gif";
75
	
76
	public static final String FILTER_IMAGE = BASE_DIR + OBJ_DIR + "filter.gif";
72
77
73
	public static ImageDescriptor getDescriptor(String key) {
78
	public static ImageDescriptor getDescriptor(String key) {
74
		return ManagedAgentUIPlugin.getImageDescriptor(key);
79
		return ManagedAgentUIPlugin.getImageDescriptor(key);
(-)src/org/eclipse/tptp/monitoring/managedagent/ui/explorer/internal/filter/FilterDialog.java (+747 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 * 	Balan Subramanian (bsubram@us.ibm.com)
10
 *     IBM Corporation - initial API and implementation
11
 *******************************************************************************/
12
13
package org.eclipse.tptp.monitoring.managedagent.ui.explorer.internal.filter;
14
15
import java.awt.Dimension;
16
import java.awt.Toolkit;
17
import java.util.Map;
18
19
import org.eclipse.jface.dialogs.MessageDialog;
20
import org.eclipse.swt.SWT;
21
import org.eclipse.swt.custom.TableEditor;
22
import org.eclipse.swt.events.ModifyEvent;
23
import org.eclipse.swt.events.ModifyListener;
24
import org.eclipse.swt.graphics.Image;
25
import org.eclipse.swt.graphics.Point;
26
import org.eclipse.swt.graphics.Rectangle;
27
import org.eclipse.swt.layout.GridData;
28
import org.eclipse.swt.layout.GridLayout;
29
import org.eclipse.swt.widgets.Button;
30
import org.eclipse.swt.widgets.Combo;
31
import org.eclipse.swt.widgets.Composite;
32
import org.eclipse.swt.widgets.Display;
33
import org.eclipse.swt.widgets.Event;
34
import org.eclipse.swt.widgets.Group;
35
import org.eclipse.swt.widgets.Label;
36
import org.eclipse.swt.widgets.List;
37
import org.eclipse.swt.widgets.Listener;
38
import org.eclipse.swt.widgets.Shell;
39
import org.eclipse.swt.widgets.TabFolder;
40
import org.eclipse.swt.widgets.TabItem;
41
import org.eclipse.swt.widgets.Table;
42
import org.eclipse.swt.widgets.TableColumn;
43
import org.eclipse.swt.widgets.TableItem;
44
import org.eclipse.swt.widgets.Text;
45
import org.eclipse.tptp.monitoring.managedagent.ui.explorer.internal.util.ImageUtil;
46
47
48
public class FilterDialog 
49
{
50
	private Display _disp;
51
	
52
	private Shell _shell;
53
	
54
	private Group _grpExistingFilters;
55
	
56
	private Group _grpFilterDetails;
57
	
58
	private Combo _cmbExistingFilters;
59
	
60
	private Button _btnNewFilter;
61
	
62
	private Button _btnDeleteFilter;
63
	
64
	private Label _lblName;
65
	
66
	private Text _txtName;
67
	
68
	private TabFolder _tabFldr;
69
	
70
	private TabItem _tiResName;
71
	
72
	private TabItem _tiCaps;
73
	
74
	private TabItem _tiEpr;
75
	
76
	private Button _btnApply;
77
	
78
	private Button _btnCancel;
79
	
80
	private Button _btnAnd;
81
	
82
	private Button _btnAddCapUri;
83
	
84
	private Button _btnRemoveCapUri;
85
	
86
	private Text _txtResName;
87
	
88
	private Label _lblCapUri;
89
	
90
	private List _lstCapUris;
91
	
92
	private Text _txtCapUri;
93
	
94
	private Button _btnCapMatchAll;
95
	
96
	private Label _lblEprUri;
97
	
98
	private Combo _cmbEprUri;
99
	
100
	private Label _lblRefProperties;
101
	
102
	private Table _tblRefParams;
103
	
104
	private Button _btnAddProperty;
105
	
106
	private Button _btnRemoveProperty;
107
	
108
	private ComponentSelectionListener _listener;
109
	
110
	private Filter _filter;
111
112
	private Event _event;
113
		
114
	public FilterDialog()
115
	{
116
		MaxFilterPreference.loadFilters();
117
		initUI();
118
		addExistingFilterNames();
119
	}
120
	
121
	private void initUI()
122
	{
123
		_disp = Display.getCurrent();
124
		_shell = new Shell(_disp, SWT.SYSTEM_MODAL | SWT.APPLICATION_MODAL | SWT.CLOSE);
125
		_shell.setSize(500, 440);
126
		centralizeWindow();
127
		_shell.setLayout(new GridLayout(2, false));
128
		_shell.setText(Messages.getString("MAXFilter.FILTER.TITLE.UI."));
129
		Image imgFilter = ImageUtil.getImage(ImageUtil.FILTER_IMAGE);
130
		_shell.setImage(imgFilter);
131
		initExistingFiltersGroup(_shell);
132
		initDetailsGroup(_shell);
133
		initButtons(_shell);
134
		_listener = new ComponentSelectionListener(this);
135
	}
136
	
137
	private void initExistingFiltersGroup(Composite parent)
138
	{
139
		_grpExistingFilters = new Group(parent, SWT.NONE);
140
		_grpExistingFilters.setText(Messages.getString("MAXFilter.EXFILTER.UI."));
141
		_grpExistingFilters.setLayout(new GridLayout(2, false));
142
		
143
		_cmbExistingFilters = new Combo(_grpExistingFilters, SWT.DROP_DOWN | SWT.SINGLE | SWT.READ_ONLY);
144
		
145
		_cmbExistingFilters.addModifyListener(new ModifyListener()
146
		{
147
			public void modifyText(ModifyEvent e) 
148
			{
149
				loadFilter();
150
			}
151
		});
152
		
153
		_btnNewFilter = new Button(_grpExistingFilters, SWT.PUSH);
154
		_btnNewFilter.setText(Messages.getString("MAXFilter.NEW.FILTER.UI."));
155
		
156
		_btnDeleteFilter = new Button(_grpExistingFilters, SWT.PUSH);
157
		_btnDeleteFilter.setText(Messages.getString("MAXFilter.DELETE.FILTER.UI."));
158
		_btnDeleteFilter.setEnabled(false);
159
		
160
		GridData gd = new GridData(GridData.FILL_HORIZONTAL);
161
		gd.horizontalSpan = 2;
162
		_grpExistingFilters.setLayoutData(gd);
163
		
164
		gd = new GridData(GridData.FILL_HORIZONTAL);
165
		gd.horizontalSpan = 2;
166
		_cmbExistingFilters.setLayoutData(gd);
167
		
168
		gd = new GridData(GridData.FILL_HORIZONTAL);
169
		gd.horizontalSpan = 1;
170
		gd.horizontalAlignment = SWT.END;
171
		_btnNewFilter.setLayoutData(gd);
172
		
173
		gd = new GridData();
174
		_btnDeleteFilter.setLayoutData(gd);
175
	}
176
	
177
	private void initDetailsGroup(Composite parent)
178
	{
179
		_grpFilterDetails = new Group(parent, SWT.NONE);
180
		_grpFilterDetails.setText(Messages.getString("MAXFilter.DETAILS.UI."));
181
		_grpFilterDetails.setLayout(new GridLayout(2, false));
182
		
183
		_lblName = new Label(_grpFilterDetails, SWT.NONE);
184
		_lblName.setText(Messages.getString("MAXFilter.NAME.LABEL.UI."));
185
		
186
		_txtName = new Text(_grpFilterDetails, SWT.BORDER);
187
		
188
		GridData gd = new GridData();
189
		gd.widthHint = 100;
190
		_lblName.setLayoutData(gd);
191
		
192
		gd = new GridData(GridData.FILL_HORIZONTAL);
193
		_txtName.setLayoutData(gd);
194
		
195
		initTabs(_grpFilterDetails);
196
		initAndButton(_grpFilterDetails);
197
		
198
		gd = new GridData(GridData.FILL_HORIZONTAL);
199
		gd.horizontalSpan = 2;
200
		_grpFilterDetails.setLayoutData(gd);
201
	}
202
	
203
	private void initTabs(Composite parent)
204
	{
205
		_tabFldr = new TabFolder(parent, SWT.NONE);
206
		
207
		initResourceTab(_tabFldr);
208
		initCapsTab(_tabFldr);
209
		initEPRTab(_tabFldr);
210
		
211
		GridData gd = new GridData(GridData.FILL_HORIZONTAL);
212
		gd.horizontalSpan = 2;
213
		_tabFldr.setLayoutData(gd);
214
	}
215
	
216
	private void initResourceTab(Composite parent)
217
	{
218
		_tiResName = new TabItem((TabFolder) parent, SWT.NONE);
219
		_tiResName.setText(Messages.getString("MAXFilter.RESNAME.UI."));
220
		
221
		Composite comp = new Composite(parent, SWT.NONE);
222
		comp.setLayout(new GridLayout(1, false));
223
		
224
		_txtResName = new Text(comp, SWT.BORDER);
225
		GridData gd = new GridData(GridData.FILL_HORIZONTAL);
226
		gd.grabExcessVerticalSpace = false;
227
		_txtResName.setLayoutData(gd);
228
		
229
		_tiResName.setControl(comp);
230
		
231
	}
232
	
233
	private void initCapsTab(Composite parent)
234
	{
235
		_tiCaps = new TabItem((TabFolder) parent, SWT.NONE);
236
		_tiCaps.setText(Messages.getString("MAXFilter.CAPABILITY.UI."));
237
		
238
		Composite comp = new Composite(parent, SWT.NONE);
239
		comp.setLayout(new GridLayout(2, false));
240
		
241
		_lblCapUri = new Label(comp, SWT.NONE);
242
		_lblCapUri.setText(Messages.getString("MAXFilter.CAPABILITY.URI.UI."));
243
		_txtCapUri = new Text(comp, SWT.BORDER);
244
		_txtCapUri.addModifyListener(new ModifyListener()
245
		{
246
			public void modifyText(ModifyEvent e) 
247
			{
248
				if(_txtCapUri.getText() == null || _txtCapUri.getText().trim().length() == 0)
249
				{
250
					_btnAddCapUri.setEnabled(false);
251
				}
252
				else
253
				{
254
					_btnAddCapUri.setEnabled(true);
255
				}
256
			}
257
		});
258
		
259
		_btnCapMatchAll = new Button(comp, SWT.CHECK);
260
		_btnCapMatchAll.setText(Messages.getString("MAXFilter.ANDFILTER.UI."));
261
		_btnCapMatchAll.setEnabled(false);
262
		
263
		_lstCapUris = new List(comp, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.SINGLE);
264
		
265
		_btnAddCapUri = new Button(comp, SWT.PUSH);
266
		_btnAddCapUri.setText(Messages.getString("MAXFilter.ADD_CAP_URI.UI."));
267
		_btnAddCapUri.setEnabled(false);
268
		
269
		_btnRemoveCapUri = new Button(comp, SWT.PUSH);
270
		_btnRemoveCapUri.setText(Messages.getString("MAXFilter.REM_CAP_URI.UI."));
271
		_btnRemoveCapUri.setEnabled(false);
272
		
273
		GridData gd = new GridData();
274
		_lblCapUri.setLayoutData(gd);
275
		
276
		gd = new GridData(GridData.FILL_HORIZONTAL);
277
		gd.grabExcessHorizontalSpace = true;
278
		_txtCapUri.setLayoutData(gd);
279
		
280
		gd = new GridData();
281
		gd.horizontalAlignment = SWT.BEGINNING;
282
		gd.horizontalSpan = 2;
283
		_btnCapMatchAll.setLayoutData(gd);
284
		
285
		gd = new GridData(GridData.FILL_VERTICAL);
286
		gd.widthHint = 100;
287
		gd.verticalSpan = 2;
288
		_lstCapUris.setLayoutData(gd);
289
		
290
		gd = new GridData();
291
		gd.horizontalAlignment = SWT.BEGINNING;
292
		gd.widthHint = 75;
293
		_btnAddCapUri.setLayoutData(gd);
294
		
295
		gd = new GridData();
296
		gd.horizontalAlignment = SWT.BEGINNING;
297
		gd.verticalAlignment = SWT.TOP;
298
		gd.widthHint = 75;
299
		_btnRemoveCapUri.setLayoutData(gd);
300
		
301
		_tiCaps.setControl(comp);
302
	}
303
	
304
	private void initEPRTab(Composite parent)
305
	{
306
		_tiEpr = new TabItem((TabFolder) parent, SWT.NONE);
307
		_tiEpr.setText(Messages.getString("MAXFilter.EPR.UI."));
308
		
309
		Composite comp = new Composite(parent, SWT.NONE);
310
		comp.setLayout(new GridLayout(2, false));
311
		
312
		_lblEprUri = new Label(comp, SWT.NONE);
313
		_lblEprUri.setText(Messages.getString("MAXFilter.EPRURI.UI."));
314
		
315
		_cmbEprUri = new Combo(comp, SWT.BORDER);
316
		_cmbEprUri.addModifyListener(new ModifyListener()
317
		{
318
			public void modifyText(ModifyEvent e) 
319
			{
320
				if(_cmbEprUri.getText() == null || _cmbEprUri.getText().trim().length() == 0)
321
				{
322
					_btnAddProperty.setEnabled(false);
323
				}
324
				else
325
				{
326
					_btnAddProperty.setEnabled(true);
327
				}
328
			}
329
		});
330
		
331
		_lblRefProperties = new Label(comp, SWT.NONE);
332
		_lblRefProperties.setText(Messages.getString("MAXFilter.REFPROP.UI."));
333
		
334
		initTable(comp);
335
		
336
		_btnAddProperty = new Button(comp, SWT.PUSH);
337
		_btnAddProperty.setText(Messages.getString("MAXFilter.ADDPROP.UI."));
338
		_btnAddProperty.setEnabled(false);
339
		
340
		_btnRemoveProperty = new Button(comp, SWT.PUSH);
341
		_btnRemoveProperty.setText(Messages.getString("MAXFilter.REMPROP.UI."));
342
		_btnRemoveProperty.setEnabled(false);
343
		
344
		GridData gd = new GridData(GridData.FILL_HORIZONTAL);
345
		gd.horizontalSpan = 2;
346
		_lblEprUri.setLayoutData(gd);
347
		
348
		gd = new GridData(GridData.FILL_HORIZONTAL);
349
		gd.horizontalSpan = 2;
350
		_cmbEprUri.setLayoutData(gd);
351
		
352
		gd = new GridData(GridData.FILL_HORIZONTAL);
353
		gd.horizontalSpan = 2;
354
		_lblRefProperties.setLayoutData(gd);
355
		
356
		gd = new GridData();
357
		_btnAddProperty.setLayoutData(gd);
358
		
359
		gd = new GridData(GridData.FILL_HORIZONTAL);
360
		gd.horizontalAlignment = SWT.BEGINNING;
361
		_btnRemoveProperty.setLayoutData(gd);
362
		
363
		_tiEpr.setControl(comp);
364
		
365
		//test
366
		_cmbEprUri.setText("http://localhost:8080/TP/services/TP");
367
		TableItem ti = new TableItem(_tblRefParams, SWT.NONE);
368
		ti.setText(new String[] {"muse-wsa", "http://ws.apache.org/muse/addressing", "ResourceId", "MuseResource-1"});
369
	}
370
	
371
	private void initTable(Composite comp)
372
	{
373
		_tblRefParams = new Table(comp, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.SINGLE);
374
		_tblRefParams.setLinesVisible(true);
375
		_tblRefParams.setHeaderVisible(true);
376
		
377
		TableColumn tcPfx = new TableColumn(_tblRefParams, SWT.NONE);
378
		tcPfx.setText(Messages.getString("MAXFilter.PREFIX.UI."));
379
		tcPfx.setWidth(110);
380
		
381
		TableColumn tcNs = new TableColumn(_tblRefParams, SWT.NONE);
382
		tcNs.setText(Messages.getString("MAXFilter.NS.UI."));
383
		tcNs.setWidth(110);
384
		
385
		TableColumn tcName = new TableColumn(_tblRefParams, SWT.NONE);
386
		tcName.setText(Messages.getString("MAXFilter.NAME.LABEL.UI."));
387
		tcName.setWidth(110);
388
		
389
		TableColumn tcVal = new TableColumn(_tblRefParams, SWT.NONE);
390
		tcVal.setText(Messages.getString("MAXFilter.VALUE.UI."));
391
		tcVal.setWidth(113);
392
		
393
		setInPlaceEditor(_tblRefParams);
394
		
395
		GridData gd = new GridData(GridData.FILL_HORIZONTAL);
396
		gd.horizontalSpan = 2;
397
		gd.heightHint = 75;
398
		_tblRefParams.setLayoutData(gd);
399
	}
400
	
401
	/**
402
	 * This code taken from SWT code snippets from the following URI
403
	 * http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet124.java?view=co
404
	 * @param table
405
	 */
406
	void setInPlaceEditor(final Table table)
407
	{
408
		final TableEditor editor = new TableEditor (table);
409
		editor.horizontalAlignment = SWT.LEFT;
410
		editor.grabHorizontal = true;
411
		table.addListener (SWT.MouseDown, new Listener () {
412
			public void handleEvent (Event event) {
413
				Rectangle clientArea = table.getClientArea ();
414
				Point pt = new Point (event.x, event.y);
415
				int index = table.getTopIndex ();
416
				while (index < table.getItemCount ()) {
417
					boolean visible = false;
418
					final TableItem item = table.getItem (index);
419
					for (int i=0; i<table.getColumnCount (); i++) {
420
						Rectangle rect = item.getBounds (i);
421
						if (rect.contains (pt)) {
422
							final int column = i;
423
							final Text text = new Text (table, SWT.NONE);
424
							Listener textListener = new Listener () {
425
								public void handleEvent (final Event e) {
426
									switch (e.type) {
427
										case SWT.FocusOut:
428
											item.setText (column, text.getText ());
429
											text.dispose ();
430
											break;
431
										case SWT.Traverse:
432
											switch (e.detail) {
433
												case SWT.TRAVERSE_RETURN:
434
													item.setText (column, text.getText ());
435
													//FALL THROUGH
436
												case SWT.TRAVERSE_ESCAPE:
437
													text.dispose ();
438
													e.doit = false;
439
											}
440
											break;
441
									}
442
								}
443
							};
444
							text.addListener (SWT.FocusOut, textListener);
445
							text.addListener (SWT.Traverse, textListener);
446
							editor.setEditor (text, item, i);
447
							text.setText (item.getText (i));
448
							text.selectAll ();
449
							text.setFocus ();
450
							return;
451
						}
452
						if (!visible && rect.intersects (clientArea)) {
453
							visible = true;
454
						}
455
					}
456
					if (!visible) return;
457
					index++;
458
				}
459
			}
460
		});
461
	}
462
	
463
	private void initAndButton(Composite parent)
464
	{
465
		_btnAnd = new Button(parent, SWT.CHECK);
466
		_btnAnd.setText(Messages.getString("MAXFilter.ANDFILTER.UI."));
467
		
468
		GridData gd = new GridData(GridData.FILL_HORIZONTAL);
469
		gd.horizontalSpan = 2;
470
		_btnAnd.setLayoutData(gd);
471
	}
472
	
473
	private void initButtons(Composite parent)
474
	{
475
		_btnApply = new Button(parent, SWT.PUSH);
476
		_btnApply.setText(Messages.getString("MAXFilter.APPLY.UI."));
477
		
478
		_btnCancel = new Button(parent, SWT.PUSH);
479
		_btnCancel.setText(Messages.getString("MAXFilter.CANCEL.UI."));
480
		
481
		GridData gd = new GridData(GridData.FILL_HORIZONTAL);
482
		gd.grabExcessHorizontalSpace = true;
483
		gd.horizontalAlignment = SWT.END;
484
		gd.widthHint = 75;
485
		_btnApply.setLayoutData(gd);
486
		
487
		gd = new GridData();
488
		gd.widthHint = 75;
489
		_btnCancel.setLayoutData(gd);
490
	}
491
	
492
	private void centralizeWindow()
493
	{
494
		Toolkit tk = Toolkit.getDefaultToolkit();
495
		Dimension scrSize = tk.getScreenSize();
496
		int wdth = scrSize.width;
497
		int hght = scrSize.height;
498
		int x = (wdth - 500)/2;
499
		int y = (hght - 440)/2;
500
		_shell.setLocation(x, y);
501
	}
502
	
503
	
504
	public Filter showWindow()
505
	{
506
		_shell.open ();
507
		while (!_shell.isDisposed ()) {
508
			if (!_disp.readAndDispatch ()) _disp.sleep ();
509
		}
510
		return _filter;
511
	}
512
	
513
	private void addExistingFilterNames()
514
	{
515
		//_cmbExistingFilters.add("None");
516
		java.util.List filters = MaxFilterPreference.getFilters();
517
		if(filters == null || filters.size() == 0)
518
		{
519
			_cmbExistingFilters.setItems(new String[]{"None"});
520
			_cmbExistingFilters.select(1);
521
			return;
522
		}
523
		String filterNames[] = new String[filters.size() + 1];
524
		filterNames[0] = "None";
525
		for(int i = 0; i < filters.size(); i++)
526
		{
527
			Filter f = (Filter) filters.get(i);
528
			String fName = f.getFilterName();
529
			if(fName == null || fName.trim().length() == 0)
530
				fName = "NoName--" + (i + 1);
531
			filterNames[i + 1] = fName; 
532
			//_cmbExistingFilters.add(f.getFilterName());
533
			Map mp = FilterUtil.getEPRMap(f.getEpr());
534
			if(mp == null || mp.size() == 0)
535
				continue;
536
			String addrURL = (String) mp.get(FilterUtil.ADDRESS_KEY);
537
			if(addrURL == null || addrURL.trim().length() == 0)
538
			{
539
				continue;
540
			}
541
			_cmbEprUri.add(addrURL);
542
		}
543
		_cmbExistingFilters.setItems(filterNames);
544
		_cmbExistingFilters.select(1);
545
	}
546
	
547
	private void loadFilter()
548
	{
549
		String fName = _cmbExistingFilters.getText(); 
550
		if(fName == null || fName.trim().length() == 0)
551
			return;
552
		fName = fName.trim();
553
		if(fName.equals("None"))
554
		{
555
			clearAll();
556
			return;
557
		}
558
		else
559
		{
560
			_btnDeleteFilter.setEnabled(true);
561
		}
562
		Filter f = getFilterFromName(fName);
563
		loadFilterDetails(f);
564
		notifyListeners();
565
	}
566
	
567
	public void clearAll()
568
	{
569
		_btnDeleteFilter.setEnabled(false);
570
		_txtName.setText("");
571
		_txtResName.setText("");
572
		_txtCapUri.setText("");
573
		_lstCapUris.removeAll();
574
		_cmbEprUri.setText("");
575
		_tblRefParams.removeAll();
576
	}
577
	
578
	private void notifyListeners()
579
	{
580
		_txtCapUri.notifyListeners(SWT.Modify, _event);
581
		_lstCapUris.notifyListeners(SWT.Selection, _event);
582
		_btnAddCapUri.notifyListeners(SWT.Modify, _event);
583
		_cmbEprUri.notifyListeners(SWT.Modify, _event);
584
		_tblRefParams.notifyListeners(SWT.Selection, _event);
585
	}
586
	
587
	private Filter getFilterFromName(String name)
588
	{
589
		java.util.List filters = MaxFilterPreference.getFilters();
590
		if(filters == null || filters.size() == 0)
591
			return null;
592
		for(int i = 0; i < filters.size(); i++)
593
		{
594
			Filter f = (Filter) filters.get(i);
595
			if(f.getFilterName().trim().equals(name))
596
				return f;
597
		}
598
		return null;
599
	}
600
	
601
	private void loadFilterDetails(Filter f)
602
	{
603
		if(f == null)
604
		{
605
			MessageDialog.openError(_shell, Messages.getString("MAXFilter.Filter.Error.Title."), Messages.getString("MAXFilter.Filter.Load.Error."));
606
			return;
607
		}
608
		_txtName.setText(f.getFilterName());
609
		_txtResName.setText(f.getResName().equals("NO-RN") ? "" : f.getResName());
610
		if(!f.getCapUris()[0].equals("NO-CAP"))
611
			_lstCapUris.setItems(f.getCapUris());
612
		if(_lstCapUris.getItemCount() > 2)
613
		{
614
			_btnCapMatchAll.setEnabled(true);
615
		}
616
		else
617
		{
618
			_btnCapMatchAll.setEnabled(false);
619
		}
620
		if(f.getOverallMatch() == 1)
621
		{
622
			_btnAnd.setSelection(true);
623
		}
624
		else
625
		{
626
			_btnAnd.setSelection(false);
627
		}
628
		if(f.getCapMatch() == 1)
629
		{
630
			_btnCapMatchAll.setSelection(true);
631
		}
632
		else
633
		{
634
			_btnCapMatchAll.setSelection(false);
635
		}
636
		String eprStr = f.getEpr();
637
		if(eprStr.trim().equals("NO-EPR"))
638
			return;
639
		Map mp = FilterUtil.getEPRMap(eprStr);
640
		if(mp == null || mp.size() == 0)
641
			return;
642
		String addrURL = (String) mp.get(FilterUtil.ADDRESS_KEY);
643
		if(addrURL == null || addrURL.trim().length() == 0)
644
		{
645
			MessageDialog.openError(_shell, Messages.getString("MAXFilter.Filter.Error.Title."), Messages.getString("MAXFilter.Filter.Load.Error."));
646
			return;
647
		}
648
		_cmbEprUri.setText(addrURL);
649
		String[] params = (String[]) mp.get(FilterUtil.REFPARAMS_KEY);
650
		if(params == null || params.length == 0)
651
			return;
652
		for(int i = 0; i < params.length; i++)
653
		{
654
			if(params[i] == null || params[i].trim().length() == 0)
655
				continue;
656
			TableItem ti = new TableItem(_tblRefParams, SWT.NONE);
657
			ti.setText(FilterUtil.getParamPrefString(params[i]));
658
		}
659
	}
660
	
661
	/*public static void main(String args[])
662
	{
663
		new FilterDialog().showWindow();
664
	}*/
665
666
	public Shell getShell() {
667
		return _shell;
668
	}
669
670
	public Combo getCmbExistingFilters() {
671
		return _cmbExistingFilters;
672
	}
673
674
	public Button getBtnNewFilter() {
675
		return _btnNewFilter;
676
	}
677
678
	public Button getBtnDeleteFilter() {
679
		return _btnDeleteFilter;
680
	}
681
682
	public Text getTxtName() {
683
		return _txtName;
684
	}
685
686
	public Button getBtnApply() {
687
		return _btnApply;
688
	}
689
690
	public Button getBtnCancel() {
691
		return _btnCancel;
692
	}
693
694
	public Button getBtnAnd() {
695
		return _btnAnd;
696
	}
697
698
	public Button getBtnAddCapUri() {
699
		return _btnAddCapUri;
700
	}
701
	
702
	public Button getBtnRemCapUri() {
703
		return _btnRemoveCapUri;
704
	}
705
706
	public Text getTxtResName() {
707
		return _txtResName;
708
	}
709
710
	public List getLstCapUris() {
711
		return _lstCapUris;
712
	}
713
714
	public Text getTxtCapUri() {
715
		return _txtCapUri;
716
	}
717
718
	public Button getBtnCapMatchAll() {
719
		return _btnCapMatchAll;
720
	}
721
722
	public Combo getCmbEprUri() {
723
		return _cmbEprUri;
724
	}
725
726
	public Table getTblRefParams() {
727
		return _tblRefParams;
728
	}
729
730
	public Button getBtnAddProperty() {
731
		return _btnAddProperty;
732
	}
733
734
	public Button getBtnRemoveProperty() {
735
		return _btnRemoveProperty;
736
	}
737
	
738
	public Filter getFilter()
739
	{
740
		return _filter;
741
	}
742
	
743
	public void setFilter(Filter f)
744
	{
745
		this._filter = f;
746
	}
747
}
(-)src/org/eclipse/tptp/monitoring/managedagent/ui/explorer/internal/filter/Comparator.java (+23 lines)
Added Link Here
1
package org.eclipse.tptp.monitoring.managedagent.ui.explorer.internal.filter;
2
3
import org.eclipse.jface.viewers.ViewerComparator;
4
import org.eclipse.tptp.monitoring.managedagent.ui.explorer.provisional.controller.CollectionNode;
5
import org.eclipse.tptp.monitoring.managedagent.ui.explorer.provisional.controller.OperationNode;
6
import org.eclipse.tptp.monitoring.managedagent.ui.explorer.provisional.controller.PropertyNode;
7
import org.eclipse.tptp.monitoring.managedagent.ui.explorer.provisional.controller.PropertySourceCollectionNode;
8
9
public class Comparator extends ViewerComparator {
10
11
	public int category(Object element)
12
	{
13
		if(element instanceof PropertySourceCollectionNode)
14
			return 1;
15
		else if(element instanceof CollectionNode)
16
			return 2;
17
		else if(element instanceof OperationNode)
18
			return 3;
19
		else if(element instanceof PropertyNode)
20
			return 4;
21
		return 0;
22
	}
23
}
(-)src/org/eclipse/tptp/monitoring/managedagent/ui/explorer/internal/filter/ComponentSelectionListener.java (+179 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 * 	Balan Subramanian (bsubram@us.ibm.com)
10
 *     IBM Corporation - initial API and implementation
11
 *******************************************************************************/
12
13
package org.eclipse.tptp.monitoring.managedagent.ui.explorer.internal.filter;
14
15
import org.eclipse.swt.SWT;
16
import org.eclipse.swt.events.SelectionAdapter;
17
import org.eclipse.swt.events.SelectionEvent;
18
import org.eclipse.swt.widgets.TableItem;
19
20
import sun.rmi.runtime.GetThreadPoolAction;
21
22
public class ComponentSelectionListener extends SelectionAdapter 
23
{
24
	private FilterDialog _dialog;
25
	
26
	public ComponentSelectionListener(FilterDialog dlg)
27
	{
28
		this._dialog = dlg;
29
		addListeners();
30
	}
31
	
32
	private void addListeners()
33
	{
34
		_dialog.getBtnAddCapUri().addSelectionListener(this);
35
		_dialog.getBtnRemCapUri().addSelectionListener(this);
36
		_dialog.getLstCapUris().addSelectionListener(this);
37
		_dialog.getBtnAddProperty().addSelectionListener(this);
38
		_dialog.getBtnApply().addSelectionListener(this);
39
		_dialog.getBtnCancel().addSelectionListener(this);
40
		_dialog.getBtnDeleteFilter().addSelectionListener(this);
41
		_dialog.getBtnNewFilter().addSelectionListener(this);
42
		_dialog.getBtnRemoveProperty().addSelectionListener(this);
43
		_dialog.getTblRefParams().addSelectionListener(this);
44
	}
45
	
46
	public void widgetSelected(SelectionEvent e) 
47
	{
48
		Object src = e.getSource();
49
		if(src == _dialog.getBtnAddProperty())
50
		{
51
			TableItem ti = new TableItem(_dialog.getTblRefParams(), SWT.NONE);
52
			ti.setText(new String[] {"pfx", "ns", "Name"});
53
		}
54
		else if(src == _dialog.getBtnRemoveProperty())
55
		{
56
			_dialog.getBtnRemoveProperty().setEnabled(false);
57
			int selIdx = _dialog.getTblRefParams().getSelectionIndex();
58
			if(selIdx == -1)
59
			{
60
				return;
61
			}
62
			_dialog.getTblRefParams().remove(selIdx);
63
		}
64
		else if(src == _dialog.getBtnAddCapUri())
65
		{
66
			_dialog.getLstCapUris().add(_dialog.getTxtCapUri().getText().trim());
67
			if(_dialog.getLstCapUris().getItemCount() > 1)
68
			{
69
				_dialog.getBtnCapMatchAll().setEnabled(true);
70
			}
71
			else
72
			{
73
				_dialog.getBtnCapMatchAll().setSelection(false);
74
				_dialog.getBtnCapMatchAll().setEnabled(false);
75
			}
76
			_dialog.getTxtCapUri().setText("");
77
			_dialog.getBtnAddCapUri().setEnabled(false);
78
		}
79
		else if(src == _dialog.getBtnRemCapUri())
80
		{
81
			_dialog.getBtnRemCapUri().setEnabled(false);
82
			int selIdx = _dialog.getLstCapUris().getSelectionIndex();
83
			if(selIdx == -1)
84
				return;
85
			_dialog.getLstCapUris().remove(selIdx);
86
			if(_dialog.getLstCapUris().getItemCount() > 1)
87
			{
88
				_dialog.getBtnCapMatchAll().setEnabled(true);
89
			}
90
			else
91
			{
92
				_dialog.getBtnCapMatchAll().setSelection(false);
93
				_dialog.getBtnCapMatchAll().setEnabled(false);
94
			}
95
		}
96
		else if(src == _dialog.getLstCapUris())
97
		{
98
			if(_dialog.getLstCapUris().getSelectionIndex() != -1)
99
			{
100
				_dialog.getBtnRemCapUri().setEnabled(true);
101
			}
102
			else
103
			{
104
				_dialog.getBtnRemCapUri().setEnabled(false);
105
			}
106
		}
107
		else if(src == _dialog.getBtnApply())
108
		{
109
			Filter filter = FilterUtil.getFilterFromDialog(_dialog);
110
			if(filter == null)
111
			{
112
				return;
113
			}
114
			int fIdx = getFilterIndex(filter);
115
			if(fIdx == -1) //Indicates new filter
116
			{
117
				MaxFilterPreference.getFilters().add(filter);
118
			}
119
			else
120
			{
121
				MaxFilterPreference.getFilters().remove(fIdx);
122
				MaxFilterPreference.getFilters().add(fIdx, filter);
123
			}
124
			_dialog.setFilter(filter);
125
			MaxFilterPreference.saveFilters();
126
			_dialog.getShell().dispose();
127
		}
128
		else if(src == _dialog.getBtnCancel())
129
		{
130
			_dialog.setFilter(null);
131
			_dialog.getShell().dispose();
132
		}
133
		else if(src == _dialog.getBtnNewFilter())
134
		{
135
			_dialog.getCmbExistingFilters().select(0);
136
			//_dialog.getCmbExistingFilters().setEnabled(false);
137
			_dialog.clearAll();
138
		}
139
		else if(src == _dialog.getBtnDeleteFilter())
140
		{
141
			int idx = _dialog.getCmbExistingFilters().getSelectionIndex();
142
			if(idx == -1 || idx == 0)
143
			{
144
				return;
145
			}
146
			MaxFilterPreference.getFilters().remove(idx - 1);
147
			MaxFilterPreference.saveFilters();
148
			_dialog.getCmbExistingFilters().remove(idx);
149
			_dialog.getBtnDeleteFilter().setEnabled(false);
150
			_dialog.getCmbExistingFilters().select(0);
151
		}
152
		else if(src == _dialog.getTblRefParams())
153
		{
154
			int selCnt = _dialog.getTblRefParams().getSelectionCount();
155
			if(selCnt == 0)
156
			{
157
				_dialog.getBtnRemoveProperty().setEnabled(false);
158
			}
159
			else if(selCnt == 1)
160
			{
161
				_dialog.getBtnRemoveProperty().setEnabled(true);
162
			}
163
		}
164
	}
165
	
166
	private int getFilterIndex(Filter f)
167
	{
168
		java.util.List filters = MaxFilterPreference.getFilters();
169
		if(filters == null || filters.size() == 0)
170
			return -1;
171
		for(int i = 0; i < filters.size(); i++)
172
		{
173
			Filter f1 = (Filter) filters.get(i);
174
			if(f1.equals(f))
175
				return i;
176
		}
177
		return -1;
178
	}
179
}
(-)src/org/eclipse/tptp/monitoring/managedagent/ui/explorer/internal/filter/Filter.java (+254 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 * 	Balan Subramanian (bsubram@us.ibm.com)
10
 *     IBM Corporation - initial API and implementation
11
 *******************************************************************************/
12
13
package org.eclipse.tptp.monitoring.managedagent.ui.explorer.internal.filter;
14
15
import java.util.Map;
16
import java.util.StringTokenizer;
17
18
public class Filter 
19
{
20
	private String _filterName;
21
	
22
	private String _resName;
23
	
24
	private String[] _capUris;
25
	
26
	private String _epr;
27
	
28
	private int _overallMatch = 0; //0 indicates OR and 1 indicates AND
29
	
30
	private int _capMatch = 0;
31
	
32
	private Object[] _filter;
33
	
34
	public static final int MATCH_ALL = 1;
35
	
36
	public static final int MATCH_ANY = 0;
37
	
38
	public Filter()
39
	{
40
		
41
	}
42
43
	private Object[] createFilter()
44
	{
45
		Object[] filter = new Object[5];
46
		String matchCriteria = "OR";
47
		if(getOverallMatch() == 1)
48
		{
49
			matchCriteria = "AND";
50
		}
51
		filter[0] = _resName;
52
		filter[1] = matchCriteria;
53
		String[] capUriFilter = createCapUriFilter(_capUris);
54
		filter[2] = capUriFilter;
55
		filter[3] = matchCriteria;
56
		filter[4] = _epr;
57
		return filter;
58
	}
59
	
60
	
61
	private String[] createCapUriFilter(String[] uris)
62
	{
63
		String filt = getCapUriPrefString(uris);
64
		if(filt.equals("NO-CAP"))
65
		{
66
			return new String[] {"NO-CAP"};
67
		}
68
		if(filt.indexOf('&') == -1 && filt.indexOf('|') == -1)
69
		{
70
			return new String[] {filt};
71
		}
72
		String separChar = "|";
73
		if(filt.indexOf('&') != -1)
74
			separChar = "&";
75
		StringTokenizer st = new StringTokenizer(filt, separChar);
76
		String caps[] = new String[2 * st.countTokens() - 1];
77
		int idx = 0;
78
		while(st.hasMoreTokens())
79
		{
80
			caps[idx] = st.nextToken();
81
			idx ++;
82
			if(idx == caps.length)
83
				break;
84
			if(separChar.equals("|"))
85
				caps[idx] = "OR";
86
			else
87
				caps[idx] = "AND";
88
			idx ++;
89
		}
90
		return caps;
91
	}
92
	
93
	private String getCapUriPrefString(String uris[])
94
	{
95
		if(uris == null || uris.length == 0)
96
		{
97
			return "NO-CAP";
98
		}
99
		if(uris.length == 1 && uris[0].equals("NO-CAP"))
100
		{
101
			return "NO-CAP";
102
		}
103
		char matchCriteria = '|';
104
		if(getCapMatch() == 1)
105
		{
106
			matchCriteria = '&';
107
		}
108
		String filt = "";
109
		for(int i = 0; i < uris.length; i++)
110
		{
111
			if(i < uris.length - 1)
112
			{
113
				filt += uris[i] + matchCriteria;
114
			}
115
			else
116
			{
117
				filt += uris[i];
118
			}
119
		}
120
		return filt;
121
	}
122
	
123
	
124
	public String getFilterName() 
125
	{
126
		return _filterName;
127
	}
128
129
	public String getResName() 
130
	{
131
		return _resName;
132
	}
133
134
	public String[] getCapUris() 
135
	{
136
		return _capUris;
137
	}
138
139
	public String getEpr() 
140
	{
141
		return _epr;
142
	}
143
144
	public void setFilterName(String name) 
145
	{
146
		_filterName = name;
147
	}
148
149
	public void setResName(String name) 
150
	{
151
		_resName = name;
152
	}
153
154
	public void setCapUris(String[] uris) 
155
	{
156
		_capUris = uris;
157
	}
158
159
	public void setEpr(String epr) 
160
	{
161
		this._epr = epr;
162
	}
163
164
	public int getOverallMatch() {
165
		return _overallMatch;
166
	}
167
168
	
169
	public void setOverallMatch(int match) 
170
	{
171
		this._overallMatch = match;
172
	}
173
174
	public int getCapMatch() 
175
	{
176
		return _capMatch;
177
	}
178
179
	public void setCapMatch(int match) 
180
	{
181
		this._capMatch = match;
182
	}
183
184
	public Object[] getFilter() 
185
	{
186
		if(_filter == null)
187
			_filter = createFilter();
188
		return _filter;
189
	}
190
	
191
	public String toString()
192
	{
193
		//send it like "FilterName->[resName]|/&[capuri1|/&capuri2|/&...]|/&[addr(pfx+ns+name+val,....)]";
194
		String fStr = "";
195
		char match = '|';
196
		fStr += _filterName + "->";
197
		if(_overallMatch == 1)
198
			match = '&';
199
		if(_resName == null || _resName.trim().length() == 0)
200
		{
201
			_resName = "NO-RN";
202
		}
203
		String capUriStr = getCapUriPrefString(_capUris);
204
		String eprStr = getEPRPrefString(_epr);
205
		return _filterName + "->[" + _resName + "]" + match + "[" + capUriStr + "]" + match + "[" + eprStr + "]";
206
		//return "";
207
	}
208
	
209
	private String getEPRPrefString(String es)
210
	{
211
		//send it like addr$(pfx+ns+name+val,....)
212
		Map eprMap = FilterUtil.getEPRMap(es);
213
		if(eprMap == null)
214
			return "NO-EPR";
215
		String addr = (String) eprMap.get(FilterUtil.ADDRESS_KEY);
216
		String retStr = addr;
217
		String[] params = (String[]) eprMap.get(FilterUtil.REFPARAMS_KEY);
218
		if(params == null || params.length == 0)
219
			return retStr;
220
		for(int i = 0; i < params.length; i++)
221
		{
222
			if(params[i] == null || params[i].trim().length() == 0)
223
				continue;
224
			if(retStr.indexOf('(') == -1)
225
				retStr += '(';
226
			if(i < params.length - 1)
227
				retStr += getParamPrefString(params[i]) + ',';
228
			else
229
				retStr += getParamPrefString(params[i]);
230
		}
231
		if(retStr.indexOf('(') != -1)
232
			retStr += ')';
233
		return retStr;
234
	}
235
	
236
	public boolean equals(Object o)
237
	{
238
		if(o == null)
239
			return false;
240
		if(o instanceof Filter)
241
		{
242
			if(this.getFilterName().trim().equals(((Filter) o).getFilterName().trim()))
243
					return true;
244
		}
245
		return false;
246
	}
247
	
248
	private String getParamPrefString(String param)
249
	{
250
		// <muse-wsa:ResourceId xmlns:muse-wsa="http://ws.apache.org/muse/addressing">MuseResource-1</muse-wsa:ResourceId>
251
		String pa[] = FilterUtil.getParamPrefString(param);
252
		return pa[0] + "+" + pa[1] + "+" + pa[2] + "+" + pa[3];
253
	}
254
}
(-)src/org/eclipse/tptp/monitoring/managedagent/ui/explorer/internal/filter/messages.properties (+50 lines)
Added Link Here
1
###############################################################################
2
# Copyright (c) 2006 IBM Corporation and others.
3
# All rights reserved. This program and the accompanying materials
4
# are made available under the terms of the Eclipse Public License v1.0
5
# which accompanies this distribution, and is available at
6
# http://www.eclipse.org/legal/epl-v10.html
7
# 
8
# Contributors:
9
# 	Balan Subramanian (bsubram@us.ibm.com)
10
#     IBM Corporation - initial API and implementation
11
###############################################################################
12
13
# NLS_MESSAGEFORMAT_VAR
14
# NLS_ENCODING=UTF-8
15
16
MAXFilter.APPLY.UI.=Apply
17
MAXFilter.PROPERTY.UI.=Property
18
MAXFilter.VALUE.UI.=Value
19
MAXFilter.DETAILS.UI.=Details
20
MAXFilter.FILTER.TITLE.UI.=Specify Filter Criteria
21
MAXFilter.EXFILTER.UI.=Existing Filters
22
MAXFilter.NAME.LABEL.UI.=Name
23
MAXFilter.ANDFILTER.UI.=Match All
24
MAXFilter.CANCEL.UI.=Cancel
25
MAXFilter.RESNAME.UI.=Resource Name
26
MAXFilter.CAPABILITY.UI.=Capabilities
27
MAXFilter.EPR.UI.=End Point Reference
28
MAXFilter.NEW.FILTER.UI.=Create New
29
MAXFilter.CAPABILITY.URI.UI.=Namespace URI
30
MAXFilter.ADD_CAP_URI.UI.=Add
31
MAXFilter.REM_CAP_URI.UI.=Remove
32
MAXFilter.ADDPROP.UI.=Add Property
33
MAXFilter.REMPROP.UI.=Remove Property
34
MAXFilter.EPRURI.UI.=Specify the URI
35
MAXFilter.REFPROP.UI.=Reference Properties
36
MAXFilter.PREFIX.UI.=Prefix
37
MAXFilter.NS.UI.=Namespace
38
MAXFilter.DELETE.FILTER.UI.=Delete
39
40
41
# ERROR_MESSAGES
42
MAXFilter.Filter.Error.Title.=Error
43
MAXFilter.Filter.Name.Error.=The filter name is not valid.
44
MAXFilter.Filter.Name.Duplicate.Error.=The specified filter name already exists.
45
MAXFilter.Filter.Invalid.Error.=No filter criteria specified.\n Please specify any one of the filter criteria.
46
MAXFilter.Filter.Prefix.Error.=Please enter the prefix for the parameter
47
MAXFilter.Filter.NS.Error.=Please enter the name space for the parameter
48
MAXFilter.Filter.PropName.Error.=Please enter the name for the parameter
49
MAXFilter.Filter.Value.Error.=Please enter the value for the parameter
50
MAXFilter.Filter.Load.Error.=Could not load the selected filter
(-)src/org/eclipse/tptp/monitoring/managedagent/ui/explorer/internal/filter/MaxFilterPreference.java (+165 lines)
Added Link Here
1
package org.eclipse.tptp.monitoring.managedagent.ui.explorer.internal.filter;
2
3
import java.util.ArrayList;
4
import java.util.HashMap;
5
import java.util.List;
6
import java.util.Map;
7
import java.util.StringTokenizer;
8
9
import org.eclipse.jface.preference.IPreferenceStore;
10
import org.eclipse.jface.preference.PreferenceStore;
11
import org.eclipse.tptp.monitoring.managedagent.ui.explorer.internal.ManagedAgentUIPlugin;
12
13
public class MaxFilterPreference 
14
{
15
	private static IPreferenceStore _prefs;
16
	
17
	private static ArrayList _filters = new ArrayList();
18
	
19
	public static final String PREF_FILTERS = "FILTERS";
20
	
21
	private String filePath = "D:\\Eclipse_Europa\\Workspace_From_13_Feb_07\\org.eclipse.tptp.monitoring.managedagent.ui\\filterPrefs.properties";
22
	
23
	public MaxFilterPreference()
24
	{
25
		_prefs = new PreferenceStore(filePath);
26
	}
27
	
28
	public static void loadFilters()
29
	{
30
		if(_prefs == null)
31
			_prefs = ManagedAgentUIPlugin.getDefault().getPreferenceStore();
32
		_filters = new ArrayList();
33
		String filters = _prefs.getString(PREF_FILTERS);
34
		if(filters == null || filters.trim().length() == 0)
35
		{
36
			return;
37
		}
38
		StringTokenizer st = new StringTokenizer(filters, ";");
39
		while(st.hasMoreTokens())
40
		{
41
			Filter f = getFilterFromPrefString(st.nextToken());
42
			if(f != null)
43
				_filters.add(f);
44
		}
45
	}
46
	
47
	private static Filter getFilterFromPrefString(String ps)
48
	{
49
		if(ps == null || ps.trim().length() == 0)
50
			return null;
51
		
52
		String name = ps.substring(0, ps.indexOf("->"));
53
		if(name == null)
54
			name = "";
55
		
56
		String resName = ps.substring(ps.indexOf('[') + 1, ps.indexOf(']'));
57
		if(resName == null)
58
			resName = "NO-RN";
59
		
60
		String match = ps.indexOf("]|") == -1 ? "]&" : "]|";		
61
		String capUriStr =  ps.substring(ps.indexOf(match) + 3, ps.lastIndexOf(match));
62
		String capUris[] = getCapUrisFromPrefString(capUriStr);
63
		String rawEprStr = ps.substring(ps.lastIndexOf('[') + 1, ps.lastIndexOf(']'));
64
		String eprStr = getEPRFromPrefString(rawEprStr);
65
		
66
		int overAllMatch = match.indexOf('&') == -1 ? 0 : 1;
67
		int capMatch = capUriStr.indexOf('&') == -1 ? 0 : 1;
68
		
69
		Filter f = new Filter();
70
		f.setFilterName(name);
71
		f.setResName(resName);
72
		f.setCapUris(capUris);
73
		f.setEpr(eprStr);
74
		f.setCapMatch(capMatch);
75
		f.setOverallMatch(overAllMatch);
76
		
77
		return f;
78
	}
79
	
80
	private static String[] getCapUrisFromPrefString(String uris)
81
	{
82
		if(uris == null || uris.trim().length() == 0 || uris.equals("NO-CAP"))
83
			return new String[] {"NO-CAP"};
84
		String separChar = "|";
85
		if(uris.indexOf('&') != -1)
86
			separChar = "&";
87
		StringTokenizer st = new StringTokenizer(uris, separChar);
88
		String caps[] = new String[st.countTokens()];
89
		int idx = 0;
90
		while(st.hasMoreTokens())
91
		{
92
			caps[idx] = st.nextToken();
93
			idx ++;
94
			if(idx == caps.length)
95
				break;
96
		}
97
		return caps;
98
	}
99
	
100
	private static String getEPRFromPrefString(String rawStr)
101
	{
102
		if(rawStr == null)
103
			return "NO-EPR";
104
		if(rawStr.trim().equals("NO-EPR") || rawStr.indexOf('(') == -1)
105
			return rawStr.trim();
106
		Map map = formatRawEPR(rawStr);
107
		if(map == null || map.size() == 0)
108
			return "NO-EPR";
109
		Object[] keys = map.keySet().toArray();
110
		String addrURL = (String) keys[0];
111
		String[][] params = (String[][]) map.get(addrURL);
112
		return FilterUtil.getEPRString(addrURL, params);
113
	}
114
	
115
	private static Map formatRawEPR(String rawEpr)
116
	{
117
		rawEpr = rawEpr.trim();
118
		String addrURL = rawEpr.substring(0, rawEpr.indexOf('('));
119
		String paramStr = rawEpr.substring(rawEpr.indexOf('(') + 1, rawEpr.lastIndexOf(')'));
120
		StringTokenizer st = new StringTokenizer(paramStr, ",");
121
		String[][] params = new String[st.countTokens()][4];
122
		int idx = 0;
123
		while(st.hasMoreTokens())
124
		{
125
			String param = st.nextToken();
126
			if(param == null || param.trim().length() == 0)
127
				continue;
128
			StringTokenizer st1 = new StringTokenizer(param, "+");
129
			if(st1.countTokens() != 4)
130
				continue;
131
			for(int i = 0; i < 4; i++)
132
			{
133
				params[idx][i] = st1.nextToken();
134
			}
135
			idx ++;
136
		}
137
		Map map = new HashMap();
138
		map.put(addrURL, params);
139
		return map;
140
	}
141
	
142
	public static void saveFilters()
143
	{
144
		if(_filters == null || _filters.size() == 0)
145
		{
146
			_prefs.putValue(PREF_FILTERS, "");
147
			return;
148
		}
149
		String fs = "";
150
		for(int i = 0; i < _filters.size(); i++)
151
		{
152
			Filter f = (Filter) _filters.get(i);
153
			if(i < _filters.size() - 1)
154
				fs += f.toString() + ";";
155
			else
156
				fs += f.toString();
157
		}
158
		_prefs.setValue(PREF_FILTERS, fs);
159
	}
160
	
161
	public static List getFilters()
162
	{
163
		return _filters;
164
	}
165
}
(-)icons/obj16/filter.gif (+2 lines)
Added Link Here
1
GIF89aÄ8D]ov„Wd|w„še}”\…¥T‹³MZ]þýïýòÆýñÆýñÇýòÇü枽„®uº€º?´z´{¹€¹€ªo©o¯t®t¯t¦kÿÿÿ!ù,X 'Ždiã`–Á!ª¦QAí«؊B>¢"Çá𕈢‰R¡@(
2
)M	†BÁH,¶’Ò#óÐd0˜Fãa]–?#Ülr;N/6«ípx.€r)&!;
(-)src/org/eclipse/tptp/monitoring/managedagent/ui/explorer/internal/filter/FilterUtil.java (+459 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 * 	Balan Subramanian (bsubram@us.ibm.com)
10
 *     IBM Corporation - initial API and implementation
11
 *******************************************************************************/
12
13
package org.eclipse.tptp.monitoring.managedagent.ui.explorer.internal.filter;
14
15
import java.util.ArrayList;
16
import java.util.HashMap;
17
import java.util.Hashtable;
18
import java.util.List;
19
import java.util.Map;
20
21
import org.eclipse.emf.common.util.EList;
22
import org.eclipse.jface.dialogs.MessageDialog;
23
import org.eclipse.swt.widgets.TableItem;
24
import org.eclipse.tptp.monitoring.managedagent.provisional.model.ManagedResource;
25
import org.eclipse.tptp.monitoring.managedagent.provisional.model.Property;
26
import org.eclipse.tptp.monitoring.managedagent.provisional.model.util.ModelUtils;
27
import org.eclipse.tptp.monitoring.managedagent.ui.explorer.internal.ManagedAgentUIPlugin;
28
import org.eclipse.tptp.monitoring.managedagent.ui.launch.provisional.common.IConnectionHelper;
29
30
public class FilterUtil 
31
{
32
	
33
	private static Filter filter;
34
	
35
	private static String resName;
36
	
37
	private static String[] capUris;
38
	
39
	private static String epr;
40
	
41
	private static Object[] filt;
42
	
43
	public static final String ADDRESS_KEY = "Address";
44
	
45
	public static final String REFPARAMS_KEY = "RefParams";
46
	
47
	private static Map _conf = null;
48
	
49
	private static ManagedResource _mr = null;
50
	
51
	public static boolean matchFilter(ManagedResource mr)
52
	{
53
		_mr = mr;
54
		boolean match = false;
55
		_conf = ModelUtils.getMapFromConnProperties(mr.getConnectionProperties());
56
		String mrName = mr.getName();
57
		String mrEpr = (String) _conf.get("epr");
58
		String caps[] = getImplementedCapabilities(mr);
59
		if(filt[1].equals("AND"))
60
		{
61
			match = matchResourceName(mrName, 1) && matchCapabilities(caps, 1) && matchEPR(mrEpr, 1);
62
			System.out.println(matchResourceName(mrName, 1) + " && " +  matchCapabilities(caps, 1) + " && " + matchEPR(mrEpr, 1));
63
		}
64
		else
65
		{
66
			match = matchResourceName(mrName, 0) || matchCapabilities(caps, 0) || matchEPR(mrEpr, 0);
67
			System.out.println(matchResourceName(mrName, 1) + " || " +  matchCapabilities(caps, 1) + " || " + matchEPR(mrEpr, 1));
68
		}
69
		
70
		return match;
71
	}
72
	
73
	private static String[] getImplementedCapabilities(ManagedResource mr)
74
	{
75
		EList props = mr.getProperties();
76
		for(int i = 0; i < props.size(); i++)
77
		{
78
			Property prop = (Property) props.get(i);
79
			if(prop.getName().indexOf("ManageabilityCapability") != -1)
80
			{
81
				EList capList = prop.getValue();
82
				if(capList == null || capList.size() == 0)
83
				{
84
					return null;
85
				}
86
				String caps[] = new String[capList.size()];
87
				for(int j = 0; j < capList.size(); j++)
88
				{
89
					caps[j] = ((String) capList.get(j)).trim();
90
				}
91
				return caps;
92
			}
93
		}
94
		return null;
95
	}
96
	
97
	private static boolean matchResourceName(String name, int match)
98
	{
99
		if(resName == null || name == null)
100
			return false;
101
		if(match == 1 && resName.trim().equals("NO-RN"))
102
			return true;
103
		if(name.equals(resName)) 
104
			return true;
105
		return false;
106
	}
107
	
108
	private static boolean matchCapabilities(String caps[], int match)
109
	{
110
		if(capUris != null && match == 1 && capUris[0].trim().equals("NO-CAP") && capUris.length == 1)
111
			return true;
112
		if(capUris == null || caps == null)
113
			return false;
114
		int capMatch = 0;
115
		if(capUris.length > 1)
116
		{
117
			if(capUris[1].equals("AND"))
118
			{
119
				capMatch = 1;
120
			}
121
		}
122
		if(capMatch == 0)
123
		{
124
			for(int i = 0; i < capUris.length; i++)
125
			{
126
				if(capUris[i].equals("OR"))
127
					continue;
128
				if(inList(caps, capUris[i]))
129
					return true;
130
			}
131
		}
132
		else if(capMatch == 1)
133
		{
134
			for(int i = 0; i < capUris.length; i++)
135
			{
136
				if(capUris[i].equals("AND"))
137
					continue;
138
				if(!inList(caps, capUris[i]))
139
					return false;
140
			}
141
			return true;
142
		}
143
		return false;
144
	}
145
	
146
	private static boolean matchEPR(String eprStr, int match)
147
	{
148
		if(epr == null || eprStr == null)
149
			return false;
150
		if(match == 1 && epr.trim().equals("NO-EPR"))
151
			return true;
152
		
153
		
154
		IConnectionHelper helper = ManagedAgentUIPlugin.getConnectionHelper((String)_conf.get("ManagedAgentType"));
155
		
156
		Map eprMap1 = new Hashtable();
157
		Map eprMap2 = new Hashtable();
158
		eprMap1.put("epr", epr);
159
		eprMap2.put("epr", eprStr);
160
		if( ! helper.isSameResource(eprMap1, eprMap2) ){
161
			return false;
162
		}else{
163
			return true;
164
		}
165
		
166
		/*Map eprFilterMap = getEPRMap(epr);
167
		if(eprFilterMap == null || eprFilterMap.size() == 0)
168
		{
169
			return false;
170
		}
171
		
172
		Map eprStrMap = getEPRMap(eprStr);
173
		String addr1 = ((String) eprFilterMap.get(ADDRESS_KEY)).trim();
174
		String addr2 = ((String) eprStrMap.get(ADDRESS_KEY)).trim();
175
		if(!addr1.equals(addr2))
176
		{
177
			return false;
178
		}
179
		String filterRPs[] = (String[]) eprFilterMap.get(REFPARAMS_KEY);
180
		String resourceRPs[] = (String[]) eprStrMap.get(REFPARAMS_KEY);
181
		if(filterRPs == null || resourceRPs == null)
182
		{
183
			return false;
184
		}
185
		if(filterRPs.length != resourceRPs.length)
186
		{
187
			return false;
188
		}
189
		for(int i = 0; i < filterRPs.length; i++)
190
		{
191
			if(!inList(filterRPs, resourceRPs[i]))
192
			{
193
				return false;
194
			}
195
		}
196
		return true;
197
		*/
198
	}
199
	
200
	public static Filter getFilterFromDialog(FilterDialog dlg)
201
	{
202
		if(dlg == null)
203
		{
204
			return null;
205
		}
206
		String fName = dlg.getTxtName().getText();
207
		if(fName == null || fName.trim().length() == 0)
208
		{
209
			MessageDialog.openError(dlg.getShell(), Messages.getString("MAXFilter.Filter.Error.Title."), Messages.getString("MAXFilter.Filter.Name.Error."));
210
			return null;
211
		}
212
		if(dlg.getCmbExistingFilters().getText() != null && dlg.getCmbExistingFilters().getText().equals("None"))
213
		{
214
			boolean valid = validateFilterName(fName);
215
			if(!valid)
216
			{
217
				MessageDialog.openError(dlg.getShell(), Messages.getString("MAXFilter.Filter.Error.Title."), Messages.getString("MAXFilter.Filter.Name.Duplicate.Error."));
218
				return null;
219
			}
220
		}
221
		boolean valid = validate(dlg);
222
		if(!valid)
223
		{
224
			return null;
225
		}
226
		String resName = dlg.getTxtResName().getText();
227
		if(resName == null || resName.trim().length() == 0)
228
		{
229
			resName = "NO-RN";
230
		}
231
		String capUris[] = dlg.getLstCapUris().getItems();
232
		if(capUris == null || capUris.length == 0)
233
		{
234
			capUris = new String[] {"NO-CAP"};
235
		}
236
		String eprStr = getEPRString(dlg);
237
		if(resName == null && capUris == null && eprStr == null)
238
		{
239
			MessageDialog.openError(dlg.getShell(), Messages.getString("MAXFilter.Filter.Error.Title."), Messages.getString("MAXFilter.Filter.Invalid.Error."));
240
			return null;
241
		}
242
		int overallMatch = dlg.getBtnAnd().getSelection() ? 1 : 0;
243
		int capMatch = dlg.getBtnCapMatchAll().getSelection() ? 1 : 0;
244
		Filter filter = new Filter();
245
		filter.setFilterName(fName);
246
		filter.setResName(resName);
247
		filter.setCapUris(capUris);
248
		filter.setEpr(eprStr);
249
		filter.setOverallMatch(overallMatch);
250
		filter.setCapMatch(capMatch);
251
		return filter;
252
	}
253
254
	private static boolean validateFilterName(String name)
255
	{
256
		List filters = MaxFilterPreference.getFilters();
257
		if(filters == null || filters.size() == 0)
258
		{
259
			return true;
260
		}
261
		for(int i = 0; i < filters.size(); i++)
262
		{
263
			Filter f = (Filter) filters.get(i);
264
			if(f.getFilterName().trim().equals(name.trim()))
265
				return false;
266
		}
267
		return true;
268
	}
269
	
270
	
271
	private static boolean validate(FilterDialog dlg)
272
	{
273
		String addrURL = dlg.getCmbEprUri().getText();
274
		if(addrURL == null || addrURL.trim().length() == 0)
275
		{
276
			return true;
277
		}
278
		TableItem[] tis = dlg.getTblRefParams().getItems();
279
		if(tis != null && tis.length > 0)
280
		{
281
			for(int i = 0; i < tis.length; i++)
282
			{
283
				TableItem ti = tis[i];
284
				String pfx = ti.getText(0);
285
				if(pfx == null || pfx.trim().length() == 0)
286
				{
287
					MessageDialog.openError(dlg.getShell(), Messages.getString("MAXFilter.Filter.Error.Title."), Messages.getString("MAXFilter.Filter.Prefix.Error.") + (i + 1));
288
					return false;
289
				}
290
				String ns = ti.getText(1);
291
				if(ns == null || ns.trim().length() == 0)
292
				{
293
					MessageDialog.openError(dlg.getShell(), Messages.getString("MAXFilter.Filter.Error.Title."), Messages.getString("MAXFilter.Filter.NS.Error.") + (i + 1));
294
					return false;
295
				}
296
				String name = ti.getText(2);
297
				if(name == null || name.trim().length() == 0)
298
				{
299
					MessageDialog.openError(dlg.getShell(), Messages.getString("MAXFilter.Filter.Error.Title."), Messages.getString("MAXFilter.Filter.PropName.Error.") + (i + 1));
300
					return false;
301
				}
302
				String val = ti.getText(3);
303
				if(val == null || val.trim().length() == 0)
304
				{
305
					MessageDialog.openError(dlg.getShell(), Messages.getString("MAXFilter.Filter.Error.Title."), Messages.getString("MAXFilter.Filter.Value.Error.") + (i + 1));
306
					return false;
307
				}
308
			}
309
		}
310
		return true;
311
	}
312
	
313
	private static String getEPRString(FilterDialog dlg) 
314
	{
315
		String addrURL = dlg.getCmbEprUri().getText();
316
		String params[][] = null;
317
		TableItem[] tis = dlg.getTblRefParams().getItems();
318
		if(tis != null && tis.length > 0)
319
		{
320
			params = new String[tis.length][4];
321
			for(int i = 0; i < tis.length; i++)
322
			{
323
				TableItem ti = tis[i];
324
				for(int j = 0; j < 4; j++)
325
				{
326
					params[i][j] = ti.getText(j);
327
				}
328
			}
329
		}
330
		return getEPRString(addrURL, params);
331
	}
332
	
333
	public static String getEPRString(String addrURL, String[][] params)
334
	{
335
		if(addrURL == null || addrURL.trim().length() == 0)
336
		{
337
			return "NO-EPR";
338
		}
339
		String eprStr = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "\n" + "<wsa:EndpointReference xmlns:wsa=\"http://www.w3.org/2005/08/addressing\">" + "\n" + "<wsa:Address>"; 
340
		eprStr += addrURL + "</wsa:Address>\n";
341
		if(params != null && params.length > 0)
342
		{
343
			eprStr += "<wsa:ReferenceParameters>\n";
344
			for(int i = 0; i < params.length; i++)
345
			{
346
				String param[] = params[i];
347
				String pfx = param[0];
348
				if(pfx == null || pfx.trim().length() == 0)
349
				{
350
					pfx = "";
351
				}
352
				String ns = param[1];
353
				if(ns == null)
354
				{
355
					ns = "";
356
				}
357
				String name = param[2];
358
				if(name == null)
359
				{
360
					name = "";
361
				}
362
				String val = param[3];
363
				if(val == null)
364
				{
365
					val = "";
366
				}
367
				eprStr += "<" + pfx + ":" + name + " xmlns:" + pfx + "=\"" + ns + "\">" + val + "</" + pfx + ":" + name + ">\n";
368
			}
369
			eprStr += "</wsa:ReferenceParameters>\n";
370
		}
371
		eprStr += "</wsa:EndpointReference>";
372
		return eprStr;
373
	}
374
	
375
	public static Filter getFilter()
376
	{
377
		return filter;
378
	}
379
	
380
	public static void setFilter(Filter f)
381
	{
382
		filter = f;
383
		if(filter == null)
384
		{
385
			return;
386
		}
387
		filt = filter.getFilter();
388
		resName = (String) filt[0];
389
		capUris = (String[]) filt[2];
390
		epr = (String) filt[4];
391
	}
392
	
393
	public static Map getEPRMap(String orgEprStr)
394
	{
395
		String eprStr = orgEprStr.replace('\n', ' ');
396
		if(eprStr == null || eprStr.trim().length() == 0)
397
			return null;
398
		int addrIdx = eprStr.indexOf(":Address");
399
		if(addrIdx == -1)
400
			return null;
401
		int endOfAddressElementIdx = eprStr.indexOf('>', addrIdx+1);
402
		int startOfClosingTagIdx = eprStr.indexOf('<', endOfAddressElementIdx);
403
		Map map = new HashMap();
404
		String address = eprStr.substring(endOfAddressElementIdx+1, startOfClosingTagIdx);
405
		map.put(ADDRESS_KEY, address.trim());
406
		int refParamIdx = eprStr.indexOf("<wsa:ReferenceParameters>");
407
		if(refParamIdx != -1)
408
		{
409
			String rps = eprStr.substring(refParamIdx + "<wsa:ReferenceParameters>".length(), eprStr.indexOf("</wsa:ReferenceParameters>"));
410
			String params[] = rps.split("\n");
411
			ArrayList prm = new ArrayList();
412
			for(int i = 0; i < params.length; i++)
413
			{
414
				if(params[i] == null || params[i].trim().length() == 0)
415
					continue;
416
				prm.add(params[i].trim());
417
			}
418
			params = new String[prm.size()];
419
			for(int i = 0; i < params.length; i++)
420
			{
421
				params[i] = (String) prm.get(i);
422
			}
423
			map.put(REFPARAMS_KEY, params);
424
		}
425
		return map;
426
	}
427
	
428
	private static boolean inList(String[] vals, String val)
429
	{
430
		if(val == null || vals == null)
431
		{
432
			return false;
433
		}
434
		for(int i = 0; i < vals.length; i++)
435
		{
436
			if(vals[i] == null)
437
				continue;
438
			if(vals[i].trim().equals(val.trim()))
439
			{
440
				return true;
441
			}
442
		}
443
		return false;
444
	}
445
	
446
	public static String[] getParamPrefString(String param)
447
	{
448
		if(param == null || param.trim().length() == 0)
449
		{
450
			return new String[] {"", "", "", ""};
451
		}
452
		param = param.trim();
453
		String pfx = param.substring(1, param.indexOf(':'));
454
		String ns = param.substring(param.indexOf('=') + 2, param.indexOf('>') - 1);
455
		String name = param.substring(param.indexOf(":") + 1, param.indexOf(' '));
456
		String val = param.substring(param.indexOf('>') + 1, param.indexOf("</"));
457
		return new String[] {pfx, ns, name, val};
458
	}
459
}
(-)icons/obj16/sort.gif (+3 lines)
Added Link Here
1
GIF89ağ_Ÿ????Ÿ??_?_¿?¿?Ÿ¿ŸŸŸ¿¿¿ŸŸß¿¿¿¿¿ŸŸŸÿÿÿ!ù,_ $ŽÊq(Ë8>Ä#ž¬JOàª2ӌ»$¹Üîq•1݌h<HÂeñ‰0)
2
ÊÕt7ܪà0Í;4$Ž`|S?ÓëˆAÙÁE?ˆ2»KÎy|3"
3
\#ab‰\!;
(-)icons/obj16/unsort.gif (+2 lines)
Added Link Here
1
GIF89a÷Ÿ_Ÿ????Ÿ??_?_¿?¿?Ÿ¿ŸŸŸ¿¿¿ŸŸß¿¿¿¿¿ŸŸŸÿÿÿ,?%¨àÀ$Dˆ0ð?J?¸°aˆ'"PÈPà$8€€dņ T0ñ$J•$,pùRfɅ6f|?2#͚+JTOŒ'4?à`£=].mú4‚«?©
2
„°°kF­–rý	`€À‚vÌH´èό;
(-)src/org/eclipse/tptp/monitoring/managedagent/ui/explorer/internal/filter/Messages.java (+33 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 * 	Balan Subramanian (bsubram@us.ibm.com)
10
 *     IBM Corporation - initial API and implementation
11
 *******************************************************************************/
12
package org.eclipse.tptp.monitoring.managedagent.ui.explorer.internal.filter;
13
14
import java.util.MissingResourceException;
15
import java.util.ResourceBundle;
16
17
public class Messages {
18
	private static final String BUNDLE_NAME = "org.eclipse.tptp.monitoring.managedagent.ui.explorer.internal.filter.messages"; //$NON-NLS-1$
19
20
	private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle
21
			.getBundle(BUNDLE_NAME);
22
23
	private Messages() {
24
	}
25
26
	public static String getString(String key) {
27
		try {
28
			return RESOURCE_BUNDLE.getString(key);
29
		} catch (MissingResourceException e) {
30
			return '!' + key + '!';
31
		}
32
	}
33
}

Return to bug 165565