@Override public boolean applicable(final ServiceContext context) { ISapphirePart part = context.find(ISapphirePart.class); if (part instanceof SapphireDiagramEditorPagePart) { SapphireDiagramEditorPagePart diagramPagePart = (SapphireDiagramEditorPagePart) part; DiagramEditorPageDef pageDef = diagramPagePart.getPageDef(); if (pageDef.getLayoutPersistence().content() == LayoutPersistence.SIDE_BY_SIDE) { return true; } } return false; }
@Override protected Object run(final Presentation context) { final SapphireDiagramEditorPagePart page = (SapphireDiagramEditorPagePart) getPart(); for (ISapphirePart selectedPart : page.getSelections()) { if (selectedPart instanceof DiagramConnectionPart) { ((DiagramConnectionPart) selectedPart).removeAllBendpoints(); } } return null; }
@Override public boolean isEnabled() { final SapphireDiagramEditorPagePart page = (SapphireDiagramEditorPagePart) getPart(); for (ISapphirePart selectedPart : page.getSelections()) { if (selectedPart instanceof DiagramConnectionPart) { if (!((DiagramConnectionPart) selectedPart).getBendpoints().isEmpty()) { return true; } } } return false; }
private void refreshConnectionPartsListener() { for (DiagramConnectionPart connPart : this.selectedConnectionParts) { connPart.detach(this.connectionPartListener); } SapphireDiagramEditorPagePart pagePart = (SapphireDiagramEditorPagePart) getPart(); List<DiagramConnectionPart> newSelectedParts = new ArrayList<DiagramConnectionPart>(); for (ISapphirePart part : pagePart.getSelections()) { if (part instanceof DiagramConnectionPart) { newSelectedParts.add((DiagramConnectionPart) part); ((DiagramConnectionPart) part).attach(this.connectionPartListener); } } this.selectedConnectionParts.clear(); this.selectedConnectionParts.addAll(newSelectedParts); }
@Override public void init(SapphireAction action, ActionHandlerDef def) { super.init(action, def); SapphireDiagramEditorPagePart part = (SapphireDiagramEditorPagePart) getPart(); part.attach( new Listener() { @Override public void handle(final Event e) { if (e instanceof SelectionChangedEvent) { broadcast(new EnablementChangedEvent()); refreshConnectionPartsListener(); } } }); refreshConnectionPartsListener(); }