1 /*******************************************************************************
2 * Copyright (c) 2016 Ericsson
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *******************************************************************************/
9 package org
.eclipse
.tracecompass
.tmf
.ui
.views
.timegraph
;
11 import org
.eclipse
.jface
.action
.Action
;
12 import org
.eclipse
.tracecompass
.internal
.tmf
.ui
.Activator
;
13 import org
.eclipse
.tracecompass
.internal
.tmf
.ui
.ITmfImageConstants
;
14 import org
.eclipse
.tracecompass
.internal
.tmf
.ui
.Messages
;
15 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.timegraph
.AbstractTimeGraphView
.FindTarget
;
16 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.ITimeGraphEntry
;
17 import org
.eclipse
.ui
.IWorkbenchPart
;
20 * Action to show a time graph find dialog to search for a
21 * {@link ITimeGraphEntry}
23 * @author Jean-Christian Kouame
25 class ShowFindDialogAction
extends Action
{
27 private static final int SHELL_MINIMUM_SIZE
= 320;
28 private static TimeGraphFindDialog fDialog
;
29 private FindTarget fFindTarget
;
34 public ShowFindDialogAction() {
35 setText(Messages
.ShowFindDialogAction_Search
);
36 setToolTipText(Messages
.ShowFindDialogAction_ShowSearchDialog
);
37 setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_SEARCH
));
42 FindTarget findTarget
= fFindTarget
;
43 if (findTarget
== null) {
46 checkShell(findTarget
);
47 if (fDialog
== null) {
48 fDialog
= new TimeGraphFindDialog(findTarget
.getShell());
50 if (fDialog
!= null) {
51 fDialog
.update(findTarget
);
53 fDialog
.getShell().setMinimumSize(SHELL_MINIMUM_SIZE
, SHELL_MINIMUM_SIZE
);
58 * Checks if the dialogs shell is the same as the given <code>shell</code>
59 * and if not clears the stub and closes the dialog.
62 * the target that owns the shell to check
64 public void checkShell(FindTarget target
) {
65 if (fDialog
!= null && !fDialog
.isDialogParentShell(target
.getShell())) {
72 * Define what to do when a part is activated.
75 * The activated workbenchPart
77 public synchronized void partActivated(IWorkbenchPart part
) {
78 FindTarget newTarget
= null;
79 if (part
instanceof AbstractTimeGraphView
) {
80 newTarget
= ((AbstractTimeGraphView
) part
).getFindTarget();
81 if (newTarget
!= fFindTarget
) {
82 fFindTarget
= newTarget
;
86 * Update target in all for all parts. If it is null the dialog will
87 * disable the find button.
89 if (fDialog
!= null) {
90 fDialog
.updateTarget(newTarget
, false);