blob: f3039af56a626cec32d9d3ca77b3ecffdabdd531 [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.IRelation;
import org.eclipse.viatra2.treeeditor.Plugin;
import org.eclipse.viatra2.treeeditor.ViatraTreeEditor;
import org.eclipse.viatra2.treeeditor.providers.ViatraContentProvider.TargetRelationDummy;
public class NavigateRelationSourceAction extends ViatraTreeEditorSelectionAction {
public static final String ID = "ViatraTreeEditor.Actions.NavigateRelationSourceAction";
public NavigateRelationSourceAction(IWorkbenchPart part) {
super(part);
setText("Navigate to source");
setToolTipText("Reveal and select the source of this relation.");
setImageDescriptor(Plugin.getImageDescriptor("icons/relation_target_transparent.png"));
}
public void run() {
final IRelation source = ((TargetRelationDummy)getSelectedObjects().toList().get(0)).rel;
Display.getDefault().asyncExec(new Runnable(){
public void run() {
try {
((ViatraTreeEditor)iPart).getTreeViewer().reveal( source.getFrom() );
((ViatraTreeEditor)iPart).getTreeViewer().setSelection(new StructuredSelection(new Object[]{source.getFrom()}));
}
catch (Exception e) { e.printStackTrace(); }
}
});
}
@Override
public void updateSelf() {
if (getSelectedObjects().size() == 1 && getSelectedObjects().getFirstElement() instanceof TargetRelationDummy)
setEnabled(true);
else
setEnabled(false);
}
}