1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
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
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.message.ui;
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;
23 * Opens EventDetailsDialog
25 public class EventDetailsDialogAction extends SelectionProviderAction {
28 * The shell in which to open the property dialog
31 private ISelectionProvider provider;
32 private EventDetailsDialog propertyDialog;
33 private Comparator<Object> comparator;
34 private IMemento memento;
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
44 public EventDetailsDialogAction(Shell shell, ISelectionProvider provider, IMemento memento) {
45 super(provider, Messages.EventDetailsDialog_title);
46 Assert.isNotNull(shell);
48 this.provider = provider;
49 this.memento = memento;
51 //WorkbenchHelp.setHelp
54 public boolean resetSelection(byte sortType, int sortOrder) {
55 IAdaptable element = (IAdaptable) getStructuredSelection().getFirstElement();
58 if (propertyDialog != null && propertyDialog.isOpen()) {
59 propertyDialog.resetSelection(element, sortType, sortOrder);
65 public void resetSelection() {
66 IAdaptable element = (IAdaptable) getStructuredSelection().getFirstElement();
67 if ((element == null) || (!(element instanceof LogEntry)))
69 if (propertyDialog != null && propertyDialog.isOpen())
70 propertyDialog.resetSelection(element);
73 public void resetDialogButtons() {
74 if (propertyDialog != null && propertyDialog.isOpen())
75 propertyDialog.resetButtons();
78 public void setComparator(Comparator<Object> comparator) {
79 this.comparator = comparator;
80 if (propertyDialog != null && propertyDialog.isOpen())
81 propertyDialog.setComparator(comparator);
85 if (propertyDialog != null && propertyDialog.isOpen()) {
90 //get initial selection
91 IAdaptable element = (IAdaptable) getStructuredSelection().getFirstElement();
92 if ((element == null) || (!(element instanceof LogEntry)))
95 propertyDialog = new EventDetailsDialog(shell, element, provider, comparator, memento);
96 propertyDialog.create();
97 propertyDialog.getShell().setText(Messages.EventDetailsDialog_title);
98 propertyDialog.open();