| 1 | /********************************************************************** |
| 2 | * Copyright (c) 2005, 2012 IBM Corporation, Ericsson |
| 3 | * All rights reserved. This program and the accompanying materials |
| 4 | * are made available under the terms of the Eclipse Public License v1.0 |
| 5 | * which accompanies this distribution, and is available at |
| 6 | * http://www.eclipse.org/legal/epl-v10.html |
| 7 | * |
| 8 | * Contributors: |
| 9 | * IBM - Initial API and implementation |
| 10 | * Bernd Hufmann - Updated for TMF |
| 11 | **********************************************************************/ |
| 12 | |
| 13 | package org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers; |
| 14 | |
| 15 | import org.eclipse.jface.action.Action; |
| 16 | import org.eclipse.linuxtools.internal.tmf.ui.ITmfImageConstants; |
| 17 | import org.eclipse.linuxtools.internal.tmf.ui.Activator; |
| 18 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.SDView; |
| 19 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.dialogs.SearchFilterDialog; |
| 20 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.util.SDMessages; |
| 21 | import org.eclipse.swt.SWT; |
| 22 | |
| 23 | /** |
| 24 | * Action class implementation for 'Finding' of messages/lifelines. |
| 25 | * |
| 26 | * @version 1.0 |
| 27 | * @author sveyrier |
| 28 | * |
| 29 | */ |
| 30 | public class OpenSDFindDialog extends Action { |
| 31 | |
| 32 | // ------------------------------------------------------------------------ |
| 33 | // Constants |
| 34 | // ------------------------------------------------------------------------ |
| 35 | /** |
| 36 | * The action ID. |
| 37 | */ |
| 38 | public final static String ID = "org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.sdFind"; //$NON-NLS-1$ |
| 39 | /** |
| 40 | * The action definition ID. |
| 41 | */ |
| 42 | public final static String ACTION_DEFINITION_ID = "org.eclipse.ui.edit.findReplace"; //$NON-NLS-1$ |
| 43 | |
| 44 | // ------------------------------------------------------------------------ |
| 45 | // Attributes |
| 46 | // ------------------------------------------------------------------------ |
| 47 | /** |
| 48 | * The sequence diagram view reference |
| 49 | */ |
| 50 | protected SDView fView; |
| 51 | |
| 52 | // ------------------------------------------------------------------------ |
| 53 | // Constructors |
| 54 | // ------------------------------------------------------------------------ |
| 55 | /** |
| 56 | * Default constructor |
| 57 | */ |
| 58 | public OpenSDFindDialog() { |
| 59 | this(null); |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * Constructor |
| 64 | * |
| 65 | * @param view The view reference |
| 66 | */ |
| 67 | public OpenSDFindDialog(SDView view) { |
| 68 | super(SDMessages._41); |
| 69 | setImageDescriptor(Activator.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_SEARCH_SEQ)); |
| 70 | setId(ID); |
| 71 | setActionDefinitionId(ACTION_DEFINITION_ID); |
| 72 | setToolTipText(SDMessages._41); |
| 73 | fView = view; |
| 74 | } |
| 75 | |
| 76 | // ------------------------------------------------------------------------ |
| 77 | // Methods |
| 78 | // ------------------------------------------------------------------------ |
| 79 | /* |
| 80 | * (non-Javadoc) |
| 81 | * @see org.eclipse.jface.action.Action#run() |
| 82 | */ |
| 83 | @Override |
| 84 | public void run() { |
| 85 | if (fView == null) { |
| 86 | return; |
| 87 | } |
| 88 | |
| 89 | // Disable action while search is ongoing |
| 90 | this.setEnabled(false); |
| 91 | |
| 92 | try { |
| 93 | if ((fView.getExtendedFindProvider() != null) && (fView.getExtendedFindProvider().getFindAction() != null)) { |
| 94 | fView.getExtendedFindProvider().getFindAction().run(); |
| 95 | } else if (fView.getSDFindProvider() != null) { |
| 96 | SearchFilterDialog dialog = new SearchFilterDialog(fView, fView.getSDFindProvider(), false, SWT.NORMAL); |
| 97 | dialog.open(); |
| 98 | } |
| 99 | } finally { |
| 100 | // Enable action after finishing the search |
| 101 | this.setEnabled(true); |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | /** |
| 106 | * Sets the active SD view. |
| 107 | * |
| 108 | * @param view The SD view. |
| 109 | */ |
| 110 | public void setView(SDView view) { |
| 111 | fView = view; |
| 112 | } |
| 113 | } |