Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Sirius » Disable move/resize notes (text) in diagram
Disable move/resize notes (text) in diagram [message #1772949] Tue, 19 September 2017 10:43 Go to next message
Martin Jedlicka is currently offline Martin JedlickaFriend
Messages: 121
Registered: January 2016
Senior Member
Hi,

How do I disable move/resize a specific notes inserted from the palette?
I create a note on the diagram programmatically, you do not want to allow the user to move/resize.

I have already disabled delete (see the code below) but I do not know how to disable move/resize.

Thanks.

Martin

Extension in plugin.xml
 <extension
       point="org.eclipse.gmf.runtime.diagram.ui.editpolicyProviders">
    <editpolicyProvider
          class="com.ge.eufo.processDesigner.design.providers.NonDeleteNotePolicyProvider">
       <Priority
             name="High">
       </Priority>
    </editpolicyProvider>
 </extension>


NonDeleteNotePolicyProvider.java
public class NonDeleteNotePolicyProvider implements IEditPolicyProvider {

	@Override
	public void addProviderChangeListener(IProviderChangeListener arg0) {
	}

	@Override
	public boolean provides(IOperation operation) {
		if (operation instanceof CreateEditPoliciesOperation) {
			// code return true
		}
		return false;
	}

	@Override
	public void removeProviderChangeListener(IProviderChangeListener arg0) {
	}

	@Override
	public void createEditPolicies(EditPart editPart) {
		if (editPart instanceof SiriusTextEditPart) {
			editPart.installEditPolicy(EditPolicy.COMPONENT_ROLE, new NonDeleteEditPolicy());
		}
	}

	private class NonDeleteEditPolicy extends SemanticEditPolicy {
		@Override
		protected Command getSemanticCommand(IEditCommandRequest editRequest) {

			if (editRequest instanceof DestroyElementRequest) {
				if (getHost() instanceof GraphicalEditPart) {
					return new ICommandProxy(new DeleteCommand(editRequest.getEditingDomain(), ((GraphicalEditPart) getHost()).getPrimaryView()));
				}
			}
			return super.getSemanticCommand(editRequest);
		}
	}
}


Re: Disable move/resize notes (text) in diagram [message #1772961 is a reply to message #1772949] Tue, 19 September 2017 14:11 Go to previous messageGo to next message
Pierre Guilet is currently offline Pierre GuiletFriend
Messages: 250
Registered: June 2017
Senior Member
Hi Martin,

Your policy must provide an UnexecutableCommand for requests corresponding to removal, and resize/move. This command has priority over others that may be provided by other policies.
A working code below:
import org.eclipse.gef.EditPart;
import org.eclipse.gef.Request;
import org.eclipse.gef.commands.Command;
import org.eclipse.gef.commands.UnexecutableCommand;
import org.eclipse.gef.editpolicies.AbstractEditPolicy;
import org.eclipse.gef.requests.ChangeBoundsRequest;
import org.eclipse.gmf.runtime.common.core.service.IOperation;
import org.eclipse.gmf.runtime.common.core.service.IProviderChangeListener;
import org.eclipse.gmf.runtime.diagram.ui.requests.GroupRequestViaKeyboard;
import org.eclipse.gmf.runtime.diagram.ui.services.editpolicy.CreateEditPoliciesOperation;
import org.eclipse.gmf.runtime.diagram.ui.services.editpolicy.IEditPolicyProvider;
import org.eclipse.sirius.diagram.ui.internal.edit.parts.SiriusNoteEditPart;

public class NonDeleteNotePolicyProvider implements IEditPolicyProvider {

    @Override
    public void addProviderChangeListener(IProviderChangeListener arg0) {
    }

    @Override
    public boolean provides(IOperation operation) {
        if (operation instanceof CreateEditPoliciesOperation) {
            EditPart editPart = ((CreateEditPoliciesOperation) operation).getEditPart();
            if (editPart instanceof SiriusNoteEditPart) {
                return true;
            }
        }
        return false;
    }

    @Override
    public void removeProviderChangeListener(IProviderChangeListener arg0) {
    }

    @Override
    public void createEditPolicies(EditPart editPart) {
        editPart.installEditPolicy("NotePolicy", new NoteEditPolicy()); //$NON-NLS-1$
    }

    private class NoteEditPolicy extends AbstractEditPolicy {

        @Override
        public boolean understandsRequest(Request request) {
            return request instanceof ChangeBoundsRequest || request instanceof GroupRequest;
        }

        /*
         * (non-Javadoc)
         * @see org.eclipse.gef.editpolicies.AbstractEditPolicy#getCommand(org.
         * eclipse.gef.Request)
         */
        @Override
        public Command getCommand(Request request) {
            if (understandsRequest(request)) {
                return UnexecutableCommand.INSTANCE;
            }
            return null;
        }

        /*
         * (non-Javadoc)
         * @see
         * org.eclipse.gef.editpolicies.AbstractEditPolicy#getTargetEditPart(org
         * .eclipse.gef.Request)
         */
        @Override
        public EditPart getTargetEditPart(Request request) {
            return getHost();
        }
    }
}


Regards,


Pierre Guilet - Obeo
Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius

[Updated on: Tue, 19 September 2017 14:14]

Report message to a moderator

Re: Disable move/resize notes (text) in diagram [message #1772997 is a reply to message #1772961] Wed, 20 September 2017 05:30 Go to previous messageGo to next message
Martin Jedlicka is currently offline Martin JedlickaFriend
Messages: 121
Registered: January 2016
Senior Member
Hi Pierre,

This solution works but it has one problem.

If I select all the elements in the diagram (Select All - Ctrl + A) and there are elements that can be moved on the diagram. If I want to move the whole diagram, it is not possible because the element that can not be moved is also selected.

In other words, I have a note in the diagram that can not be edited (but must be visible) - move, resize, delete, etc. But when all the elements in the diagram (Ctrl + A) are selected so as not to affect the behavior of the diagram (other elements can be deleted/moved).

Perhaps the best solution would be if this element (note) could not be selected at all or custom action for Select All? Is that possible?

Thanks.

Martin

[Updated on: Wed, 20 September 2017 07:22]

Report message to a moderator

Re: Disable move/resize notes (text) in diagram [message #1773032 is a reply to message #1772997] Wed, 20 September 2017 12:33 Go to previous messageGo to next message
Martin Jedlicka is currently offline Martin JedlickaFriend
Messages: 121
Registered: January 2016
Senior Member
So I've already solved it.

I implemented a custom action SelectAll that does not select a element (note).

Thanks.
Re: Disable move/resize notes (text) in diagram [message #1773034 is a reply to message #1772997] Wed, 20 September 2017 14:10 Go to previous message
Pierre Guilet is currently offline Pierre GuiletFriend
Messages: 250
Registered: June 2017
Senior Member
I think it should be possible.

Thought you have more things to do than override CTRL+A selectAll behavior.
You have three ways to select all elements:
* by using the keyboard control
* by using the action in the tabbar
* by using the action with pop up menu on diagram

All the above must be overridden so you can have a coherent select all behavior.

This action is a GMF action. So you should find help in the GMF documentation.

To update the popup menu action you have to define your own contribution provider similar to org.eclipse.gmf.runtime.diagram.ui.providers.DiagramContributionItemProvider but that create a custom SelectAllAction not selecting notes.
You have example of how these kind of things are done by Sirius in org.eclipse.sirius.diagram.ui plugin.xml file and in GMF in org.eclipse.gmf.runtime.diagram.ui.providers.

Gmf extension point must be use.


You should have something like:
 <extension point="org.eclipse.gmf.runtime.common.ui.services.action.contributionItemProviders">
 <contributionItemProvider
            class="my.project.CustomDiagramContributionItemProvider"
            checkPluginLoaded="false">
         <Priority name="Lowest"/>
               	<popupContribution class="org.eclipse.gmf.runtime.diagram.ui.providers.DiagramContextMenuProvider">
            <popupStructuredContributionCriteria objectClass="org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart">
            </popupStructuredContributionCriteria>
            <popupMenu path="/filterFormatGroup" id="selectMenu">
            </popupMenu>
            <popupMenuGroup path="/selectMenu/" id="selectGroup">
            </popupMenuGroup>
            <popupAction path="/selectMenu/selectGroup" id="selectAll">
            </popupAction>
            <popupAction path="/selectMenu/selectGroup" id="selectAllConnectorsAction">
            </popupAction>
            <popupAction path="/filterFormatGroup" id="toolbarArrangeAllAction">
            </popupAction>             
        </popupContribution>   
       </contributionItemProvider>
  </extension>


For the action in tabbar you have to customize the tabbar to provide your own selectAll action by following https://www.eclipse.org/sirius/doc/developer/extensions-provide_tabbar_extensions.html

Instead of using diagramContributionItems.add(createSelectMenuManager()); you will have to provide your own SelectMenuManager providing your custom selectAll action.

Regarding the keyboard related select all action, I don't really know how to override it but the GMF documentation may provide you information about it.

Regards,

Pierre



Pierre Guilet - Obeo
Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius

[Updated on: Wed, 20 September 2017 14:42]

Report message to a moderator

Previous Topic:Acceleo 3 in Properties view
Next Topic:Displaying key-value pairs
Goto Forum:
  


Current Time: Wed Apr 01 05:49:40 GMT 2020

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

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

Back to the top