Java Code Examples for org.eclipse.jface.action.IAction#setEnabled()

The following examples show how to use org.eclipse.jface.action.IAction#setEnabled() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RefreshAction.java    From codewind-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void selectionChanged(IAction action, ISelection selection) {
    if (!(selection instanceof IStructuredSelection)) {
        action.setEnabled(false);
        return;
    }

    IStructuredSelection sel = (IStructuredSelection) selection;
    if (sel.size() == 1) {
        Object obj = sel.getFirstElement();
        if (obj instanceof CodewindManager || obj instanceof CodewindConnection || obj instanceof CodewindApplication) {
        	codewindObject = obj;
        	action.setEnabled(true);
        	return;
        }
    }
    action.setEnabled(false);
}
 
Example 2
Source File: UpdateAction.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
public void execute(IAction action) throws InterruptedException, InvocationTargetException {
       if (action != null && !action.isEnabled()) { 
       	action.setEnabled(true);
       } 
       else {
       	IPreferenceStore store = SVNUIPlugin.getPlugin().getPreferenceStore();
        IResource[] resources = getSelectedResources(); 
        SVNConflictResolver conflictResolver = new SVNConflictResolver(resources[0], store.getInt(ISVNUIConstants.PREF_UPDATE_TO_HEAD_CONFLICT_HANDLING_TEXT_FILES), store.getInt(ISVNUIConstants.PREF_UPDATE_TO_HEAD_CONFLICT_HANDLING_BINARY_FILES), store.getInt(ISVNUIConstants.PREF_UPDATE_TO_HEAD_CONFLICT_HANDLING_PROPERTIES), store.getInt(ISVNUIConstants.PREF_UPDATE_TO_HEAD_CONFLICT_HANDLING_TREE_CONFLICTS));
       	UpdateOperation updateOperation = new UpdateOperation(getTargetPart(), resources, SVNRevision.HEAD);
    	updateOperation.setDepth(depth);
    	updateOperation.setSetDepth(setDepth);
    	updateOperation.setForce(store.getBoolean(ISVNUIConstants.PREF_UPDATE_TO_HEAD_ALLOW_UNVERSIONED_OBSTRUCTIONS));
    	updateOperation.setIgnoreExternals(store.getBoolean(ISVNUIConstants.PREF_UPDATE_TO_HEAD_IGNORE_EXTERNALS));
    	updateOperation.setCanRunAsJob(canRunAsJob);
    	updateOperation.setConflictResolver(conflictResolver);
       	updateOperation.run();
       } 		
}
 
Example 3
Source File: SearchWholeWordAction.java    From xds-ide with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void selectionChanged(IAction action, ISelection selection) {
	IWorkbenchPart activePart = WorkbenchUtils.getActivePart();
	if (activePart instanceof ITextEditor) {
		ITextEditor textEditor = (ITextEditor) activePart;
		textWidget = JavaUtils.as(StyledText.class, textEditor.getAdapter(Control.class));
		action.setEnabled(true);
	}
	else {
		action.setEnabled(false);
	}
}
 
Example 4
Source File: ProcessInitDiagramFileAction.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
/**
* @generated
*/
public void selectionChanged(IAction action, ISelection selection) {
	domainModelURI = null;
	action.setEnabled(false);
	if (selection instanceof IStructuredSelection == false || selection.isEmpty()) {
		return;
	}
	IFile file = (IFile) ((IStructuredSelection) selection).getFirstElement();
	domainModelURI = URI.createPlatformResourceURI(file.getFullPath().toString(), true);
	action.setEnabled(true);
}
 
Example 5
Source File: SpellUncheckAction.java    From texlipse with Eclipse Public License 1.0 5 votes vote down vote up
/**
    * Change the active selection.
    * @param action the action
    * @param selection the selection on the currently edited document
 */
public void selectionChanged(IAction action, ISelection selection) {
       if (selection instanceof TextSelection) {
           action.setEnabled(true);
           return;
       }
       action.setEnabled(targetEditor instanceof ITextEditor);
}
 
Example 6
Source File: UnlockAction.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
protected void execute(IAction action) throws InvocationTargetException, InterruptedException {
    if (action != null && !action.isEnabled()) { 
    	action.setEnabled(true);
    } 
    else {
    	if (getSelectedResources() != null && getSelectedResources().length > 0) {
      final IResource[] resources = getSelectedResources(); 
      run(new WorkspaceModifyOperation() {
          protected void execute(IProgressMonitor monitor) throws CoreException, InvocationTargetException, InterruptedException {
              try {
			Hashtable table = getProviderMapping(getSelectedResources());
			Set keySet = table.keySet();
			Iterator iterator = keySet.iterator();
			while (iterator.hasNext()) {
			    SVNTeamProvider provider = (SVNTeamProvider)iterator.next();
		    	UnlockResourcesCommand command = new UnlockResourcesCommand(provider.getSVNWorkspaceRoot(), resources, false);
		        command.run(Policy.subMonitorFor(monitor,1000));    					
			}
              } catch (TeamException e) {
			throw new InvocationTargetException(e);
		} finally {
			monitor.done();
		}
          }              
      }, true /* cancelable */, PROGRESS_DIALOG);        
    	}
    }
}
 
