X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.diagram%2Fsrc%2Forg%2Fsimantics%2Fdiagram%2Fhandler%2FExpandSelectionHandler.java;h=2e04b05d13bc0bb3c08ca69eb194bb9492f3bc75;hp=28a5dc14f225cb21b2e582aea3afd543630d8830;hb=refs%2Fchanges%2F38%2F238%2F2;hpb=24e2b34260f219f0d1644ca7a138894980e25b14 diff --git a/bundles/org.simantics.diagram/src/org/simantics/diagram/handler/ExpandSelectionHandler.java b/bundles/org.simantics.diagram/src/org/simantics/diagram/handler/ExpandSelectionHandler.java index 28a5dc14f..2e04b05d1 100644 --- a/bundles/org.simantics.diagram/src/org/simantics/diagram/handler/ExpandSelectionHandler.java +++ b/bundles/org.simantics.diagram/src/org/simantics/diagram/handler/ExpandSelectionHandler.java @@ -1,79 +1,79 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Association for Decentralized Information Management - * in Industry THTH ry. - * 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: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -package org.simantics.diagram.handler; - -import java.util.Set; - -import org.eclipse.jface.action.IStatusLineManager; -import org.eclipse.swt.widgets.Display; -import org.simantics.g2d.canvas.impl.DependencyReflection.Dependency; -import org.simantics.g2d.diagram.participant.AbstractDiagramParticipant; -import org.simantics.g2d.diagram.participant.Selection; -import org.simantics.g2d.element.IElement; -import org.simantics.g2d.utils.TopologicalSelectionExpander; -import org.simantics.scenegraph.g2d.events.EventHandlerReflection.EventHandler; -import org.simantics.scenegraph.g2d.events.command.CommandEvent; -import org.simantics.scenegraph.g2d.events.command.Commands; - -/** - * This handler responds to the EXPAND_SELECTION command. It attempts to expand - * the current selection for pointer 0, meaning {@link Selection#SELECTION0}. - * - * @see TopologicalSelectionExpander - * @see Selection the current diagram selection source - * - * @author Tuukka Lehtonen - */ -public class ExpandSelectionHandler extends AbstractDiagramParticipant { - - private final IStatusLineManager statusLine; - - @Dependency Selection selection; - - public ExpandSelectionHandler(IStatusLineManager statusLine) { - this.statusLine = statusLine; - } - - @EventHandler(priority = 0) - public boolean handleExpand(CommandEvent event) { - if (Commands.EXPAND_SELECTION.equals( event.command )) { - return expandSelection(0); - } - return false; - } - - /** - * @param selectionId the id of the selection to expand - * @return true if the selection changed as a result of the - * expansion, false if not - */ - public boolean expandSelection(int selectionId) { - Set start = selection.getSelection(selectionId); - TopologicalSelectionExpander expander = new TopologicalSelectionExpander(diagram, start); - final Set expanded = expander.expandedIfChanged(); - if (expanded == null) - return false; - selection.setSelection(selectionId, expanded); - if(statusLine != null) { - Display.getDefault().asyncExec(new Runnable() { - - @Override - public void run() { - statusLine.setMessage("Expanded selection to include " + expanded.size() + " (from " + diagram.getElements().size() + ") items."); - } - - }); - } - return true; - } - -} +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * 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: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.diagram.handler; + +import java.util.Set; + +import org.eclipse.jface.action.IStatusLineManager; +import org.eclipse.swt.widgets.Display; +import org.simantics.g2d.canvas.impl.DependencyReflection.Dependency; +import org.simantics.g2d.diagram.participant.AbstractDiagramParticipant; +import org.simantics.g2d.diagram.participant.Selection; +import org.simantics.g2d.element.IElement; +import org.simantics.g2d.utils.TopologicalSelectionExpander; +import org.simantics.scenegraph.g2d.events.EventHandlerReflection.EventHandler; +import org.simantics.scenegraph.g2d.events.command.CommandEvent; +import org.simantics.scenegraph.g2d.events.command.Commands; + +/** + * This handler responds to the EXPAND_SELECTION command. It attempts to expand + * the current selection for pointer 0, meaning {@link Selection#SELECTION0}. + * + * @see TopologicalSelectionExpander + * @see Selection the current diagram selection source + * + * @author Tuukka Lehtonen + */ +public class ExpandSelectionHandler extends AbstractDiagramParticipant { + + private final IStatusLineManager statusLine; + + @Dependency Selection selection; + + public ExpandSelectionHandler(IStatusLineManager statusLine) { + this.statusLine = statusLine; + } + + @EventHandler(priority = 0) + public boolean handleExpand(CommandEvent event) { + if (Commands.EXPAND_SELECTION.equals( event.command )) { + return expandSelection(0); + } + return false; + } + + /** + * @param selectionId the id of the selection to expand + * @return true if the selection changed as a result of the + * expansion, false if not + */ + public boolean expandSelection(int selectionId) { + Set start = selection.getSelection(selectionId); + TopologicalSelectionExpander expander = new TopologicalSelectionExpander(diagram, start); + final Set expanded = expander.expandedIfChanged(); + if (expanded == null) + return false; + selection.setSelection(selectionId, expanded); + if(statusLine != null) { + Display.getDefault().asyncExec(new Runnable() { + + @Override + public void run() { + statusLine.setMessage("Expanded selection to include " + expanded.size() + " (from " + diagram.getElements().size() + ") items."); + } + + }); + } + return true; + } + +}