Skip to main content



      Home
Home » Eclipse Projects » Sirius » [SOLVED] How to direct edit BeginLabel/CenterLabel/EndLabel of an Edge?
[SOLVED] How to direct edit BeginLabel/CenterLabel/EndLabel of an Edge? [message #1727666] Thu, 24 March 2016 17:59 Go to next message
Eclipse UserFriend
Hi,

Currently, if the user selects the begin/center/end label of an edge, they can't edit it directly. Consider the user just needs to change the multiplicity of the roles on an association, they can't !

Is there any way to capture double click or edit of the begin/center/end labels ? I think this would be very useful if we could have it.

Thanks,
Parsa

[Updated on: Thu, 07 April 2016 11:36] by Moderator

Re: How to direct edit BeginLabel/CenterLabel/EndLabel of an Edge? [message #1728401 is a reply to message #1727666] Mon, 04 April 2016 04:27 Go to previous messageGo to next message
Eclipse UserFriend
Le 24/03/2016 22:59, Parsa Pourali a écrit :
> Hi,

Hi.

> Currently, if the user selects the begin/center/end label of an edge,
> they can't edit it directly. Consider the user just needs to change the
> multiplicity of the roles on an association, they can't !
>
> Is there any way to capture double click or edit of the begin/center/end
> labels ? I think this would be very useful if we could have it.

This is a known limitation, but fixing it is actually a more involved
that it looks, so it is not planned for now.

In the meantime you can use the same technique as used by UML Designer,
which provides its own custom edit parts for these labels, with an
additional edit policy. See http://bit.ly/224QGrZ.

Regards,

--
Pierre-Charles David - Obeo

Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius
Re: How to direct edit BeginLabel/CenterLabel/EndLabel of an Edge? [message #1728617 is a reply to message #1728401] Tue, 05 April 2016 17:54 Go to previous messageGo to next message
Eclipse UserFriend
Hi Pierre,

Thanks for your reply,

I added the UMLEditPartProvider class to my project and added an extension of org.eclipse.gmf.runtime.diagram.ui.editpartProviders. I can't get any results, I'm sure there are more steps to take. I'd appreciate it if you could share any ideas with me, if you have any ?

Thanks,
Bests,
Parsa
Re: How to direct edit BeginLabel/CenterLabel/EndLabel of an Edge? [message #1728819 is a reply to message #1728401] Thu, 07 April 2016 11:35 Go to previous messageGo to next message
Eclipse UserFriend
Thanks Pierre, I could make it work, So, I write the steps I took if anybody else has the same problem as me !

1- Add the following lines to your plugin Activator class:
    private ICommonLabelProvider labelProvider = null;
   
    /**
	 * Returns the label provider to use for displaying locked elements.
	 *
	 * @return the label provider to use for displaying locked elements.
	 */
	public ICommonLabelProvider getLabelProvider() {
		if (labelProvider == null) {
			labelProvider = new SiriusCommonLabelProvider();
		}
		return labelProvider;
	}


2- setup an extension for org.eclipse.gmf.runtime.diagram.ui.editpartProviders which points to the UMLEditPartProvider class.

3- Add the following code in the body of your UMLEditPartProvider class. Note that this class should be adopted it to your needs:
/*******************************************************************************
 * Copyright (c) 2014 Obeo.
 * 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:
 *     Obeo - initial API and implementation
 *******************************************************************************/
package externalJavaActionCalls.com.uwaterloo.cs.forml.odesign;

import javax.swing.JOptionPane;

import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.transaction.RecordingCommand;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.emf.transaction.util.TransactionUtil;
import org.eclipse.gmf.runtime.common.core.service.IOperation;
import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy;
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy;
import org.eclipse.gmf.runtime.diagram.ui.services.editpart.AbstractEditPartProvider;
import org.eclipse.gmf.runtime.diagram.ui.services.editpart.CreateGraphicEditPartOperation;
import org.eclipse.gmf.runtime.diagram.ui.services.editpart.IEditPartOperation;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.sirius.diagram.ui.internal.edit.parts.DEdgeBeginNameEditPart;
import org.eclipse.sirius.diagram.ui.internal.edit.parts.DEdgeEndNameEditPart;
import org.eclipse.sirius.diagram.ui.internal.edit.parts.DEdgeNameEditPart;
import org.eclipse.sirius.diagram.ui.part.SiriusVisualIDRegistry;
import org.eclipse.sirius.diagram.ui.tools.api.command.GMFCommandWrapper;
import org.eclipse.sirius.viewpoint.DSemanticDecorator;

//import org.obeonetwork.dsl.uml2.design.internal.services.AssociationServices;
//import org.obeonetwork.dsl.uml2.design.internal.services.EditLabelSwitch;

import services.externalJavaActionCalls.com.uwaterloo.cs.forml.odesign.AssociationServices;
import services.externalJavaActionCalls.com.uwaterloo.cs.forml.odesign.EditLabelSwitch;
import uw.cs.watform.forml.forml.Association;
import uw.cs.watform.forml.forml.Composition;
import uw.cs.watform.forml.forml.Decl;
import uw.cs.watform.forml.forml.Role;
import uw.cs.watform.forml.forml.Roleable;


@SuppressWarnings("restriction")
public class UMLEditPartProvider extends AbstractEditPartProvider {

	class UMLDirectEditForBeginRole extends LabelDirectEditPolicy {

		@Override
		protected org.eclipse.gef.commands.Command getDirectEditCommand(
				org.eclipse.gef.requests.DirectEditRequest edit) {
			final EObject element = ((org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart)getHost())
					.resolveSemanticElement();
			final TransactionalEditingDomain domain = TransactionUtil.getEditingDomain(element);
			final String labelText = (String)edit.getCellEditor().getValue();
			final RecordingCommand cmd = new RecordingCommand(domain) {

				@Override
				protected void doExecute() {
					if (element instanceof DSemanticDecorator) {
						final EObject target = ((DSemanticDecorator)element).getTarget();
						if (target instanceof Composition) {
							final Decl end = ((Composition)target).getWhole();//AssociationServices.INSTANCE.getSource((Composition)target);
							if (end != null) {
								final EditLabelSwitch swch = new EditLabelSwitch();
								swch.setEditedLabelContent(labelText);
								swch.caseRole(end);
							}
						}

					}
				}
			};
			return new ICommandProxy(new GMFCommandWrapper(domain, cmd));

		}

	}

	class UMLDirectEditForEndRole extends LabelDirectEditPolicy {

		@Override
		protected org.eclipse.gef.commands.Command getDirectEditCommand(
				org.eclipse.gef.requests.DirectEditRequest edit) {
			final EObject element = ((org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart)getHost())
					.resolveSemanticElement();
			final TransactionalEditingDomain domain = TransactionUtil.getEditingDomain(element);
			final String labelText = (String)edit.getCellEditor().getValue();
			final RecordingCommand cmd = new RecordingCommand(domain) {

				@Override
				protected void doExecute() {
					if (element instanceof DSemanticDecorator) {
						final EObject target = ((DSemanticDecorator)element).getTarget();

						if (target instanceof Role) {
							final Roleable end = AssociationServices.INSTANCE.getTarget((Role)target);
							if (end != null) {
								final EditLabelSwitch swch = new EditLabelSwitch();
								swch.setEditedLabelContent(labelText);
								//swch.caseRole(end);
							}
						}

					}
				}
			};
			return new ICommandProxy(new GMFCommandWrapper(domain, cmd));

		}

	}

	class UMLDirectEditForLabel extends LabelDirectEditPolicy {

		@Override
		protected org.eclipse.gef.commands.Command getDirectEditCommand(
				org.eclipse.gef.requests.DirectEditRequest edit) {
			final EObject element = ((org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart)getHost())
					.resolveSemanticElement();
			final TransactionalEditingDomain domain = TransactionUtil.getEditingDomain(element);
			final String labelText = (String)edit.getCellEditor().getValue();
			final RecordingCommand cmd = new RecordingCommand(domain) {

				@Override
				protected void doExecute() {
					if (element instanceof DSemanticDecorator) {
						final EObject target = ((DSemanticDecorator)element).getTarget();
						if (target instanceof Association) {
							((Association)target).setName(labelText);
						}
					}
				}
			};
			return new ICommandProxy(new GMFCommandWrapper(domain, cmd));

		}
	}

	/**
	 * @generated
	 */
	@Override
	public synchronized IGraphicalEditPart createGraphicEditPart(View view) {
		switch (SiriusVisualIDRegistry.getVisualID(view)) {

			case DEdgeBeginNameEditPart.VISUAL_ID:
				final DEdgeBeginNameEditPart dEdgeBeginPart = new DEdgeBeginNameEditPart(view) {

					@Override
					protected boolean isDirectEditEnabled() {
						return true;
					}

				};
				dEdgeBeginPart.installEditPolicy(org.eclipse.gef.RequestConstants.REQ_DIRECT_EDIT,
						new UMLDirectEditForBeginRole());
				return dEdgeBeginPart;

			case DEdgeEndNameEditPart.VISUAL_ID:
				final DEdgeEndNameEditPart dEdgeEndPart = new DEdgeEndNameEditPart(view) {
					@Override
					protected boolean isDirectEditEnabled() {
						return true;
					}

				};
				dEdgeEndPart.installEditPolicy(org.eclipse.gef.RequestConstants.REQ_DIRECT_EDIT,
						new UMLDirectEditForEndRole());
				return dEdgeEndPart;

			case DEdgeNameEditPart.VISUAL_ID:
				final DEdgeNameEditPart dEdgePart = new DEdgeNameEditPart(view) {
					@Override
					protected boolean isDirectEditEnabled() {
						return true;
					}

				};
				dEdgePart.installEditPolicy(org.eclipse.gef.RequestConstants.REQ_DIRECT_EDIT,
						new UMLDirectEditForLabel());
				return dEdgePart;
			default:
				break;
		}
		return null;
	}

	@Override
	public boolean provides(IOperation operation) {
		if (operation instanceof CreateGraphicEditPartOperation) {
			final View view = ((IEditPartOperation)operation).getView();
			if (view.getElement() instanceof DSemanticDecorator) {
				if (((DSemanticDecorator)view.getElement()).getTarget() instanceof EObject) {
					switch (SiriusVisualIDRegistry.getVisualID(view)) {

						case DEdgeBeginNameEditPart.VISUAL_ID:
							return true;

						case DEdgeEndNameEditPart.VISUAL_ID:
							return true;

						case DEdgeNameEditPart.VISUAL_ID:
							return true;
						default:
							break;
					}
				}
			}

		}
		return false;
	}

}


4- Add an editlabel in the .odesign description for the association/composition/aggregation or whatever edge you have !

5 - make a dummy java service method and set the edit label run the java service. (Simply in your editlabel add a "Change Context" element and run the service). Also don't forget to map the editlabel to your association edge.

6- Run/Debug !

Cheers,
Parsa
Re: How to direct edit BeginLabel/CenterLabel/EndLabel of an Edge? [message #1729349 is a reply to message #1728819] Wed, 13 April 2016 05:46 Go to previous messageGo to next message
Eclipse UserFriend
Hi Parsa Pourali,
I'm also getting problem in terms of label editing. Could you please send me snapshots to do so .. because currently I'm new to serius .
any help will be appreciated.
Re: How to direct edit BeginLabel/CenterLabel/EndLabel of an Edge? [message #1729506 is a reply to message #1729349] Thu, 14 April 2016 16:03 Go to previous message
Eclipse UserFriend
Hi Rahul,

Which parts exactly you have difficulties ? It will be multiple snapshots, which part you can't find?

Regards,
Parsa
Previous Topic:No connection handles visible
Next Topic:[SOLVED] Best way to apply/assign elements to others
Goto Forum:
  


Current Time: Sun Mar 23 05:09:34 EDT 2025

Powered by FUDForum. Page generated in 0.10301 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top