Example 7
Source File: RemoveAppLoaderAction.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void selectionChanged(IAction action, ISelection selection) {
	if (selection != null && selection instanceof IStructuredSelection) {
		this.selection = (IStructuredSelection) selection;
		if (action != null) {
			action.setEnabled(isEnabled());
		}
	}
}
 
Example 8
Source File: TexCorrectIndentationAction.java    From texlipse with Eclipse Public License 1.0 5 votes vote down vote up
public void selectionChanged(IAction action, ISelection selection) {
	if (selection instanceof ITextSelection) {
		action.setEnabled(true);
		return;
	}
	action.setEnabled( targetEditor instanceof ITextEditor);
}
 
Example 9
Source File: SimulationView.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
protected void updateActions() {
	IContributionItem[] items = getViewSite().getActionBars().getToolBarManager().getItems();
	for (IContributionItem iContributionItem : items) {
		if (iContributionItem instanceof ActionContributionItem) {
			IAction currentAction = ((ActionContributionItem) iContributionItem).getAction();
			currentAction.setEnabled(currentAction.isEnabled());
		}
	}
}
 
Example 10
Source File: TeamAction.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Method invoked from <code>selectionChanged(IAction, ISelection)</code> 
 * to set the enablement status of the action. The instance variable 
 * <code>selection</code> will contain the latest selection so the methods
 * <code>getSelectedResources()</code> and <code>getSelectedProjects()</code>
 * will provide the proper objects.
 * 
 * This method can be overridden by subclasses but should not be invoked by them.
 */
protected void setActionEnablement(IAction action) {
	try {
		action.setEnabled(isEnabled());
	} catch (TeamException e) {
		if (e.getStatus().getCode() == IResourceStatus.OUT_OF_SYNC_LOCAL) {
			// Enable the action to allow the user to discover the problem
			action.setEnabled(true);
		} else {
			action.setEnabled(false);
			// We should not open a dialog when determining menu enablements so log it instead
			SVNUIPlugin.log(e);
		}
	}
}
 
Example 11
Source File: FilterBugsDialogAction.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void selectionChanged(IAction action, ISelection selection) {
    if (navigator == null) {
        action.setEnabled(false);
        return;
    }
    BugContentProvider provider = BugContentProvider.getProvider(navigator.getNavigatorContentService());
    if (provider == null)
        throw new NullPointerException("Null provider");
    action.setEnabled(provider.getGrouping() != null);
}
 
Example 12
Source File: ViewDocumentAction.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
 */
public void run( IAction action )
{
	if ( !prePreview( ) )
	{
		return;
	}

	IFile file = getSelectedFile( );
	if ( file != null )
	{
		// String url = MessageFormat.format( PATTERN, new Object[]{
		// file.getLocation( ).toString( )
		// } );
		String url = file.getLocation( ).toString( );
		Map options = new HashMap( );
		options.put( WebViewer.FORMAT_KEY, WebViewer.HTML );
		options.put( WebViewer.RESOURCE_FOLDER_KEY,
				ReportPlugin.getDefault( )
						.getResourceFolder( file.getProject( ) ) );

		WebViewer.display( url, options );
	}
	else
	{
		action.setEnabled( false );
	}
}
 
Example 13
Source File: SDView.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Activate or deactivate the short key command given in parameter (see plugin.xml)
 *
 * @param id the command id defined in the plugin.xml
 * @param value the state value
 */
public void setEnableCommand(String id, boolean value) {
    IContributionItem shortKeysMenu = getViewSite().getActionBars().getMenuManager().find("org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers");//$NON-NLS-1$
    MenuManager shortKeys = (MenuManager) shortKeysMenu;
    if (shortKeys == null) {
        return;
    }
    IContributionItem item = shortKeys.find(id);
    if ((item != null) && (item instanceof ActionContributionItem)) {
        IAction action = ((ActionContributionItem) item).getAction();
        if (action != null) {
            action.setEnabled(value);
        }
    }
}
 
Example 14
Source File: AbstractProjectPropertiesAction.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
public final void selectionChanged(IAction action, ISelection selection) {
  this.resource = ResourceUtils.getSelectionResource(selection);

  boolean isJavaProjectSelected = false;

  try {
    isJavaProjectSelected = (this.resource != null && NatureUtils.hasNature(
        this.resource.getProject(), JavaCore.NATURE_ID));
  } catch (CoreException e) {
    CorePluginLog.logError(e);
  }

  action.setEnabled(isJavaProjectSelected);
}
 
Example 15
Source File: PreviewCascadingMenuGroup.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action
 *      .IAction, org.eclipse.jface.viewers.ISelection)
 */
public void selectionChanged( IAction action, ISelection selection )
{
	action.setEnabled( isEnable( ) );
}
 
