[SOLVED] How to direct edit BeginLabel/CenterLabel/EndLabel of an Edge? [message #1727666] |
Thu, 24 March 2016 17:59  |
Eclipse User |
|
|
|
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   |
Eclipse User |
|
|
|
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 #1728819 is a reply to message #1728401] |
Thu, 07 April 2016 11:35   |
Eclipse User |
|
|
|
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
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.10301 seconds