### Eclipse Workspace Patch 1.0 #P org.eclipse.uml2.uml.editor Index: src/org/eclipse/uml2/uml/editor/actions/ImportPrimitiveTypeAction.java =================================================================== RCS file: /cvsroot/tools/org.eclipse.uml2/plugins/org.eclipse.uml2.uml.editor/src/org/eclipse/uml2/uml/editor/actions/ImportPrimitiveTypeAction.java,v retrieving revision 1.2 diff -u -r1.2 ImportPrimitiveTypeAction.java --- src/org/eclipse/uml2/uml/editor/actions/ImportPrimitiveTypeAction.java 10 Oct 2006 20:40:49 -0000 1.2 +++ src/org/eclipse/uml2/uml/editor/actions/ImportPrimitiveTypeAction.java 28 Nov 2006 19:15:10 -0000 @@ -13,25 +13,13 @@ package org.eclipse.uml2.uml.editor.actions; import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; 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.common.util.URI; import org.eclipse.emf.ecore.resource.Resource; import org.eclipse.emf.ecore.resource.ResourceSet; -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.common.edit.command.ChangeCommand; import org.eclipse.uml2.uml.PrimitiveType; -import org.eclipse.uml2.uml.UMLPackage; -import org.eclipse.uml2.uml.VisibilityKind; -import org.eclipse.uml2.uml.editor.UMLEditorPlugin; import org.eclipse.uml2.uml.resource.UMLResource; public class ImportPrimitiveTypeAction @@ -40,129 +28,84 @@ public ImportPrimitiveTypeAction() { super(); } + + protected List getChoiceOfValues(org.eclipse.uml2.uml.Package package_){ + List choiceOfValues = new ArrayList(); - protected Command createActionCommand(EditingDomain editingDomain, - Collection collection) { + Resource eResource = package_.eResource(); + ResourceSet resourceSet = eResource == null + ? null + : eResource.getResourceSet(); - if (collection.size() == 1 - && collection.iterator().next() instanceof org.eclipse.uml2.uml.Package) { + if (resourceSet != null) { - return IdentityCommand.INSTANCE; - } - - return UnexecutableCommand.INSTANCE; - } - - public void run(IAction action) { - - if (command != UnexecutableCommand.INSTANCE) { - final org.eclipse.uml2.uml.Package package_ = (org.eclipse.uml2.uml.Package) collection - .iterator().next(); - - List choiceOfValues = new ArrayList(); - - Resource eResource = package_.eResource(); - ResourceSet resourceSet = eResource == null - ? null - : eResource.getResourceSet(); - - if (resourceSet != null) { + try { + Resource resource = resourceSet + .getResource( + URI + .createURI(UMLResource.UML_PRIMITIVE_TYPES_LIBRARY_URI), + true); - try { - Resource resource = resourceSet - .getResource( - URI - .createURI(UMLResource.UML_PRIMITIVE_TYPES_LIBRARY_URI), - true); + for (Iterator contents = resource.getAllContents(); contents + .hasNext();) { - for (Iterator contents = resource.getAllContents(); contents - .hasNext();) { + Object object = contents.next(); - Object object = contents.next(); + if (object instanceof PrimitiveType + && !package_.getImportedElements().contains(object)) { - if (object instanceof PrimitiveType - && !package_.getImportedElements().contains(object)) { - - choiceOfValues.add(object); - } + choiceOfValues.add(object); } - } catch (Exception e) { - // ignore } + } catch (Exception e) { + // ignore + } - try { - Resource resource = resourceSet - .getResource( - URI - .createURI(UMLResource.JAVA_PRIMITIVE_TYPES_LIBRARY_URI), - true); - - for (Iterator contents = resource.getAllContents(); contents - .hasNext();) { + try { + Resource resource = resourceSet + .getResource( + URI + .createURI(UMLResource.JAVA_PRIMITIVE_TYPES_LIBRARY_URI), + true); + + for (Iterator contents = resource.getAllContents(); contents + .hasNext();) { - Object object = contents.next(); + Object object = contents.next(); - if (object instanceof PrimitiveType - && !package_.getImportedElements().contains(object)) { + if (object instanceof PrimitiveType + && !package_.getImportedElements().contains(object)) { - choiceOfValues.add(object); - } + choiceOfValues.add(object); } - } catch (Exception e) { - // ignore } + } catch (Exception e) { + // ignore + } - try { - Resource resource = resourceSet - .getResource( - URI - .createURI(UMLResource.ECORE_PRIMITIVE_TYPES_LIBRARY_URI), - true); - - for (Iterator contents = resource.getAllContents(); contents - .hasNext();) { + try { + Resource resource = resourceSet + .getResource( + URI + .createURI(UMLResource.ECORE_PRIMITIVE_TYPES_LIBRARY_URI), + true); + + for (Iterator contents = resource.getAllContents(); contents + .hasNext();) { - Object object = contents.next(); + Object object = contents.next(); - if (object instanceof PrimitiveType - && !package_.getImportedElements().contains(object)) { + if (object instanceof PrimitiveType + && !package_.getImportedElements().contains(object)) { - choiceOfValues.add(object); - } + choiceOfValues.add(object); } - } catch (Exception e) { - // ignore } - } - - Collections.sort(choiceOfValues, new TextComparator()); - - String label = UMLEditorPlugin.INSTANCE - .getString("_UI_ImportPrimitiveTypeActionCommand_label"); //$NON-NLS-1$ - - final FeatureEditorDialog dialog = new FeatureEditorDialog( - workbenchPart.getSite().getShell(), getLabelProvider(), - package_, UMLPackage.Literals.PACKAGEABLE_ELEMENT, - Collections.EMPTY_LIST, label, choiceOfValues); - dialog.open(); - - if (dialog.getReturnCode() == FeatureEditorDialog.OK) { - editingDomain.getCommandStack().execute( - new ChangeCommand(editingDomain, new Runnable() { - - public void run() { - - for (Iterator primitiveTypes = dialog.getResult() - .iterator(); primitiveTypes.hasNext();) { - - package_.createElementImport( - (PrimitiveType) primitiveTypes.next(), - VisibilityKind.PUBLIC_LITERAL); - } - } - }, label)); + } catch (Exception e) { + // ignore } } + return choiceOfValues; } - + } Index: plugin.properties =================================================================== RCS file: /cvsroot/tools/org.eclipse.uml2/plugins/org.eclipse.uml2.uml.editor/plugin.properties,v retrieving revision 1.9 diff -u -r1.9 plugin.properties --- plugin.properties 10 Jun 2006 20:29:51 -0000 1.9 +++ plugin.properties 28 Nov 2006 19:15:10 -0000 @@ -81,7 +81,7 @@ _UI_UnapplyStereotypeAction_label = &Unapply Stereotype... _UI_ApplyProfileAction_label = &Apply Profile... -_UI_ImportPrimitiveTypeAction_label = &Import Primitive Type... +_UI_ImportTypeAction_label = &Import Type... _UI_MergePackageAction_label = &Merge... _UI_UnapplyProfileAction_label = &Unapply Profile... @@ -98,6 +98,7 @@ _UI_ApplyProfileActionCommand_label = Apply Profile(s) _UI_ImportPrimitiveTypeActionCommand_label = Import Primitive Type(s) +_UI_ImportTypeActionCommand_label = Import Type(s) _UI_MergePackageActionCommand_label = Merge Package ''{0}'' _UI_UnapplyProfileActionCommand_label = Unapply Profile(s) Index: plugin.xml =================================================================== RCS file: /cvsroot/tools/org.eclipse.uml2/plugins/org.eclipse.uml2.uml.editor/plugin.xml,v retrieving revision 1.8 diff -u -r1.8 plugin.xml --- plugin.xml 2 May 2006 21:42:26 -0000 1.8 +++ plugin.xml 28 Nov 2006 19:15:10 -0000 @@ -142,11 +142,11 @@ + id="org.eclipse.uml2.uml.editor.ImportTypeActionID"> Index: src/org/eclipse/uml2/uml/editor/actions/ImportTypeAction.java =================================================================== RCS file: src/org/eclipse/uml2/uml/editor/actions/ImportTypeAction.java diff -N src/org/eclipse/uml2/uml/editor/actions/ImportTypeAction.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/uml2/uml/editor/actions/ImportTypeAction.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,131 @@ +/* + * Copyright (c) 2005, 2006 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: ImportTypeAction.java,v 1.2 2006/11/28 20:40:49 khussey Exp $ + */ + +package org.eclipse.uml2.uml.editor.actions; + +import java.util.Collection; +import java.util.Collections; +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.common.util.URI; +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.emf.ecore.resource.ResourceSet; +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.common.edit.command.ChangeCommand; +import org.eclipse.uml2.uml.DataType; +import org.eclipse.uml2.uml.UMLPackage; +import org.eclipse.uml2.uml.VisibilityKind; +import org.eclipse.uml2.uml.editor.UMLEditorPlugin; +import org.eclipse.uml2.uml.resource.UMLResource; + + +public class ImportTypeAction + extends ImportPrimitiveTypeAction { + + public ImportTypeAction() { + super(); + } + + protected Command createActionCommand(EditingDomain editingDomain, + Collection collection) { + + if (collection.size() == 1 + && collection.iterator().next() instanceof org.eclipse.uml2.uml.Package) { + + return IdentityCommand.INSTANCE; + } + + return UnexecutableCommand.INSTANCE; + } + + protected List getChoiceOfValues(org.eclipse.uml2.uml.Package package_){ + + List choiceOfValues = super.getChoiceOfValues(package_); + + Resource eResource = package_.eResource(); + ResourceSet resourceSet = eResource == null + ? null + : eResource.getResourceSet(); + + try { + Resource resource = resourceSet + .getResource( + URI + .createURI(UMLResource.XML_DATA_TYPES_LIBRARY_URI), + true); + + for (Iterator contents = resource.getAllContents(); contents + .hasNext();) { + + Object object = contents.next(); + + if (object instanceof DataType + && !package_.getImportedElements().contains(object)) { + + choiceOfValues.add(object); + } + } + } catch (Exception e) { + // ignore + } + + return choiceOfValues; + } + + + public void run(IAction action) { + + if (command != UnexecutableCommand.INSTANCE) { + final org.eclipse.uml2.uml.Package package_ = (org.eclipse.uml2.uml.Package) collection + .iterator().next(); + + List choiceOfValues = getChoiceOfValues(package_); + + Collections.sort(choiceOfValues, new TextComparator()); + + String label = UMLEditorPlugin.INSTANCE + .getString("_UI_ImportTypeActionCommand_label"); //$NON-NLS-1$ + + final FeatureEditorDialog dialog = new FeatureEditorDialog( + workbenchPart.getSite().getShell(), getLabelProvider(), + package_, UMLPackage.Literals.PACKAGEABLE_ELEMENT, + Collections.EMPTY_LIST, label, choiceOfValues); + dialog.open(); + + if (dialog.getReturnCode() == FeatureEditorDialog.OK) { + editingDomain.getCommandStack().execute( + new ChangeCommand(editingDomain, new Runnable() { + + public void run() { + + for (Iterator dataTypes = dialog.getResult() + .iterator(); dataTypes.hasNext();) { + + package_.createElementImport( + (DataType) dataTypes.next(), + VisibilityKind.PUBLIC_LITERAL); + } + } + }, label)); + } + } + } + + +}