Example 16
Source File: PreviewToolbarMenuAction.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action
 *      .IAction, org.eclipse.jface.viewers.ISelection)
 */
public void selectionChanged( IAction action, ISelection selection )
{
	action.setEnabled( isEnable( ) );
}
 
Example 17
Source File: CommitAction.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
public void execute(IAction action) throws InvocationTargetException, InterruptedException {
	statusMap = new HashMap();
	final IResource[] resources = getSelectedResources();
    final List resourcesToBeAdded = new ArrayList();
    final List resourcesToBeDeleted = new ArrayList();
           if (action != null && !action.isEnabled()) { 
           	action.setEnabled(true);
           } 
           else {
           	run(new IRunnableWithProgress() {
       			public void run(IProgressMonitor monitor) throws InvocationTargetException {
       				try {	
       				    // search for modified or added, non-ignored resources in the selection.
       				    IResource[] modified = getModifiedResources(resources, monitor);
       					
       				    // if no changes since last commit, do not show commit dialog.
       				    if (modified.length == 0) {
       					    MessageDialog.openInformation(getShell(), Policy.bind("CommitDialog.title"), Policy.bind("CommitDialog.noChanges")); //$NON-NLS-1$ //$NON-NLS-2$
       					    commit = false;
       					} else {
       					    ProjectProperties projectProperties = ProjectProperties.getProjectProperties(modified[0]);
       					    commit = confirmCommit(modified, projectProperties);
       					}

       				    // if commit was not canceled, create a list of any
       				    // unversioned resources that were selected and a list of any missing
       				    // resources that were selected.
       					if (commit) {
       					    for (int i = 0; i < resourcesToCommit.length; i++) {
       					        IResource resource = resourcesToCommit[i];
       					        ISVNLocalResource svnResource = SVNWorkspaceRoot.getSVNResourceFor(resource);
       					        if (svnResource.exists() && !svnResource.isManaged()) resourcesToBeAdded.add(resource);
       					        if (svnResource.getStatus().isMissing()) resourcesToBeDeleted.add(resource);
       					    }
       					}
       				} catch (TeamException e) {
       					throw new InvocationTargetException(e);
       				}
       			}
       		}, true /* cancelable */, PROGRESS_BUSYCURSOR); //$NON-NLS-1$
       		
       		if (!commit) {
       			return; // user canceled
       		}
       		
       		CommitOperation commitOperation = new CommitOperation(getTargetPart(), resources, 
       				(IResource[]) resourcesToBeAdded.toArray(new IResource[resourcesToBeAdded.size()]),
       				(IResource[]) resourcesToBeDeleted.toArray(new IResource[resourcesToBeDeleted.size()]),
       				resourcesToCommit, commitComment, keepLocks);
       		commitOperation.setCanRunAsJob(canRunAsJob);       		
       		commitOperation.run();
           }
}
 
Example 18
Source File: JavaHistoryActionImpl.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public final void selectionChanged(IAction uiProxy, ISelection selection) {
	fSelection= selection;
	uiProxy.setEnabled(isEnabled(selection));
}
 
Example 19
Source File: GenerateDocumentAction.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
public void run( IAction action )
{
	if ( !preGenerate( ) )
	{
		return;
	}

	IFile file = getSelectedFile( );
	if ( file != null )
	{
		String url = file.getLocation( ).toOSString( );

		Map options = new HashMap( );
		options.put( WebViewer.RESOURCE_FOLDER_KEY,
				ReportPlugin.getDefault( )
						.getResourceFolder( file.getProject( ) ) );
		options.put( WebViewer.SERVLET_NAME_KEY, WebViewer.VIEWER_DOCUMENT );

		Object adapter = ElementAdapterManager.getAdapter( action,
				IPreviewAction.class );

		if ( adapter instanceof IPreviewAction )
		{
			IPreviewAction delegate = (IPreviewAction) adapter;

			delegate.setProperty( IPreviewConstants.REPORT_PREVIEW_OPTIONS,
					options );
			delegate.setProperty( IPreviewConstants.REPORT_FILE_PATH, url );

			delegate.run( );

			return;
		}

		try
		{
			WebViewer.display( url, options );
		}
		catch ( Exception e )
		{
			ExceptionUtil.handle( e );
			return;
		}
	}
	else
	{
		action.setEnabled( false );
	}
}
 
Example 20
Source File: AbstractTexSelectionChange.java    From texlipse with Eclipse Public License 1.0 3 votes vote down vote up
/**
 * Receive a notification about a changed selection.
 * This action is set enabled or disabled according to the type of selection.
 * This method is called by Eclipse.
 * 
 * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction,
 *      org.eclipse.jface.viewers.ISelection)
 */
public void selectionChanged(IAction action, ISelection selection) {
    if (selection instanceof TextSelection) {
        action.setEnabled(true);
        return;
    }
    action.setEnabled(targetEditor instanceof ITextEditor);
}