|
Re: Disable move/resize notes (text) in diagram [message #1772961 is a reply to message #1772949] |
Tue, 19 September 2017 14:11 |
Pierre Guilet 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 |
Martin Jedlicka Messages: 122 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 #1773034 is a reply to message #1772997] |
Wed, 20 September 2017 14:10 |
Pierre Guilet 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
|
|
|
Powered by
FUDForum. Page generated in 0.03152 seconds