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