Check out our new monthly subscription model! Only $9.99 a month!
Hi, Could you give me an example how to use the method addSelectionListener? I want to run a method every time I click on an element in Astah.
Thanks in advance
Product: Astah Professional
Hi Ano,
Thanks for your post. Here's a sample code:
package com.example;
import javax.swing.JOptionPane;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import com.change_vision.jude.api.inf.AstahAPI;
import com.change_vision.jude.api.inf.exception.InvalidUsingException;
import com.change_vision.jude.api.inf.project.ProjectAccessor;
import com.change_vision.jude.api.inf.view.IDiagramViewManager;
import com.change_vision.jude.api.inf.view.IEntitySelectionEvent;
import com.change_vision.jude.api.inf.view.IEntitySelectionListener;
public class Activator implements BundleActivator {
MySelectionListener selectionListener = new MySelectionListener(); public void start(BundleContext context) { try { getDiagramViewManager().addEntitySelectionListener(selectionListener); } catch (Exception e) { e.printStackTrace(); } } public void stop(BundleContext context) { try { getDiagramViewManager().removeEntitySelectionListener(selectionListener); } catch (Exception e) { e.printStackTrace(); } } private IDiagramViewManager getDiagramViewManager() throws ClassNotFoundException, InvalidUsingException { AstahAPI api = AstahAPI.getAstahAPI(); ProjectAccessor projectAccessor = api.getProjectAccessor(); IDiagramViewManager vm = projectAccessor.getViewManager().getDiagramViewManager(); return vm; } /** * My SelectionListener. */ public class MySelectionListener implements IEntitySelectionListener { @Override public void entitySelectionChanged(IEntitySelectionEvent arg0) { // any code JOptionPane.showMessageDialog(null, "Hello Astah World", "infomation", JOptionPane.PLAIN_MESSAGE); } }
}
PS: Sorry about the space in-between import lines at the top of the sample code. I couldn't format them right in this form for some reasons..
Cheers, SJ