blob: f97c8fb87be880f1c6227019bffd18bcc5b74658 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2004-2008 Istvan Rath and Daniel Varro
* 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:
* Istvan Rath - initial API and implementation
*******************************************************************************/
package org.eclipse.viatra2.treeeditor.actions;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.viatra2.core.IModelElement;
import org.eclipse.viatra2.core.IRelation;
import org.eclipse.viatra2.treeeditor.Plugin;
import org.eclipse.viatra2.treeeditor.ViatraTreeEditor;
public class NavigateRelationAction extends ViatraTreeEditorSelectionAction {
public static final String ID = "ViatraTreeEditor.Actions.NavigateRelationAction";
public NavigateRelationAction(IWorkbenchPart part) {
super(part);
setText("Navigate to target");
setToolTipText("Reveal and select the target of this relation.");
setImageDescriptor(Plugin.getImageDescriptor("icons/relation_transparent.png"));
}
public void run() {
final IRelation source = (IRelation) getSelectedObjects().toList().get(0);
Display.getDefault().asyncExec(new Runnable(){
public void run() {
try {
((ViatraTreeEditor)iPart).getTreeViewer().reveal( source.getTo() );
((ViatraTreeEditor)iPart).getTreeViewer().setSelection(new StructuredSelection(new Object[]{source.getTo()}));
}
catch (Exception e) { e.printStackTrace(); }
}
});
}
@Override
public void updateSelf() {
if (getSelectedObjects().size() == 1 && getSelectedObjects().getFirstElement() instanceof IModelElement)
setEnabled(true);
else
setEnabled(false);
}
}