01: /*******************************************************************************
02: * Copyright (c) 2000, 2006 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.pde.internal.runtime.logview;
11:
12: import java.util.Comparator;
13:
14: import org.eclipse.core.runtime.Assert;
15: import org.eclipse.core.runtime.IAdaptable;
16: import org.eclipse.jface.viewers.ISelectionProvider;
17: import org.eclipse.pde.internal.runtime.PDERuntimeMessages;
18: import org.eclipse.swt.widgets.Shell;
19: import org.eclipse.ui.actions.SelectionProviderAction;
20:
21: public class EventDetailsDialogAction extends SelectionProviderAction {
22:
23: /**
24: * The shell in which to open the property dialog
25: */
26: private Shell shell;
27: private ISelectionProvider provider;
28: private EventDetailsDialog propertyDialog;
29: private Comparator comparator;
30:
31: /**
32: * Creates a new action for opening a property dialog
33: * on the elements from the given selection provider
34: * @param shell - the shell in which the dialog will open
35: * @param provider - the selection provider whose elements
36: * the property dialog will describe
37: */
38: public EventDetailsDialogAction(Shell shell,
39: ISelectionProvider provider) {
40: super (provider, PDERuntimeMessages.EventDetailsDialog_title);
41: Assert.isNotNull(shell);
42: this .shell = shell;
43: this .provider = provider;
44: // setToolTipText
45: //WorkbenchHelp.setHelp
46: }
47:
48: public boolean resetSelection(byte sortType, int sortOrder) {
49: IAdaptable element = (IAdaptable) getStructuredSelection()
50: .getFirstElement();
51: if (element == null)
52: return false;
53: if (propertyDialog != null && propertyDialog.isOpen()) {
54: propertyDialog.resetSelection(element, sortType, sortOrder);
55: return true;
56: }
57: return false;
58: }
59:
60: public void resetSelection() {
61: IAdaptable element = (IAdaptable) getStructuredSelection()
62: .getFirstElement();
63: if (element == null)
64: return;
65: if (propertyDialog != null && propertyDialog.isOpen())
66: propertyDialog.resetSelection(element);
67: }
68:
69: public void resetDialogButtons() {
70: if (propertyDialog != null && propertyDialog.isOpen())
71: propertyDialog.resetButtons();
72: }
73:
74: public void setComparator(Comparator comparator) {
75: this .comparator = comparator;
76: if (propertyDialog != null && propertyDialog.isOpen())
77: propertyDialog.setComparator(comparator);
78: }
79:
80: public void run() {
81: if (propertyDialog != null && propertyDialog.isOpen()) {
82: resetSelection();
83: return;
84: }
85:
86: //get initial selection
87: IAdaptable element = (IAdaptable) getStructuredSelection()
88: .getFirstElement();
89: if (element == null)
90: return;
91:
92: propertyDialog = new EventDetailsDialog(shell, element,
93: provider, comparator);
94: propertyDialog.create();
95: propertyDialog.getShell().setText(
96: PDERuntimeMessages.EventDetailsDialog_title);
97: propertyDialog.open();
98: }
99: }
|