]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.message.ui/src/org/simantics/message/ui/EventDetailsDialogAction.java
Fixed multiple issues causing dangling references to discarded queries
[simantics/platform.git] / bundles / org.simantics.message.ui / src / org / simantics / message / ui / EventDetailsDialogAction.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in Industry THTH ry.
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.message.ui;
13
14 import java.util.Comparator;
15 import org.eclipse.core.runtime.Assert;
16 import org.eclipse.core.runtime.IAdaptable;
17 import org.eclipse.jface.viewers.ISelectionProvider;
18 import org.eclipse.swt.widgets.Shell;
19 import org.eclipse.ui.IMemento;
20 import org.eclipse.ui.actions.SelectionProviderAction;
21
22 /**
23  * Opens EventDetailsDialog
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<Object> comparator;
34         private IMemento memento;
35
36         /**
37          * Creates a new action for opening a property dialog
38          * on the elements from the given selection provider
39          * @param shell - the shell in which the dialog will open
40          * @param provider - the selection provider whose elements
41          * @param memento - memento with EventDetails dialog options
42          * the property dialog will describe
43          */
44         public EventDetailsDialogAction(Shell shell, ISelectionProvider provider, IMemento memento) {
45                 super(provider, Messages.EventDetailsDialog_title);
46                 Assert.isNotNull(shell);
47                 this.shell = shell;
48                 this.provider = provider;
49                 this.memento = memento;
50                 // setToolTipText
51                 //WorkbenchHelp.setHelp
52         }
53
54         public boolean resetSelection(byte sortType, int sortOrder) {
55                 IAdaptable element = (IAdaptable) getStructuredSelection().getFirstElement();
56                 if (element == null)
57                         return false;
58                 if (propertyDialog != null && propertyDialog.isOpen()) {
59                         propertyDialog.resetSelection(element, sortType, sortOrder);
60                         return true;
61                 }
62                 return false;
63         }
64
65         public void resetSelection() {
66                 IAdaptable element = (IAdaptable) getStructuredSelection().getFirstElement();
67                 if ((element == null) || (!(element instanceof LogEntry)))
68                         return;
69                 if (propertyDialog != null && propertyDialog.isOpen())
70                         propertyDialog.resetSelection(element);
71         }
72
73         public void resetDialogButtons() {
74                 if (propertyDialog != null && propertyDialog.isOpen())
75                         propertyDialog.resetButtons();
76         }
77
78         public void setComparator(Comparator<Object> comparator) {
79                 this.comparator = comparator;
80                 if (propertyDialog != null && propertyDialog.isOpen())
81                         propertyDialog.setComparator(comparator);
82         }
83
84         public void run() {
85                 if (propertyDialog != null && propertyDialog.isOpen()) {
86                         resetSelection();
87                         return;
88                 }
89
90                 //get initial selection
91                 IAdaptable element = (IAdaptable) getStructuredSelection().getFirstElement();
92                 if ((element == null) || (!(element instanceof LogEntry)))
93                         return;
94
95                 propertyDialog = new EventDetailsDialog(shell, element, provider, comparator, memento);
96                 propertyDialog.create();
97                 propertyDialog.getShell().setText(Messages.EventDetailsDialog_title);
98                 propertyDialog.open();
99         }
100 }