/** * Adds a given tool to this controller. * <p> * This method is called by the dependency manager. * </p> * * @param aTool * the tool to add, cannot be <code>null</code>. */ public void addTool( final Tool<?> aTool ) { if ( this.tools.putIfAbsent( aTool.getName(), aTool ) == null ) { this.actionManager.add( new RunToolAction( this, aTool.getName(), aTool.getCategory() ) ); } }
/** * Returns the action identifier for the given tool. * * @param aTool * a tool instance, cannot be <code>null</code>. * @return a tool action identifier, never <code>null</code>. */ public static final String getID( final Tool<?> aTool ) { if ( aTool == null ) { throw new IllegalArgumentException( "Tool cannot be null!" ); } return getID( aTool.getName() ); }
/** * Runs the tool denoted by the given name. * * @param aToolName * the name of the tool to run, cannot be <code>null</code>; * @param aParent * the parent window to use, can be <code>null</code>. */ public void invokeTool( final String aToolName, final Window aParent ) { if ( LOG.isLoggable( Level.INFO ) ) { LOG.log( Level.INFO, "Running tool: \"{0}\" ...", aToolName ); } final Tool<?> tool = getTool( aToolName ); if ( tool == null ) { JOptionPane.showMessageDialog( aParent, "No such tool found: " + aToolName, "Error ...", JOptionPane.ERROR_MESSAGE ); } else { final ToolContext context = createToolContext(); tool.invoke( aParent, context ); } updateActionsOnEDT(); }
/** * {@inheritDoc} */ @Override public final boolean invokeTool() throws IllegalStateException { if ( this.toolFutureTask != null ) { throw new IllegalStateException( "Tool is already running!" ); } boolean settingsValid = validateToolSettings(); if ( settingsValid ) { this.toolTask = this.tool.createToolTask( this.context, this.toolProgressListener, this.annotationListener ); prepareToolTask( this.toolTask ); this.toolFutureTask = this.taskExecutionService.execute( this.toolTask ); } return settingsValid; }
/** * Removes a given tool from this controller. * <p> * This method is called by the dependency manager. * </p> * * @param aTool * the tool to remove, cannot be <code>null</code>. */ public void removeTool( final Tool<?> aTool ) { synchronized ( this.tools ) { final String toolName = aTool.getName(); this.tools.remove( toolName ); try { IManagedAction action = this.actionManager.getAction( RunToolAction.getID( toolName ) ); this.actionManager.remove( action ); } catch ( IllegalArgumentException exception ) { LOG.log( Level.FINE, "No action for tool {}?!", toolName ); } } }
/** * Creates a new {@link BaseToolDialog} instance that is document modal. * * @param aOwner * the owning window of this dialog; * @param aTitle * the title of this dialog; * @param aContext * the tool context to use in this dialog. */ protected BaseToolDialog( final Window aOwner, final ToolContext aContext, final BundleContext aBundleContext, final Tool<RESULT_TYPE> aTool ) { super( aTool.getName() ); this.context = aContext; this.bundleContext = aBundleContext; this.tool = aTool; setModalExclusionType( ModalExclusionType.NO_EXCLUDE ); this.taskExecutionService = new TaskExecutionServiceTracker( aBundleContext ); this.annotationListener = new AnnotationListenerServiceTracker( aBundleContext ); this.toolProgressListener = new ToolProgressListenerServiceTracker( aBundleContext ); }