/******************************************************************************* | |
* 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.IEntity; | |
import org.eclipse.viatra2.treeeditor.Plugin; | |
import org.eclipse.viatra2.treeeditor.ViatraTreeEditor; | |
import org.eclipse.viatra2.treeeditor.commands.AddModelElementCommand; | |
public class NewEntityAction extends ViatraTreeEditorSelectionAction { | |
public static final String ID = "ViatraTreeEditor.Actions.NewEntityAction"; | |
public NewEntityAction(IWorkbenchPart part) { | |
super(part); | |
setId(ID); | |
setText("Add Entity"); | |
setToolTipText("Create a new entity with the selected entity as its parent."); | |
setImageDescriptor(Plugin.getImageDescriptor("icons/entity_transparent.png")); | |
} | |
public void run() { | |
IEntity parent = (IEntity)getSelectedObjects().toList().get(0); | |
AddModelElementCommand cmd = new AddModelElementCommand(); | |
cmd.setParent(parent); | |
((ViatraTreeEditor) iPart).getCommandStack().execute(cmd); | |
((ViatraTreeEditor) iPart).updateActions(); | |
} | |
@Override | |
public void updateSelf() { | |
if (getSelectedObjects().size() == 1 && getSelectedObjects().getFirstElement() instanceof IEntity) | |
{ | |
setEnabled(true); | |
} | |
else | |
setEnabled(false); | |
} | |
} |