diff options
author | ptessier | 2013-10-30 17:24:34 +0000 |
---|---|---|
committer | ptessier | 2013-10-30 17:24:34 +0000 |
commit | b6496a204a2a88b8bf9e426bd01e9e81be123adb (patch) | |
tree | 472b9f4096e74e77cc62bc30fd7bedc84e4b965b | |
parent | f51b14114fa4e8ef30e980187b06aa8ad87f9e9f (diff) | |
parent | 06abcaf8f6c39d0f65a289836fe27a2fc0ac2306 (diff) | |
download | org.eclipse.papyrus-b6496a204a2a88b8bf9e426bd01e9e81be123adb.tar.gz org.eclipse.papyrus-b6496a204a2a88b8bf9e426bd01e9e81be123adb.tar.xz org.eclipse.papyrus-b6496a204a2a88b8bf9e426bd01e9e81be123adb.zip |
Merge branch 'master' of ssh://ptessier@git.eclipse.org/gitroot/papyrus/org.eclipse.papyrus.git
3 files changed, 427 insertions, 418 deletions
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.dnd/META-INF/MANIFEST.MF b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.dnd/META-INF/MANIFEST.MF index 8c0dd41ece5..6bb3fcf838f 100644 --- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.dnd/META-INF/MANIFEST.MF +++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.dnd/META-INF/MANIFEST.MF @@ -1,24 +1,25 @@ -Manifest-Version: 1.0
-Require-Bundle: org.eclipse.ui,
- org.eclipse.core.runtime,
- org.eclipse.papyrus.infra.core.log;bundle-version="0.10.1",
- org.eclipse.gmf.runtime.diagram.ui;bundle-version="1.5.0",
- org.eclipse.papyrus.infra.gmfdiag.common;bundle-version="0.10.1",
- org.eclipse.papyrus.infra.emf;bundle-version="0.10.1",
- org.eclipse.papyrus.infra.gmfdiag.commands;bundle-version="0.10.1",
- org.eclipse.papyrus.uml.service.types;bundle-version="0.10.1",
- org.eclipse.papyrus.infra.services.edit;bundle-version="0.10.1",
- org.eclipse.papyrus.infra.widgets;bundle-version="0.10.1",
- org.eclipse.core.databinding;bundle-version="1.4.1"
-Export-Package: org.eclipse.papyrus.infra.gmfdiag.dnd.policy,
- org.eclipse.papyrus.infra.gmfdiag.dnd.strategy
-Bundle-Vendor: Eclipse Modeling Project
-Bundle-ActivationPolicy: lazy
-Bundle-Version: 0.10.1.qualifier
-Bundle-Name: Customizable Drag and Drop (Incubation)
-Bundle-ManifestVersion: 2
-Bundle-Activator: org.eclipse.papyrus.infra.gmfdiag.dnd.Activator
-Bundle-SymbolicName: org.eclipse.papyrus.infra.gmfdiag.dnd;singleton:=
- true
-Bundle-RequiredExecutionEnvironment: J2SE-1.5
-
+Manifest-Version: 1.0 +Require-Bundle: org.eclipse.ui, + org.eclipse.core.runtime, + org.eclipse.papyrus.infra.core.log;bundle-version="0.10.1", + org.eclipse.gmf.runtime.diagram.ui;bundle-version="1.5.0", + org.eclipse.papyrus.infra.gmfdiag.common;bundle-version="0.10.1", + org.eclipse.papyrus.infra.emf;bundle-version="0.10.1", + org.eclipse.papyrus.infra.gmfdiag.commands;bundle-version="0.10.1", + org.eclipse.papyrus.uml.service.types;bundle-version="0.10.1", + org.eclipse.papyrus.infra.services.edit;bundle-version="0.10.1", + org.eclipse.papyrus.infra.widgets;bundle-version="0.10.1", + org.eclipse.core.databinding;bundle-version="1.4.1", + org.eclipse.papyrus.infra.core;bundle-version="0.10.1" +Export-Package: org.eclipse.papyrus.infra.gmfdiag.dnd.policy, + org.eclipse.papyrus.infra.gmfdiag.dnd.strategy +Bundle-Vendor: Eclipse Modeling Project +Bundle-ActivationPolicy: lazy +Bundle-Version: 0.10.1.qualifier +Bundle-Name: Customizable Drag and Drop (Incubation) +Bundle-ManifestVersion: 2 +Bundle-Activator: org.eclipse.papyrus.infra.gmfdiag.dnd.Activator +Bundle-SymbolicName: org.eclipse.papyrus.infra.gmfdiag.dnd;singleton:= + true +Bundle-RequiredExecutionEnvironment: J2SE-1.5 + diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.dnd/src/org/eclipse/papyrus/infra/gmfdiag/dnd/policy/CustomizableDropEditPolicyProvider.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.dnd/src/org/eclipse/papyrus/infra/gmfdiag/dnd/policy/CustomizableDropEditPolicyProvider.java index 3eaa41d59de..9fb5012cb77 100644 --- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.dnd/src/org/eclipse/papyrus/infra/gmfdiag/dnd/policy/CustomizableDropEditPolicyProvider.java +++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.dnd/src/org/eclipse/papyrus/infra/gmfdiag/dnd/policy/CustomizableDropEditPolicyProvider.java @@ -1,44 +1,49 @@ -/*****************************************************************************
- * Copyright (c) 2012 CEA LIST.
- *
- * 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:
- * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
- *****************************************************************************/
-package org.eclipse.papyrus.infra.gmfdiag.dnd.policy;
-
-import org.eclipse.gef.EditPart;
-import org.eclipse.gef.EditPolicy;
-import org.eclipse.gmf.runtime.common.core.service.AbstractProvider;
-import org.eclipse.gmf.runtime.common.core.service.IOperation;
-import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles;
-import org.eclipse.gmf.runtime.diagram.ui.services.editpolicy.CreateEditPoliciesOperation;
-import org.eclipse.gmf.runtime.diagram.ui.services.editpolicy.IEditPolicyProvider;
-
-
-public class CustomizableDropEditPolicyProvider extends AbstractProvider implements IEditPolicyProvider {
-
- public boolean provides(IOperation operation) {
- // return false;
- CreateEditPoliciesOperation epOperation = (CreateEditPoliciesOperation)operation;
-
- return true;
-
- // return !(epOperation.getEditPart() instanceof DiagramEditPart); //TODO: Detect Papyrus diagrams
- }
-
- public void createEditPolicies(EditPart editPart) {
- EditPolicy defaultDropEditPolicy = editPart.getEditPolicy(EditPolicyRoles.DRAG_DROP_ROLE);
- EditPolicy defaultCreationEditPolicy = editPart.getEditPolicy(EditPolicyRoles.CREATION_ROLE);
-
- CustomizableDropEditPolicy dropEditPolicy = new CustomizableDropEditPolicy(defaultDropEditPolicy, defaultCreationEditPolicy);
-
- editPart.installEditPolicy(EditPolicyRoles.DRAG_DROP_ROLE, null);
- editPart.installEditPolicy(EditPolicyRoles.CREATION_ROLE, dropEditPolicy);
- }
-
-}
+/***************************************************************************** + * Copyright (c) 2012 CEA LIST. + * + * 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: + * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation + *****************************************************************************/ +package org.eclipse.papyrus.infra.gmfdiag.dnd.policy; + +import org.eclipse.gef.EditPart; +import org.eclipse.gef.EditPolicy; +import org.eclipse.gmf.runtime.common.core.service.AbstractProvider; +import org.eclipse.gmf.runtime.common.core.service.IOperation; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles; +import org.eclipse.gmf.runtime.diagram.ui.services.editpolicy.CreateEditPoliciesOperation; +import org.eclipse.gmf.runtime.diagram.ui.services.editpolicy.IEditPolicyProvider; +import org.eclipse.papyrus.infra.core.services.ServiceException; +import org.eclipse.papyrus.infra.core.services.ServicesRegistry; +import org.eclipse.papyrus.infra.gmfdiag.common.utils.ServiceUtilsForEditPart; + + +public class CustomizableDropEditPolicyProvider extends AbstractProvider implements IEditPolicyProvider { + + public boolean provides(IOperation operation) { + CreateEditPoliciesOperation epOperation = (CreateEditPoliciesOperation)operation; + + try { + ServicesRegistry registry = ServiceUtilsForEditPart.getInstance().getServiceRegistry(epOperation.getEditPart()); + return registry != null; + } catch (ServiceException e) { + return false; + } + } + + public void createEditPolicies(EditPart editPart) { + EditPolicy defaultDropEditPolicy = editPart.getEditPolicy(EditPolicyRoles.DRAG_DROP_ROLE); + EditPolicy defaultCreationEditPolicy = editPart.getEditPolicy(EditPolicyRoles.CREATION_ROLE); + + CustomizableDropEditPolicy dropEditPolicy = new CustomizableDropEditPolicy(defaultDropEditPolicy, defaultCreationEditPolicy); + + editPart.installEditPolicy(EditPolicyRoles.DRAG_DROP_ROLE, null); + editPart.installEditPolicy(EditPolicyRoles.CREATION_ROLE, dropEditPolicy); + } + +}
\ No newline at end of file diff --git a/plugins/uml/properties/org.eclipse.papyrus.uml.properties/src/org/eclipse/papyrus/uml/properties/widgets/ProfileApplicationEditor.java b/plugins/uml/properties/org.eclipse.papyrus.uml.properties/src/org/eclipse/papyrus/uml/properties/widgets/ProfileApplicationEditor.java index 9d434806108..2941d14fbac 100644 --- a/plugins/uml/properties/org.eclipse.papyrus.uml.properties/src/org/eclipse/papyrus/uml/properties/widgets/ProfileApplicationEditor.java +++ b/plugins/uml/properties/org.eclipse.papyrus.uml.properties/src/org/eclipse/papyrus/uml/properties/widgets/ProfileApplicationEditor.java @@ -1,350 +1,353 @@ -/*****************************************************************************
- * Copyright (c) 2011, 2013 CEA LIST.
- *
- * 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:
- * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
- * Christian W. Damus (CEA) - Refactoring package/profile import/apply UI for CDO
- *
- *****************************************************************************/
-package org.eclipse.papyrus.uml.properties.widgets;
-
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.LinkedHashMap;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-
-import org.eclipse.emf.common.util.URI;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.jface.viewers.ColumnLabelProvider;
-import org.eclipse.jface.viewers.ColumnWeightData;
-import org.eclipse.jface.viewers.ILabelProvider;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.ISelectionChangedListener;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.viewers.SelectionChangedEvent;
-import org.eclipse.jface.viewers.TableLayout;
-import org.eclipse.jface.viewers.ViewerCell;
-import org.eclipse.jface.window.Window;
-import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
-import org.eclipse.papyrus.infra.widgets.editors.MultipleReferenceEditor;
-import org.eclipse.papyrus.uml.profile.definition.Version;
-import org.eclipse.papyrus.uml.profile.ui.dialogs.ElementImportTreeSelectionDialog.ImportSpec;
-import org.eclipse.papyrus.uml.profile.ui.dialogs.ProfileTreeSelectionDialog;
-import org.eclipse.papyrus.uml.profile.utils.Util;
-import org.eclipse.papyrus.uml.profile.validation.ProfileValidationHelper;
-import org.eclipse.papyrus.uml.properties.Activator;
-import org.eclipse.papyrus.uml.properties.messages.Messages;
-import org.eclipse.papyrus.uml.properties.profile.ui.dialogs.Message;
-import org.eclipse.papyrus.uml.properties.profile.ui.dialogs.RegisteredProfileSelectionDialog;
-import org.eclipse.papyrus.uml.tools.importsources.PackageImportSourceDialog;
-import org.eclipse.papyrus.uml.tools.utils.ProfileUtil;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.widgets.Button;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.TreeColumn;
-import org.eclipse.uml2.uml.Package;
-import org.eclipse.uml2.uml.Profile;
-
-/**
- * An editor for Profile application
- *
- * @author Camille Letavernier
- */
-public class ProfileApplicationEditor extends MultipleReferenceEditor {
-
- /**
- * The button to add profiles from the list of registered ones
- */
- protected Button addRegisteredProfile;
-
- /**
- * The button to reapply a profile
- */
- protected Button reapplyProfile;
-
- /**
- * The umlPackage being edited
- */
- protected Package umlPackage;
-
- /**
- *
- * Constructor.
- *
- * @param parent
- * @param style
- */
- public ProfileApplicationEditor(Composite parent, int style) {
- super(parent, style);
-
- tree.setHeaderVisible(true);
- GridData treeData = new GridData(SWT.FILL, SWT.FILL, true, true);
- treeData.horizontalSpan = 2;
- treeData.minimumHeight = 140;
- tree.setLayoutData(treeData);
-
- TableLayout layout = new TableLayout(true);
- tree.setLayout(layout);
-
- TreeColumn nameColumn = new TreeColumn(tree, SWT.NONE);
- nameColumn.setText("Name");
- layout.addColumnData(new ColumnWeightData(40, 400, true));
-
- TreeColumn locationColumn = new TreeColumn(tree, SWT.NONE);
- locationColumn.setText("Location");
- layout.addColumnData(new ColumnWeightData(30, 300, true));
-
- TreeColumn versionColumn = new TreeColumn(tree, SWT.NONE);
- versionColumn.setText("Version");
- layout.addColumnData(new ColumnWeightData(10, 100, true));
- }
-
- @Override
- public void setToolTipText(String text) {
- //Override to avoid displaying a tooltip on the tree. It prevents the Cells tooltips from working
- super.setLabelToolTipText(text);
- }
-
- @Override
- public void setLabelProvider(ILabelProvider labelProvider) {
- super.setLabelProvider(new ProfileColumnsLabelProvider(labelProvider));
- }
-
- protected class ProfileColumnsLabelProvider extends ColumnLabelProvider {
-
- private ILabelProvider defaultLabelProvider;
-
- public ProfileColumnsLabelProvider(ILabelProvider defaultLabelProvider) {
- this.defaultLabelProvider = defaultLabelProvider;
- }
-
- @Override
- public void update(ViewerCell cell) {
- if(cell.getColumnIndex() == 0) {
- updateName(cell);
- return;
- }
-
- Profile profile;
- EObject element = EMFHelper.getEObject(cell.getElement());
-
- if(element instanceof Profile) {
- profile = (Profile)element;
- } else {
- cell.setText("");
- return;
- }
-
- switch(cell.getColumnIndex()) {
- case 1:
- updateLocation(cell, profile);
- break;
- case 2:
- updateVersion(cell, profile);
- break;
- }
-
- }
-
- public void updateName(ViewerCell cell) {
- cell.setImage(defaultLabelProvider.getImage(cell.getElement()));
- cell.setText(defaultLabelProvider.getText(cell.getElement()));
- }
-
- public void updateLocation(ViewerCell cell, Profile profile) {
- String location = "Unknown";
- if(profile.eResource() != null) {
- URI uri = profile.eResource().getURI();
- if(uri != null) {
- location = uri.toString();
- }
- }
-
- cell.setText(location);
- }
-
- public void updateVersion(ViewerCell cell, Profile profile) {
- String versionText = "";
- Version version = Util.getProfileDefinitionVersion(profile);
- if(version != Version.emptyVersion) {
- versionText = version.toString();
- }
-
- cell.setText(versionText);
- }
- }
-
- @Override
- protected void createListControls() {
- super.createListControls();
- up.dispose();
- down.dispose();
- edit.dispose();
- up = down = edit = null;
-
- add.setToolTipText(Messages.ProfileApplicationEditor_ApplyProfile);
- addRegisteredProfile = createButton(Activator.getDefault().getImage("/icons/AddReg.gif"), Messages.ProfileApplicationEditor_ApplyRegisteredProfile); //$NON-NLS-1$
-
- reapplyProfile = createButton(org.eclipse.papyrus.infra.widgets.Activator.getDefault().getImage("/icons/refresh.gif"), "Reapply profile");
- treeViewer.addSelectionChangedListener(new ISelectionChangedListener() {
-
- public void selectionChanged(SelectionChangedEvent event) {
- updateControls();
- }
- });
- }
-
- /**
- * Applies a profile from workspace
- *
- * @see org.eclipse.papyrus.infra.widgets.editors.MultipleValueEditor#addAction()
- *
- */
- @Override
- protected void addAction() {
- //Code from org.eclipse.papyrus.uml.profile.ui.compositesformodel.AppliedProfileCompositeOnModel#applyProfileButtonPressed()
-
-
- // Create and open the dialog box
- // ResourceSelectionDialog dialog =
- // new ResourceSelectionDialog(getShell(), ResourcesPlugin.getWorkspace().getRoot(), "Apply Profiles");
-
- Map<String, String> extensionFilters = new LinkedHashMap<String, String>();
- extensionFilters.put("*.profile.uml", "UML Profiles (*.profile.uml)");
- extensionFilters.put("*.uml", "UML (*.uml)");
- extensionFilters.put("*", "All (*)");
-
- Collection<Package> packages = PackageImportSourceDialog.open(getShell(), Messages.ProfileApplicationEditor_ApplyProfilesDialogTitle, Collections.singletonList(umlPackage), extensionFilters);
-
- // If nothing is selected : abort
- if((packages == null) || packages.isEmpty()) {
- return;
- }
-
- if(packages.size() > 0) {
- ProfileTreeSelectionDialog profileDialog = new ProfileTreeSelectionDialog(getShell(), packages);
-
- if(profileDialog.open() != Window.OK) {
- return;
- }
-
- if(profileDialog.getResult().isEmpty()) {
- return;
- }
-
- Collection<ImportSpec<Profile>> profilesImportToApply = profileDialog.getResult();
-
- Collection<Profile> profilesToApply = new LinkedList<Profile>();
- for(ImportSpec<Profile> importProfile : profilesImportToApply) {
- profilesToApply.add(importProfile.getElement());
- }
-
- if(!ProfileValidationHelper.checkApplicableProfiles(getShell(), profilesToApply)) {
- return;
- }
-
- Message message = new Message(Messages.ProfileApplicationEditor_WaitMessageTitle, Messages.ProfileApplicationEditor_WaitMessage);
- message.open();
- for(Profile profile : profilesToApply) {
- modelProperty.add(profile);
- }
- message.close();
- commit();
- }
- }
-
- /**
- * Applies a profile from the registry
- */
- protected void addRegisteredAction() {
- RegisteredProfileSelectionDialog profileSelectionDialog = new RegisteredProfileSelectionDialog(getShell(), umlPackage);
- List<Profile> profilesToApply = profileSelectionDialog.run();
- for(Profile profile : profilesToApply) {
- modelProperty.add(profile);
- }
-
- commit();
- }
-
- protected void reapplyProfileAction() {
- ISelection selectedElements = treeViewer.getSelection();
-
- //Filter profiles
- List<Profile> profilesToRefresh = new LinkedList<Profile>();
- if(!selectedElements.isEmpty() && selectedElements instanceof IStructuredSelection) {
- IStructuredSelection selection = (IStructuredSelection)selectedElements;
- Iterator<?> iterator = selection.iterator();
- while(iterator.hasNext()) {
- Object element = iterator.next();
- if(element instanceof Profile) {
- profilesToRefresh.add((Profile)element);
- }
- }
- }
-
- //Check validity
- if(ProfileValidationHelper.checkApplicableProfiles(getShell(), profilesToRefresh)) {
- //If everything is fine, refresh the profiles
- for(Profile profile : profilesToRefresh) {
- modelProperty.add(profile);
- }
-
- commit();
- }
- }
-
- @Override
- public void widgetSelected(SelectionEvent e) {
- super.widgetSelected(e);
- if(e.widget == addRegisteredProfile) {
- addRegisteredAction();
- }
- if(e.widget == reapplyProfile) {
- reapplyProfileAction();
- }
- }
-
- /**
- * Sets the package on which the profiles will be applied
- *
- * @param umlPackage
- */
- public void setPackage(Package umlPackage) {
- this.umlPackage = umlPackage;
- updateControls();
- }
-
- @Override
- protected void updateControls() {
- boolean enabled = modelProperty != null && umlPackage != null;
- add.setEnabled(enabled);
- addRegisteredProfile.setEnabled(enabled);
- remove.setEnabled(enabled);
-
- // check whether the selection can be reapplied
- IStructuredSelection selection = (IStructuredSelection)treeViewer.getSelection();
- enabled = false;
- Iterator<?> iterator = selection.iterator();
- while(iterator.hasNext()) {
- Object element = iterator.next();
- if(element instanceof Profile) {
- if(ProfileUtil.isDirty(umlPackage, (Profile)element)) {
- enabled = true; //At least one dirty profile is selected
- break;
- }
- }
- }
-
- reapplyProfile.setEnabled(enabled);
- }
-}
+/***************************************************************************** + * Copyright (c) 2011, 2013 CEA LIST. + * + * 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: + * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation + * Christian W. Damus (CEA) - Refactoring package/profile import/apply UI for CDO + * + *****************************************************************************/ +package org.eclipse.papyrus.uml.properties.widgets; + +import java.util.Collection; +import java.util.Collections; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + +import org.eclipse.emf.common.util.URI; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.util.EcoreUtil; +import org.eclipse.jface.viewers.ColumnLabelProvider; +import org.eclipse.jface.viewers.ColumnWeightData; +import org.eclipse.jface.viewers.ILabelProvider; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.SelectionChangedEvent; +import org.eclipse.jface.viewers.TableLayout; +import org.eclipse.jface.viewers.ViewerCell; +import org.eclipse.jface.window.Window; +import org.eclipse.papyrus.infra.emf.utils.EMFHelper; +import org.eclipse.papyrus.infra.widgets.editors.MultipleReferenceEditor; +import org.eclipse.papyrus.uml.profile.definition.Version; +import org.eclipse.papyrus.uml.profile.ui.dialogs.ElementImportTreeSelectionDialog.ImportSpec; +import org.eclipse.papyrus.uml.profile.ui.dialogs.ProfileTreeSelectionDialog; +import org.eclipse.papyrus.uml.profile.utils.Util; +import org.eclipse.papyrus.uml.profile.validation.ProfileValidationHelper; +import org.eclipse.papyrus.uml.properties.Activator; +import org.eclipse.papyrus.uml.properties.messages.Messages; +import org.eclipse.papyrus.uml.properties.profile.ui.dialogs.Message; +import org.eclipse.papyrus.uml.properties.profile.ui.dialogs.RegisteredProfileSelectionDialog; +import org.eclipse.papyrus.uml.tools.importsources.PackageImportSourceDialog; +import org.eclipse.papyrus.uml.tools.utils.ProfileUtil; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.TreeColumn; +import org.eclipse.uml2.uml.Package; +import org.eclipse.uml2.uml.Profile; + +/** + * An editor for Profile application + * + * @author Camille Letavernier + */ +public class ProfileApplicationEditor extends MultipleReferenceEditor { + + /** + * The button to add profiles from the list of registered ones + */ + protected Button addRegisteredProfile; + + /** + * The button to reapply a profile + */ + protected Button reapplyProfile; + + /** + * The umlPackage being edited + */ + protected Package umlPackage; + + /** + * + * Constructor. + * + * @param parent + * @param style + */ + public ProfileApplicationEditor(Composite parent, int style) { + super(parent, style); + + tree.setHeaderVisible(true); + GridData treeData = new GridData(SWT.FILL, SWT.FILL, true, true); + treeData.horizontalSpan = 2; + treeData.minimumHeight = 140; + tree.setLayoutData(treeData); + + TableLayout layout = new TableLayout(true); + tree.setLayout(layout); + + TreeColumn nameColumn = new TreeColumn(tree, SWT.NONE); + nameColumn.setText("Name"); + layout.addColumnData(new ColumnWeightData(40, 400, true)); + + TreeColumn locationColumn = new TreeColumn(tree, SWT.NONE); + locationColumn.setText("Location"); + layout.addColumnData(new ColumnWeightData(30, 300, true)); + + TreeColumn versionColumn = new TreeColumn(tree, SWT.NONE); + versionColumn.setText("Version"); + layout.addColumnData(new ColumnWeightData(10, 100, true)); + } + + @Override + public void setToolTipText(String text) { + //Override to avoid displaying a tooltip on the tree. It prevents the Cells tooltips from working + super.setLabelToolTipText(text); + } + + @Override + public void setLabelProvider(ILabelProvider labelProvider) { + super.setLabelProvider(new ProfileColumnsLabelProvider(labelProvider)); + } + + protected class ProfileColumnsLabelProvider extends ColumnLabelProvider { + + private ILabelProvider defaultLabelProvider; + + public ProfileColumnsLabelProvider(ILabelProvider defaultLabelProvider) { + this.defaultLabelProvider = defaultLabelProvider; + } + + @Override + public void update(ViewerCell cell) { + if(cell.getColumnIndex() == 0) { + updateName(cell); + return; + } + + Profile profile; + EObject element = EMFHelper.getEObject(cell.getElement()); + + if(element instanceof Profile) { + profile = (Profile)element; + } else { + cell.setText(""); + return; + } + + switch(cell.getColumnIndex()) { + case 1: + updateLocation(cell, profile); + break; + case 2: + updateVersion(cell, profile); + break; + } + + } + + public void updateName(ViewerCell cell) { + cell.setImage(defaultLabelProvider.getImage(cell.getElement())); + cell.setText(defaultLabelProvider.getText(cell.getElement())); + } + + public void updateLocation(ViewerCell cell, Profile profile) { + String location = "Unknown"; + if(profile.eIsProxy()) { + location = EcoreUtil.getURI(profile).trimFragment().toString(); + } else if(profile.eResource() != null) { + URI uri = profile.eResource().getURI(); + if(uri != null) { + location = uri.toString(); + } + } + + cell.setText(location); + } + + public void updateVersion(ViewerCell cell, Profile profile) { + String versionText = ""; + Version version = Util.getProfileDefinitionVersion(profile); + if(version != Version.emptyVersion) { + versionText = version.toString(); + } + + cell.setText(versionText); + } + } + + @Override + protected void createListControls() { + super.createListControls(); + up.dispose(); + down.dispose(); + edit.dispose(); + up = down = edit = null; + + add.setToolTipText(Messages.ProfileApplicationEditor_ApplyProfile); + addRegisteredProfile = createButton(Activator.getDefault().getImage("/icons/AddReg.gif"), Messages.ProfileApplicationEditor_ApplyRegisteredProfile); //$NON-NLS-1$ + + reapplyProfile = createButton(org.eclipse.papyrus.infra.widgets.Activator.getDefault().getImage("/icons/refresh.gif"), "Reapply profile"); + treeViewer.addSelectionChangedListener(new ISelectionChangedListener() { + + public void selectionChanged(SelectionChangedEvent event) { + updateControls(); + } + }); + } + + /** + * Applies a profile from workspace + * + * @see org.eclipse.papyrus.infra.widgets.editors.MultipleValueEditor#addAction() + * + */ + @Override + protected void addAction() { + //Code from org.eclipse.papyrus.uml.profile.ui.compositesformodel.AppliedProfileCompositeOnModel#applyProfileButtonPressed() + + + // Create and open the dialog box + // ResourceSelectionDialog dialog = + // new ResourceSelectionDialog(getShell(), ResourcesPlugin.getWorkspace().getRoot(), "Apply Profiles"); + + Map<String, String> extensionFilters = new LinkedHashMap<String, String>(); + extensionFilters.put("*.profile.uml", "UML Profiles (*.profile.uml)"); + extensionFilters.put("*.uml", "UML (*.uml)"); + extensionFilters.put("*", "All (*)"); + + Collection<Package> packages = PackageImportSourceDialog.open(getShell(), Messages.ProfileApplicationEditor_ApplyProfilesDialogTitle, Collections.singletonList(umlPackage), extensionFilters); + + // If nothing is selected : abort + if((packages == null) || packages.isEmpty()) { + return; + } + + if(packages.size() > 0) { + ProfileTreeSelectionDialog profileDialog = new ProfileTreeSelectionDialog(getShell(), packages); + + if(profileDialog.open() != Window.OK) { + return; + } + + if(profileDialog.getResult().isEmpty()) { + return; + } + + Collection<ImportSpec<Profile>> profilesImportToApply = profileDialog.getResult(); + + Collection<Profile> profilesToApply = new LinkedList<Profile>(); + for(ImportSpec<Profile> importProfile : profilesImportToApply) { + profilesToApply.add(importProfile.getElement()); + } + + if(!ProfileValidationHelper.checkApplicableProfiles(getShell(), profilesToApply)) { + return; + } + + Message message = new Message(Messages.ProfileApplicationEditor_WaitMessageTitle, Messages.ProfileApplicationEditor_WaitMessage); + message.open(); + for(Profile profile : profilesToApply) { + modelProperty.add(profile); + } + message.close(); + commit(); + } + } + + /** + * Applies a profile from the registry + */ + protected void addRegisteredAction() { + RegisteredProfileSelectionDialog profileSelectionDialog = new RegisteredProfileSelectionDialog(getShell(), umlPackage); + List<Profile> profilesToApply = profileSelectionDialog.run(); + for(Profile profile : profilesToApply) { + modelProperty.add(profile); + } + + commit(); + } + + protected void reapplyProfileAction() { + ISelection selectedElements = treeViewer.getSelection(); + + //Filter profiles + List<Profile> profilesToRefresh = new LinkedList<Profile>(); + if(!selectedElements.isEmpty() && selectedElements instanceof IStructuredSelection) { + IStructuredSelection selection = (IStructuredSelection)selectedElements; + Iterator<?> iterator = selection.iterator(); + while(iterator.hasNext()) { + Object element = iterator.next(); + if(element instanceof Profile) { + profilesToRefresh.add((Profile)element); + } + } + } + + //Check validity + if(ProfileValidationHelper.checkApplicableProfiles(getShell(), profilesToRefresh)) { + //If everything is fine, refresh the profiles + for(Profile profile : profilesToRefresh) { + modelProperty.add(profile); + } + + commit(); + } + } + + @Override + public void widgetSelected(SelectionEvent e) { + super.widgetSelected(e); + if(e.widget == addRegisteredProfile) { + addRegisteredAction(); + } + if(e.widget == reapplyProfile) { + reapplyProfileAction(); + } + } + + /** + * Sets the package on which the profiles will be applied + * + * @param umlPackage + */ + public void setPackage(Package umlPackage) { + this.umlPackage = umlPackage; + updateControls(); + } + + @Override + protected void updateControls() { + boolean enabled = modelProperty != null && umlPackage != null; + add.setEnabled(enabled); + addRegisteredProfile.setEnabled(enabled); + remove.setEnabled(enabled); + + // check whether the selection can be reapplied + IStructuredSelection selection = (IStructuredSelection)treeViewer.getSelection(); + enabled = false; + Iterator<?> iterator = selection.iterator(); + while(iterator.hasNext()) { + Object element = iterator.next(); + if(element instanceof Profile) { + if(ProfileUtil.isDirty(umlPackage, (Profile)element)) { + enabled = true; //At least one dirty profile is selected + break; + } + } + } + + reapplyProfile.setEnabled(enabled); + } +}
\ No newline at end of file |