blob: 2d08dbd110c3afdcf3250d69f7fe762ce2fe4047 [file] [log] [blame]
/*
* Copyright (c) 2003, 2005 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 - initial API and implementation
*
* $Id: UnapplyProfileAction.java,v 1.4 2005/06/02 14:29:46 khussey Exp $
*/
package org.eclipse.uml2.examples.ui.actions;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
import org.eclipse.emf.common.command.Command;
import org.eclipse.emf.common.command.IdentityCommand;
import org.eclipse.emf.common.command.UnexecutableCommand;
import org.eclipse.emf.edit.domain.EditingDomain;
import org.eclipse.emf.edit.ui.celleditor.FeatureEditorDialog;
import org.eclipse.jface.action.IAction;
import org.eclipse.uml2.Profile;
import org.eclipse.uml2.ProfileApplication;
import org.eclipse.uml2.UML2Package;
import org.eclipse.uml2.common.edit.command.ChangeCommand;
import org.eclipse.uml2.examples.ui.ExamplesUIPlugin;
/**
*
*/
public class UnapplyProfileAction
extends UML2CommandAction {
public UnapplyProfileAction() {
super();
}
/*
* (non-Javadoc)
*
* @see org.eclipse.emf.edit.ui.action.CommandAction#createActionCommand(org.eclipse.emf.edit.domain.EditingDomain,
* java.util.Collection)
*/
protected Command createActionCommand(EditingDomain editingDomain,
Collection collection) {
if (1 == collection.size()
&& org.eclipse.uml2.Package.class
.isInstance(collection.toArray()[0])) {
return IdentityCommand.INSTANCE;
}
return UnexecutableCommand.INSTANCE;
}
/*
* (non-Javadoc)
*
* @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
*/
public void run(IAction action) {
if (UnexecutableCommand.INSTANCE != command) {
final org.eclipse.uml2.Package package_ = (org.eclipse.uml2.Package) collection
.toArray()[0];
List choiceOfValues = new ArrayList();
for (Iterator appliedProfiles = package_.getAppliedProfiles()
.iterator(); appliedProfiles.hasNext();) {
ProfileApplication profileApplication = (ProfileApplication) appliedProfiles
.next();
if (null != profileApplication.getImportedProfile()) {
choiceOfValues.add(profileApplication.getImportedProfile());
}
}
Collections.sort(choiceOfValues, new Comparator() {
public int compare(Object o1, Object o2) {
return getLabelProvider().getText(o1).compareTo(
getLabelProvider().getText(o2));
}
});
String label = ExamplesUIPlugin.INSTANCE.getString(
"_UI_UnapplyProfileActionCommand_label", //$NON-NLS-1$
new Object[]{getLabelProvider()
.getText(collection.toArray()[0])});
final FeatureEditorDialog dialog = new FeatureEditorDialog(
workbenchPart.getSite().getShell(), getLabelProvider(),
package_, UML2Package.eINSTANCE.getProfile(),
Collections.EMPTY_LIST, label, choiceOfValues);
dialog.open();
if (FeatureEditorDialog.OK == dialog.getReturnCode()) {
editingDomain.getCommandStack().execute(
new ChangeCommand(editingDomain, new Runnable() {
public void run() {
for (Iterator profiles = dialog.getResult()
.iterator(); profiles.hasNext();) {
package_.unapply((Profile) profiles.next());
}
}
}, label));
}
}
}
}