Added
Link Here
|
1 |
/******************************************************************************* |
2 |
* Copyright (c) 2000, 2008 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 |
* Initial Contributors: |
9 |
* The following IBM employees contributed to the Remote System Explorer |
10 |
* component that contains this file: David McKnight, Kushal Munir, |
11 |
* Michael Berger, David Dykstal, Phil Coulthard, Don Yantzi, Eric Simpson, |
12 |
* Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley. |
13 |
* |
14 |
* Contributors: |
15 |
* Kevin Doyle (IBM) - [187553] - Removed code and related methods for toolbar/button bar. |
16 |
* Martin Oberhuber (Wind River) - [190271] Move ISystemViewInputProvider to Core |
17 |
* David McKnight (IBM) - [187711] select SystemView APIs exposed by the ISystemTree interface |
18 |
*******************************************************************************/ |
19 |
package org.eclipse.rse.ui.view; |
20 |
import java.util.List; |
21 |
import java.util.Vector; |
22 |
|
23 |
import org.eclipse.jface.action.ToolBarManager; |
24 |
import org.eclipse.jface.viewers.IDoubleClickListener; |
25 |
import org.eclipse.jface.viewers.ISelection; |
26 |
import org.eclipse.jface.viewers.ISelectionChangedListener; |
27 |
import org.eclipse.jface.viewers.ViewerFilter; |
28 |
import org.eclipse.jface.wizard.WizardPage; |
29 |
import org.eclipse.rse.core.filters.ISystemFilter; |
30 |
import org.eclipse.rse.core.filters.ISystemFilterReference; |
31 |
import org.eclipse.rse.core.model.ISystemViewInputProvider; |
32 |
import org.eclipse.rse.core.subsystems.ISubSystem; |
33 |
import org.eclipse.rse.internal.ui.view.SystemEmptyListAPIProviderImpl; |
34 |
import org.eclipse.rse.internal.ui.view.SystemView; |
35 |
import org.eclipse.rse.ui.dialogs.SystemPromptDialog; |
36 |
import org.eclipse.rse.ui.messages.ISystemMessageLine; |
37 |
import org.eclipse.swt.SWT; |
38 |
import org.eclipse.swt.events.MouseAdapter; |
39 |
import org.eclipse.swt.events.MouseEvent; |
40 |
import org.eclipse.swt.events.MouseListener; |
41 |
import org.eclipse.swt.layout.GridData; |
42 |
import org.eclipse.swt.layout.GridLayout; |
43 |
import org.eclipse.swt.widgets.Button; |
44 |
import org.eclipse.swt.widgets.Composite; |
45 |
import org.eclipse.swt.widgets.Item; |
46 |
import org.eclipse.swt.widgets.Shell; |
47 |
import org.eclipse.swt.widgets.ToolBar; |
48 |
import org.eclipse.swt.widgets.Tree; |
49 |
import org.eclipse.swt.widgets.TreeItem; |
50 |
|
51 |
|
52 |
/** |
53 |
* This re-usable widget is for a single widget that displays a |
54 |
* toolbar underneath which is a systems view tree. |
55 |
*/ |
56 |
public class SystemViewForm extends Composite implements ISystemTree |
57 |
{ |
58 |
private ToolBar toolbar = null; |
59 |
private ToolBarManager toolbarMgr = null; |
60 |
private Button refreshButton, getListButton; |
61 |
private SystemView tree = null; |
62 |
private ISystemMessageLine msgLine = null; |
63 |
private boolean showActions = true; |
64 |
private boolean deferLoading = false; |
65 |
private boolean requestInProgress = false; |
66 |
private ISystemViewInputProvider inputProvider = null; |
67 |
private ISystemViewInputProvider emptyProvider = new SystemEmptyListAPIProviderImpl(); |
68 |
private Vector requestListeners = null; |
69 |
public static final int DEFAULT_WIDTH = 300; |
70 |
public static final int DEFAULT_HEIGHT = 300; |
71 |
|
72 |
// the following allows us to identify dialog/wizard hosting this widget so we can |
73 |
// disable it's close capability while a remote request is in place. |
74 |
protected Object caller; |
75 |
protected boolean callerInstanceOfWizardPage, callerInstanceOfSystemPromptDialog; |
76 |
|
77 |
// viewer filters |
78 |
protected ViewerFilter[] initViewerFilters = null; |
79 |
|
80 |
/** |
81 |
* Constructor |
82 |
* @param shell The owning window |
83 |
* @param parent The owning composite |
84 |
* @param style The swt style to apply to the overall composite. Typically SWT.NULL |
85 |
* @param inputProvider Who is supplying the roots for the system viewer? |
86 |
* @param singleSelectionMode Are users allowed to select multiple things at once? |
87 |
* @param msgLine where to show messages and tooltip text |
88 |
*/ |
89 |
public SystemViewForm(Shell shell, Composite parent, int style, ISystemViewInputProvider inputProvider, |
90 |
boolean singleSelectionMode, ISystemMessageLine msgLine) |
91 |
{ |
92 |
this(shell, parent, style, inputProvider, singleSelectionMode, msgLine, 1, 1); |
93 |
} |
94 |
/** |
95 |
* Constructor when you want to span more than one column or row |
96 |
* @param shell The owning window |
97 |
* @param parent The owning composite |
98 |
* @param style The swt style to apply to the overall composite. Typically SWT.NULL |
99 |
* @param inputProvider Who is supplying the roots for the system viewer? |
100 |
* @param singleSelectionMode Are users allowed to select multiple things at once? |
101 |
* @param msgLine where to show messages and tooltip text |
102 |
* @param horizontalSpan how many columns in parent composite to span |
103 |
* @param verticalSpan how many rows in parent composite to span |
104 |
*/ |
105 |
public SystemViewForm(Shell shell, Composite parent, int style, ISystemViewInputProvider inputProvider, |
106 |
boolean singleSelectionMode, ISystemMessageLine msgLine, |
107 |
int horizontalSpan, int verticalSpan) |
108 |
{ |
109 |
this(shell, parent, style, inputProvider, singleSelectionMode, msgLine, horizontalSpan, verticalSpan, null); |
110 |
} |
111 |
|
112 |
/** |
113 |
* Constructor when you want to span more than one column or row |
114 |
* @param shell The owning window |
115 |
* @param parent The owning composite |
116 |
* @param style The swt style to apply to the overall composite. Typically SWT.NULL |
117 |
* @param inputProvider Who is supplying the roots for the system viewer? |
118 |
* @param singleSelectionMode Are users allowed to select multiple things at once? |
119 |
* @param msgLine where to show messages and tooltip text |
120 |
* @param horizontalSpan how many columns in parent composite to span |
121 |
* @param verticalSpan how many rows in parent composite to span |
122 |
* @param initViewerFilters the initial viewer filters to apply. |
123 |
*/ |
124 |
public SystemViewForm(Shell shell, Composite parent, int style, ISystemViewInputProvider inputProvider, |
125 |
boolean singleSelectionMode, ISystemMessageLine msgLine, |
126 |
int horizontalSpan, int verticalSpan, ViewerFilter[] initViewerFilters) |
127 |
{ |
128 |
super(parent, style); |
129 |
this.inputProvider = inputProvider; |
130 |
this.msgLine = msgLine; |
131 |
callerInstanceOfWizardPage = (caller instanceof WizardPage); |
132 |
callerInstanceOfSystemPromptDialog = (caller instanceof SystemPromptDialog); |
133 |
prepareComposite(1, horizontalSpan, verticalSpan); |
134 |
|
135 |
// set viewer filters |
136 |
this.initViewerFilters = initViewerFilters; |
137 |
|
138 |
createSystemView(shell, inputProvider, singleSelectionMode); |
139 |
|
140 |
} |
141 |
|
142 |
/** |
143 |
* Return the toolbar widget manager |
144 |
*/ |
145 |
public ToolBarManager getToolBarManager() |
146 |
{ |
147 |
return toolbarMgr; |
148 |
} |
149 |
/** |
150 |
* Return the system view tree viewer |
151 |
*/ |
152 |
public ISystemTree getSystemTree() |
153 |
{ |
154 |
return tree; |
155 |
} |
156 |
/** |
157 |
* Return the system view tree viewer tree widget |
158 |
*/ |
159 |
public Tree getTreeControl() |
160 |
{ |
161 |
return tree.getTree(); |
162 |
} |
163 |
|
164 |
/** |
165 |
* Set the tree's tooltip text |
166 |
*/ |
167 |
public void setToolTipText(String tip) |
168 |
{ |
169 |
tree.getTree().setToolTipText(tip); |
170 |
} |
171 |
|
172 |
/** |
173 |
* Refresh contents |
174 |
*/ |
175 |
public void refresh() |
176 |
{ |
177 |
tree.refreshAll(); |
178 |
} |
179 |
|
180 |
/** |
181 |
* Reset contents |
182 |
*/ |
183 |
public void reset(ISystemViewInputProvider inputProvider) |
184 |
{ |
185 |
this.inputProvider = inputProvider; |
186 |
if (deferLoading) |
187 |
{ |
188 |
tree.setSelection(null); |
189 |
tree.setInputProvider(emptyProvider); |
190 |
} |
191 |
else |
192 |
{ |
193 |
tree.setSelection(null); |
194 |
tree.setInputProvider(inputProvider); |
195 |
} |
196 |
} |
197 |
|
198 |
/* |
199 |
* Turn off right-click actions |
200 |
* |
201 |
NOW SET VIA INPUT PROVIDER METHODS |
202 |
public void setShowActions(boolean show) |
203 |
{ |
204 |
this.showActions = show; |
205 |
if (tree != null) |
206 |
tree.setShowActions(show); |
207 |
}*/ |
208 |
|
209 |
/** |
210 |
* Disable/Enable all the child controls. |
211 |
*/ |
212 |
public void setEnabled(boolean enabled) |
213 |
{ |
214 |
if (toolbar != null) |
215 |
toolbar.setEnabled(enabled); |
216 |
tree.setEnabled(enabled); |
217 |
//if ((tree != null) && (tree.getTree() != null)) |
218 |
// tree.getTree().setEnabled(enabled); |
219 |
//super.setEnabled(enabled); |
220 |
} |
221 |
/** |
222 |
* Register a listener interested in an item is selected in the system view |
223 |
* @see #removeSelectionChangedListener(ISelectionChangedListener) |
224 |
*/ |
225 |
public void addSelectionChangedListener(ISelectionChangedListener listener) |
226 |
{ |
227 |
tree.addSelectionChangedListener(listener); |
228 |
} |
229 |
/** |
230 |
* Remove a previously set system view selection listener. |
231 |
* @see #addSelectionChangedListener(ISelectionChangedListener) |
232 |
*/ |
233 |
public void removeSelectionChangedListener(ISelectionChangedListener listener) |
234 |
{ |
235 |
tree.removeSelectionChangedListener(listener); |
236 |
} |
237 |
/** |
238 |
* Add a listener that is informed when a remote list request starts and stops. |
239 |
* This allows for the listener to do things like disable the Close button |
240 |
*/ |
241 |
public void addListRequestListener(ISystemLongRunningRequestListener listener) |
242 |
{ |
243 |
if (requestListeners == null) |
244 |
requestListeners = new Vector(); |
245 |
requestListeners.addElement(listener); |
246 |
} |
247 |
/** |
248 |
* Add a listener that is informed when a remote list request starts and stops. |
249 |
* This allows for the listener to do things like disable the Close button |
250 |
*/ |
251 |
public void removeListRequestListener(ISystemLongRunningRequestListener listener) |
252 |
{ |
253 |
if (requestListeners != null) |
254 |
requestListeners.removeElement(listener); |
255 |
} |
256 |
|
257 |
/** |
258 |
* Return the selection of the tree viewer |
259 |
*/ |
260 |
public ISelection getSelection() |
261 |
{ |
262 |
return tree.getSelection(); |
263 |
} |
264 |
|
265 |
|
266 |
// -------------------------------------------- |
267 |
// ISystemTree methods to facilitate our GUI... |
268 |
// ... all these are delegated to the SystemView tree |
269 |
// -------------------------------------------- |
270 |
/** |
271 |
* Returns true if any of the selected items are currently expanded |
272 |
*/ |
273 |
public boolean areAnySelectedItemsExpanded() |
274 |
{ |
275 |
return tree.areAnySelectedItemsExpanded(); |
276 |
} |
277 |
/** |
278 |
* Returns true if any of the selected items are expandable but not yet expanded |
279 |
*/ |
280 |
public boolean areAnySelectedItemsExpandable() |
281 |
{ |
282 |
return tree.areAnySelectedItemsExpandable(); |
283 |
} |
284 |
/** |
285 |
* This is called to ensure all elements in a multiple-selection have the same parent in the |
286 |
* tree viewer. If they don't we automatically disable all actions. |
287 |
* <p> |
288 |
* Designed to be as fast as possible by going directly to the SWT widgets |
289 |
*/ |
290 |
public boolean sameParent() |
291 |
{ |
292 |
return tree.sameParent(); |
293 |
} |
294 |
/** |
295 |
* This is called to accurately get the parent object for the current selection |
296 |
* for this viewer. |
297 |
* <p> |
298 |
* The getParent() method in the adapter is very unreliable... adapters can't be sure |
299 |
* of the context which can change via filtering and view options. |
300 |
*/ |
301 |
public Object getSelectedParent() |
302 |
{ |
303 |
return tree.getSelectedParent(); |
304 |
} |
305 |
/** |
306 |
* This returns the element immediately before the first selected element in this tree level. |
307 |
* Often needed for enablement decisions for move up actions. |
308 |
*/ |
309 |
public Object getPreviousElement() |
310 |
{ |
311 |
return tree.getPreviousElement(); |
312 |
} |
313 |
/** |
314 |
* This returns the element immediately after the last selected element in this tree level |
315 |
* Often needed for enablement decisions for move down actions. |
316 |
*/ |
317 |
public Object getNextElement() |
318 |
{ |
319 |
return tree.getNextElement(); |
320 |
} |
321 |
|
322 |
/** |
323 |
* This is called to walk the tree back up to the roots and return the visible root |
324 |
* node for the first selected object. |
325 |
*/ |
326 |
public Object getRootParent() |
327 |
{ |
328 |
return tree.getRootParent(); |
329 |
} |
330 |
/** |
331 |
* This returns an array containing each element in the tree, up to but not including the root. |
332 |
* The array is in reverse order, starting at the leaf and going up. |
333 |
*/ |
334 |
public Object[] getElementNodes(Object element) |
335 |
{ |
336 |
return tree.getElementNodes(element); |
337 |
} |
338 |
/** |
339 |
* Helper method to determine if a given object is currently selected. |
340 |
* Does consider if a child node of the given object is currently selected. |
341 |
*/ |
342 |
public boolean isSelectedOrChildSelected(Object parentElement) |
343 |
{ |
344 |
return tree.isSelectedOrChildSelected(parentElement); |
345 |
} |
346 |
|
347 |
/** |
348 |
* Return the number of immediate children in the tree, for the given tree node |
349 |
*/ |
350 |
public int getChildCount(Object element) |
351 |
{ |
352 |
return tree.getChildCount(element); |
353 |
} |
354 |
|
355 |
/** |
356 |
* Called when a property is updated and we need to inform the Property Sheet viewer. |
357 |
* There is no formal mechanism for this so we simulate a selection changed event as |
358 |
* this is the only event the property sheet listens for. |
359 |
*/ |
360 |
public void updatePropertySheet() |
361 |
{ |
362 |
tree.updatePropertySheet(); |
363 |
} |
364 |
|
365 |
/** |
366 |
* Called to select an object within the tree, and optionally expand it |
367 |
*/ |
368 |
public void select(Object element, boolean expand) |
369 |
{ |
370 |
tree.select(element, expand); |
371 |
} |
372 |
|
373 |
/** |
374 |
* Returns the tree item of the first selected object. Used for setViewerItem in a resource |
375 |
* change event. |
376 |
*/ |
377 |
public Item getViewerItem() |
378 |
{ |
379 |
return tree.getViewerItem(); |
380 |
} |
381 |
|
382 |
/** |
383 |
* Returns true if it is ok to close the dialog or wizard page. Returns false if there |
384 |
* is a remote request currently in progress. |
385 |
*/ |
386 |
public boolean okToClose() |
387 |
{ |
388 |
return !requestInProgress; //d43433 |
389 |
} |
390 |
|
391 |
// ----------------------- |
392 |
// INTERNAL-USE METHODS... |
393 |
// ----------------------- |
394 |
/** |
395 |
* Prepares this composite control and sets the default layout data. |
396 |
* @param Number of columns the new group will contain. |
397 |
*/ |
398 |
protected Composite prepareComposite(int numColumns, |
399 |
int horizontalSpan, int verticalSpan) |
400 |
{ |
401 |
Composite composite = this; |
402 |
//GridLayout |
403 |
GridLayout layout = new GridLayout(); |
404 |
layout.numColumns = numColumns; |
405 |
layout.marginWidth = 0; |
406 |
layout.marginHeight = 0; |
407 |
layout.horizontalSpacing = 0; |
408 |
layout.verticalSpacing = 0; |
409 |
composite.setLayout(layout); |
410 |
//GridData |
411 |
GridData data = new GridData(); |
412 |
data.verticalAlignment = GridData.FILL; |
413 |
data.horizontalAlignment = GridData.FILL; |
414 |
data.grabExcessHorizontalSpace = true; |
415 |
data.grabExcessVerticalSpace = true; |
416 |
data.widthHint = DEFAULT_WIDTH; |
417 |
data.heightHint = DEFAULT_HEIGHT; |
418 |
data.horizontalSpan = horizontalSpan; |
419 |
data.verticalSpan = verticalSpan; |
420 |
composite.setLayoutData(data); |
421 |
return composite; |
422 |
} |
423 |
|
424 |
protected void createSystemView(Shell shell, ISystemViewInputProvider inputProvider, boolean singleSelectionMode) |
425 |
{ |
426 |
// TREE |
427 |
int style = (singleSelectionMode ? SWT.SINGLE : SWT.MULTI) | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER; |
428 |
tree = new SystemView(shell, this, style, deferLoading ? emptyProvider : inputProvider, msgLine, initViewerFilters); |
429 |
GridData treeData = new GridData(); |
430 |
treeData.horizontalAlignment = GridData.FILL; |
431 |
treeData.verticalAlignment = GridData.FILL; |
432 |
treeData.grabExcessHorizontalSpace = true; |
433 |
treeData.grabExcessVerticalSpace = true; |
434 |
treeData.widthHint = 300; |
435 |
treeData.heightHint= 200; |
436 |
tree.getTree().setLayoutData(treeData); |
437 |
tree.setShowActions(showActions); |
438 |
} |
439 |
|
440 |
protected void addOurMouseListener() |
441 |
{ |
442 |
MouseListener mouseListener = new MouseAdapter() |
443 |
{ |
444 |
public void mouseDown(MouseEvent e) |
445 |
{ |
446 |
//requestActivation(); |
447 |
} |
448 |
}; |
449 |
toolbar.addMouseListener(mouseListener); |
450 |
} |
451 |
|
452 |
/** |
453 |
* Fire long running request listener event |
454 |
*/ |
455 |
protected void fireRequestStartEvent() |
456 |
{ |
457 |
if (requestListeners != null) |
458 |
{ |
459 |
SystemLongRunningRequestEvent event = new SystemLongRunningRequestEvent(); |
460 |
for (int idx=0; idx<requestListeners.size(); idx++) |
461 |
((ISystemLongRunningRequestListener)requestListeners.elementAt(idx)).startingLongRunningRequest(event); |
462 |
} |
463 |
} |
464 |
|
465 |
/** |
466 |
* Fire long running request listener event |
467 |
*/ |
468 |
protected void fireRequestStopEvent() |
469 |
{ |
470 |
if (requestListeners != null) |
471 |
{ |
472 |
SystemLongRunningRequestEvent event = new SystemLongRunningRequestEvent(); |
473 |
for (int idx=0; idx<requestListeners.size(); idx++) |
474 |
((ISystemLongRunningRequestListener)requestListeners.elementAt(idx)).endingLongRunningRequest(event); |
475 |
} |
476 |
} |
477 |
|
478 |
|
479 |
|
480 |
/** |
481 |
* wrapper method to satisfy the ISystemTree interface |
482 |
*/ |
483 |
public void createTreeItems(TreeItem widget, Object[] children) |
484 |
{ |
485 |
tree.createTreeItems(widget, children); |
486 |
} |
487 |
|
488 |
/** |
489 |
* wrapper method to satisfy the ISystemTree interface |
490 |
*/ |
491 |
public List findAllRemoteItemReferences(Object element, |
492 |
Object elementObject, List matches) { |
493 |
return tree.findAllRemoteItemReferences(element, elementObject, matches); |
494 |
} |
495 |
|
496 |
/** |
497 |
* wrapper method to satisfy the ISystemTree interface |
498 |
*/ |
499 |
public Item findFirstRemoteItemReference(Object remoteObject, |
500 |
Item parentItem) { |
501 |
return tree.findFirstRemoteItemReference(remoteObject, parentItem); |
502 |
} |
503 |
|
504 |
/** |
505 |
* wrapper method to satisfy the ISystemTree interface |
506 |
*/ |
507 |
public Tree getTree() { |
508 |
return tree.getTree(); |
509 |
} |
510 |
|
511 |
/** |
512 |
* wrapper method to satisfy the ISystemTree interface |
513 |
*/ |
514 |
public ISystemFilterReference revealAndExpand(ISubSystem parentSubSystem, |
515 |
ISystemFilter filter) { |
516 |
return tree.revealAndExpand(parentSubSystem, filter); |
517 |
} |
518 |
public void addDoubleClickListener(IDoubleClickListener listener) { |
519 |
tree.addDoubleClickListener(listener); |
520 |
} |
521 |
public void addFilter(ViewerFilter filter) { |
522 |
tree.addFilter(filter); |
523 |
|
524 |
} |
525 |
public void expandTo(Object parentObject, Object remoteObject) { |
526 |
tree.expandTo(parentObject, remoteObject); |
527 |
|
528 |
} |
529 |
public void expandTo(String filterString) { |
530 |
tree.expandTo(filterString); |
531 |
|
532 |
} |
533 |
public boolean isExpandable(Object elementOrTreePath) { |
534 |
return tree.isExpandable(elementOrTreePath); |
535 |
} |
536 |
public void setAutoExpandLevel(int level) { |
537 |
tree.setAutoExpandLevel(level); |
538 |
} |
539 |
|
540 |
} |