blob: 7cf99a788daec76e21c1a2f5bde5e30e94ab1c38 [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.ui.IWorkbenchPart;
import org.eclipse.viatra2.core.IModelElement;
import org.eclipse.viatra2.treeeditor.Plugin;
import org.eclipse.viatra2.treeeditor.ViatraTreeEditor;
import org.eclipse.viatra2.treeeditor.commands.AddModelElementCommand;
public class NewRelationAction extends ViatraTreeEditorSelectionAction {
public static final String ID = "ViatraTreeEditor.Actions.NewRelationAction";
public NewRelationAction(IWorkbenchPart part) {
super(part);
setText("Add Relation");
setToolTipText("Create a new relation with the selected model element as its source and target.");
setImageDescriptor(Plugin.getImageDescriptor("icons/relation_transparent.png"));
}
public void run() {
IModelElement source = (IModelElement) getSelectedObjects().toList().get(0);
AddModelElementCommand cmd = new AddModelElementCommand();
cmd.setSource(source);
((ViatraTreeEditor) iPart).getCommandStack().execute(cmd);
((ViatraTreeEditor) iPart).updateActions();
}
@Override
public void updateSelf() {
if (getSelectedObjects().size() == 1 && getSelectedObjects().getFirstElement() instanceof IModelElement)
{
String s = ((IModelElement) getSelectedObjects().getFirstElement()).getFullyQualifiedName();
if (s!=null && s.length()>0)
setEnabled(true);
else
setEnabled(false);
}
else
setEnabled(false);
}
}