Initial implementation of the new Debug Plugin
[phpeclipse.git] / net.sourceforge.phpeclipse.xdebug.ui / src / net / sourceforge / phpeclipse / xdebug / ui / views / 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.phpeclipse.xdebug.ui.views.logview;
12
13 import java.util.Comparator;
14
15
16 import net.sourceforge.phpeclipse.xdebug.ui.XDebugUIPlugin;
17
18 import org.eclipse.core.runtime.IAdaptable;
19 import org.eclipse.jface.util.Assert;
20 import org.eclipse.jface.viewers.ISelectionProvider;
21 import org.eclipse.swt.widgets.Shell;
22 import org.eclipse.ui.actions.SelectionProviderAction;
23
24
25
26 public class EventDetailsDialogAction extends SelectionProviderAction{
27
28         /**
29          * The shell in which to open the property dialog
30          */
31         private Shell shell;
32         private ISelectionProvider provider;
33         private EventDetailsDialog propertyDialog;
34         private Comparator comparator;
35         /**
36          * Creates a new action for opening a property dialog
37          * on the elements from the given selection provider
38          * @param shell - the shell in which the dialog will open
39          * @param provider - the selection provider whose elements
40          * the property dialog will describe
41          */
42         public EventDetailsDialogAction(Shell shell, ISelectionProvider provider){
43        super(provider, "Test Text"); 
44                 Assert.isNotNull(shell);
45                 this.shell = shell;
46                 this.provider = provider;
47                 // setToolTipText
48                 //WorkbenchHelp.setHelp
49         }
50         
51         public boolean resetSelection(byte sortType, int sortOrder){
52                 IAdaptable element = (IAdaptable) getStructuredSelection().getFirstElement();
53                 if (element == null)
54                         return false;
55                 if (propertyDialog != null && propertyDialog.isOpen()){
56                         propertyDialog.resetSelection(element, sortType, sortOrder);
57                         return true;
58                 }
59                 return false;
60         }
61         public void resetSelection(){
62                 IAdaptable element = (IAdaptable) getStructuredSelection().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         }
77         public void run(){
78                 if (propertyDialog != null && propertyDialog.isOpen()){
79                         resetSelection();
80                         return;
81                 }
82                 
83                 //get initial selection
84                 IAdaptable element = (IAdaptable) getStructuredSelection().getFirstElement();
85                 if (element == null)
86                         return;
87                 
88                 propertyDialog = new EventDetailsDialog(shell, element, provider);
89                 propertyDialog.create();
90                 propertyDialog.getShell().setText(XDebugUIPlugin.getString("EventDetailsDialog.title")); //$NON-NLS-1$
91                 propertyDialog.setComparator(comparator);
92                 propertyDialog.open();
93         }
94 }