tmf : Add search dialog to timegraph views
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.ui / src / org / eclipse / tracecompass / tmf / ui / views / timegraph / ShowFindDialogAction.java
1 /*******************************************************************************
2 * Copyright (c) 2016 Ericsson
3 *
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;
10
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;
18
19 /**
20 * Action to show a time graph find dialog to search for a
21 * {@link ITimeGraphEntry}
22 *
23 * @author Jean-Christian Kouame
24 */
25 class ShowFindDialogAction extends Action {
26
27 private static final int SHELL_MINIMUM_SIZE = 320;
28 private static TimeGraphFindDialog fDialog;
29 private FindTarget fFindTarget;
30
31 /**
32 * Constructor
33 */
34 public ShowFindDialogAction() {
35 setText(Messages.ShowFindDialogAction_Search);
36 setToolTipText(Messages.ShowFindDialogAction_ShowSearchDialog);
37 setImageDescriptor(Activator.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_SEARCH));
38 }
39
40 @Override
41 public void run() {
42 FindTarget findTarget = fFindTarget;
43 if (findTarget == null) {
44 return;
45 }
46 checkShell(findTarget);
47 if (fDialog == null) {
48 fDialog = new TimeGraphFindDialog(findTarget.getShell());
49 }
50 if (fDialog != null) {
51 fDialog.update(findTarget);
52 fDialog.open();
53 fDialog.getShell().setMinimumSize(SHELL_MINIMUM_SIZE, SHELL_MINIMUM_SIZE);
54 }
55 }
56
57 /**
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.
60 *
61 * @param target
62 * the target that owns the shell to check
63 */
64 public void checkShell(FindTarget target) {
65 if (fDialog != null && !fDialog.isDialogParentShell(target.getShell())) {
66 fDialog.close();
67 fDialog = null;
68 }
69 }
70
71 /**
72 * Define what to do when a part is activated.
73 *
74 * @param part
75 * The activated workbenchPart
76 */
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;
83 }
84 }
85 /*
86 * Update target in all for all parts. If it is null the dialog will
87 * disable the find button.
88 */
89 if (fDialog != null) {
90 fDialog.updateTarget(newTarget, false);
91 }
92 }
93
94 }
This page took 0.033961 seconds and 5 git commands to generate.