blob: 0954ae0fa98e31efd0f1b6ff7b70e24475c6ff10 [file] [log] [blame]
//------------------------------------------------------------------------------
// Copyright (c) 2005, 2006 IBM Corporation and others.
// 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:
// IBM Corporation - initial implementation
//------------------------------------------------------------------------------
package org.eclipse.epf.authoring.ui.actions;
import org.eclipse.epf.authoring.ui.AuthoringUIPlugin;
import org.eclipse.epf.authoring.ui.views.LibraryView;
import org.eclipse.epf.library.edit.util.TngUtil;
import org.eclipse.epf.uma.MethodElement;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.actions.BaseSelectionListenerAction;
/**
*
* Finds an element in library view
*
* @author Shilpa Toraskar
* @since 1.0
*
*/
public class LibraryViewFindElementAction extends BaseSelectionListenerAction {
/**
* The ID for this action.
*/
public static final String ACTION_ID = LibraryViewFindElementAction.class
.getName();
private LibraryView targetView;
private IStructuredSelection selected;
public LibraryViewFindElementAction(String text) {
super(text);
}
/**
* @see org.eclipse.jface.action.Action#run()
*/
public void run() {
if (targetView == null)
targetView = LibraryView.getView();
// select currentSelection in Lib View
if (targetView != null && selected != null && !selected.isEmpty()) {
// Bugzilla Bug 177805
try {
targetView.getSite().getPage().showView(LibraryView.VIEW_ID);
} catch (PartInitException pe) {
AuthoringUIPlugin.getDefault().getLogger().logError(pe);
}
targetView.setSelectionToViewer(selected.getFirstElement());
}
}
/**
* @see org.eclipse.ui.actions.BaseSelectionListenerAction#updateSelection(org.eclipse.jface.viewers.IStructuredSelection)
*/
protected boolean updateSelection(IStructuredSelection selection) {
selected = selection;
if (selection != null && !selection.isEmpty()) {
Object element = selection.getFirstElement();
Object realObj = TngUtil.unwrap(element);
if (realObj instanceof MethodElement) {
return true;
}
}
return false;
}
}