blob: dd8291b929f4c4b3c51991769e82336741c13379 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
/*******************************************************************************
* Copyright (c) 2008, 2009 THALES GLOBAL SERVICES.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Obeo - initial API and implementation
*******************************************************************************/
package org.eclipse.sirius.diagram.ui.tools.api.action;
import org.eclipse.gmf.runtime.diagram.ui.parts.DiagramEditor;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.sirius.common.ui.tools.api.find.AbstractFindLabelDialog;
import org.eclipse.sirius.diagram.ui.tools.internal.find.BasicFindLabelEngine;
import org.eclipse.ui.IObjectActionDelegate;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI;
/**
* A find element Eclipse action.
*
* @author glefur
*/
public class FindElementAction implements IObjectActionDelegate {
/**
* The action ID.
*/
public static final String ID = "org.eclipse.sirius.transversal.find.ui.binding.FindElementAction"; //$NON-NLS-1$
private DiagramEditor currentPart;
/**
* {@inheritDoc}
*
* @see org.eclipse.ui.IObjectActionDelegate#setActivePart(org.eclipse.jface.action.IAction,
* org.eclipse.ui.IWorkbenchPart)
*/
public void setActivePart(final IAction action, final IWorkbenchPart targetPart) {
if (targetPart instanceof DiagramEditor) {
currentPart = (DiagramEditor) targetPart;
}
}
/**
* {@inheritDoc}
*
* @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
*/
public void run(final IAction action) {
if (currentPart != null) {
final AbstractFindLabelDialog dialog = new RevealFindLabelDialog(currentPart.getSite().getShell(), new BasicFindLabelEngine(currentPart), currentPart);
dialog.open();
}
}
/**
* {@inheritDoc}
*
* @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction,
* org.eclipse.jface.viewers.ISelection)
*/
public void selectionChanged(final IAction action, final ISelection selection) {
final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (window != null) {
final IWorkbenchPage page = window.getActivePage();
if (page != null) {
final IWorkbenchPart targetPart = page.getActivePart();
if (targetPart instanceof DiagramEditor) {
currentPart = (DiagramEditor) targetPart;
}
}
}
}
}
|