Java Code Examples for org.eclipse.jface.viewers.IStructuredSelection#isEmpty()

The following examples show how to use org.eclipse.jface.viewers.IStructuredSelection#isEmpty() . 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 Project: typescript.java   File: TextSpanLinkHelper.java    License: MIT License 6 votes vote down vote up
private NavigationTextSpan getSpan(IStructuredSelection selection) {
	if (selection.isEmpty()) {
		return null;
	}
	Object element = selection.getFirstElement();
	if (element instanceof NavigationTextSpan) {
		return (NavigationTextSpan) element;
	}
	if (element instanceof NavigationBarItem) {
		NavigationBarItem item = (NavigationBarItem) element;
		if (item.hasSpans()) {
			return item.getSpans().get(0);
		}
	}
	return null;
}
 
Example 2
@Override
public void expandAll() {
	getControl().setRedraw(false);
	NavigatorContentProvider.FILE_CHILDREN_ENABLED = false;
	final IStructuredSelection currentSelection = (IStructuredSelection) getSelection();
	if (currentSelection == null || currentSelection.isEmpty()) {
		super.expandAll();
	} else {
		final Iterator<?> it = currentSelection.iterator();
		while (it.hasNext()) {
			final Object o = it.next();
			if (o instanceof TopLevelFolder) {
				expandToLevel(o, CommonViewer.ALL_LEVELS); // 2
			} else if (o instanceof IContainer) {
				expandToLevel(o, CommonViewer.ALL_LEVELS);
			}
		}

	}
	NavigatorContentProvider.FILE_CHILDREN_ENABLED = true;
	this.refresh(false);
	getControl().setRedraw(true);

}
 
Example 3
@Override
public boolean updateSelection(IStructuredSelection selection) {
	if (selection == null || selection.isEmpty()) {
		return false;
	}

	final Object[] selectedElements = selection.toArray();
	final IProject[] selectedProjects = Arrays2.filter(selectedElements, IProject.class);

	// only enable this action for project-only selections
	if (selectedElements.length != selectedProjects.length) {
		return false;
	}

	// also check whether the active manager is {@link ManualAssociationAwareWorkingSetManager}
	if (!(broker.getActiveManager() instanceof ManualAssociationAwareWorkingSetManager)) {
		return false;
	} else {
		return true;
	}
}
 
Example 4
@SuppressWarnings("unchecked")
private void exportAll() {
   	// save selection
	IStructuredSelection selectionSave= (IStructuredSelection)tableViewer.getSelection();
	// select all
	tableViewer.getTable().selectAll();
	IStructuredSelection selection= (IStructuredSelection)tableViewer.getSelection();

	if(selection.isEmpty()) {
       	MessageDialog.openError(getShell(),
       			LogViewerPlugin.getResourceString("preferences.ruleseditor.export.error.title"), //$NON-NLS-1$
       			LogViewerPlugin.getResourceString("preferences.ruleseditor.export.error.select.items.text")); //$NON-NLS-1$
   		return;
	} else {
		//export
    	Collection<RulePreferenceData> itemArray= new ArrayList<RulePreferenceData>();
    	itemArray.addAll(selection.toList());
    	export(itemArray.toArray(new RulePreferenceData[itemArray.size()]));
	}

	// restore selection
	tableViewer.setSelection(selectionSave, true);
   }
 
Example 5
Source Project: nebula   File: TreeMapper.java    License: Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @see org.eclipse.jface.viewers.ISelectionProvider#setSelection(org.eclipse.jface.viewers.ISelection)
 */
@SuppressWarnings("unchecked")
public void setSelection(ISelection selection) {
	IStructuredSelection strSelection = (IStructuredSelection)selection;
	if (strSelection.isEmpty()) {
		currentSelection = new StructuredSelection();
		fireMouseExited(selectedMapping, mappingsToFigures.get(selectedMapping));
	} else {
		M mapping = (M) strSelection.getFirstElement();
		fireMappingSelection(mapping, mappingsToFigures.get(mapping));
	}
}
 
Example 6
private CustomizeData getCustTableSelection() {
   IStructuredSelection selection = (IStructuredSelection) custTable.getViewer().getSelection();
   if (selection.isEmpty()) {
      return null;
   }
   Iterator<?> i = selection.iterator();
   return (CustomizeData) i.next();
}
 
Example 7
private static IMember[] getSelectedMembers(IStructuredSelection selection){
	if (selection.isEmpty())
		return null;

	for  (Iterator<?> iter= selection.iterator(); iter.hasNext(); ) {
		if (! (iter.next() instanceof IMember))
			return null;
	}
	return convertToMemberArray(selection.toArray());
}
 
Example 8
public void selectionChanged(SelectionChangedEvent event) {
	IStructuredSelection selection = (IStructuredSelection)event.getSelection();
	if (!selection.isEmpty()) {
		Object elem = selection.getFirstElement();
		if (elem instanceof JimpleOutlineObject) {
			String toHighlight = ((JimpleOutlineObject)elem).getLabel();
			int start = getJimpleFileParser().getStartOfSelected(toHighlight);
			int length = getJimpleFileParser().getLength(toHighlight);
			getEd().selectAndReveal(start, length);
		}
	}
}
 
Example 9
Source Project: tesb-studio-se   File: RunCamelProcess.java    License: Apache License 2.0 5 votes vote down vote up
public void init(TreeViewer viewer, IStructuredSelection selection) {
    boolean canWork = !selection.isEmpty() && selection.size() == 1;
    // if
    // (DesignerPlugin.getDefault().getRepositoryService().getProxyRepositoryFactory().isUserReadOnlyOnCurrentProject())
    // {
    // canWork = false;
    // }
    if (canWork) {
        Object o = selection.getFirstElement();
        RepositoryNode node = (RepositoryNode) o;

        switch (node.getType()) {
        case REPOSITORY_ELEMENT:
            if (node.getParent() == null || node.getParent().getContentType() != CamelRepositoryNodeType.repositoryRoutesType) {
                canWork = false;
            }
            // Avoid showing in route test case
            if (node.getObjectType().getType().equals(TEST_CONTAINER)) {
                canWork = false;
            }
            break;
        default:
            canWork = false;
        }
        RepositoryNode parent = node.getParent();
        if (canWork && parent != null && parent instanceof BinRepositoryNode) {
            canWork = false;
        }
    }
    setEnabled(canWork);
}
 
Example 10
@Override
public void selectionChanged(SelectionChangedEvent event) {
  projectSelector.clearStatusLink();
  latestQueryJob = null;

  IStructuredSelection selection = (IStructuredSelection) event.getSelection();
  if (selection.isEmpty()) {
    return;
  }

  GcpProject project = (GcpProject) selection.getFirstElement();
  String email = accountSelector.getSelectedEmail();
  String createAppLink = MessageFormat.format(CREATE_APP_LINK,
      project.getId(), UrlEscapers.urlFormParameterEscaper().escape(email));

  boolean queryCached = project.hasAppEngineInfo();
  if (queryCached) {
    if (project.getAppEngine() == AppEngine.NO_APPENGINE_APPLICATION) {
      projectSelector.setStatusLink(
          Messages.getString("projectselector.missing.appengine.application.link", createAppLink),
          createAppLink /* tooltip */);
    }
  } else {  // The project has never been queried.
    Credential credential = accountSelector.getSelectedCredential();
    Predicate<Job> isLatestQueryJob = job -> job == latestQueryJob;
    latestQueryJob = new AppEngineApplicationQueryJob(project, credential, projectRepository,
        projectSelector, createAppLink, isLatestQueryJob);
    latestQueryJob.schedule();
  }
}
 
Example 11
private static IMethod getSingleSelectedMethod(IStructuredSelection selection){
	if (selection.isEmpty() || selection.size() != 1)
		return null;
	if (selection.getFirstElement() instanceof IMethod)
		return (IMethod)selection.getFirstElement();
	return null;
}
 
Example 12
Source Project: tlaplus   File: TLCErrorView.java    License: MIT License 5 votes vote down vote up
private void handleValueViewerUpdate(final IStructuredSelection structuredSelection) {
if (!structuredSelection.isEmpty()) {
	// Set selection to the selected element (or the first if there are multiple
	// selections), and show its string representation in the value viewer (the lower sub-window).
	final Object selection = structuredSelection.getFirstElement();
	if (selection instanceof TLCState) {
		final TLCState state;
		if ((filteredStateIndexMap.size() != 0) && !valueReflectsFiltering.getSelection()) {
			final Integer index = filteredStateIndexMap.get(selection);
			
			if (index != null) {
				state = unfilteredInput.getStates(TLCError.Length.ALL).get(index.intValue());
			} else {
				TLCUIActivator.getDefault().logWarning("Could not find mapped index for state.");
				
				state = (TLCState) selection;
			}
		} else {
			state = (TLCState) selection;
		}
		valueViewer.setDocument(new Document(state.getConjunctiveDescription(true)));
	} else {
		valueViewer.setDocument(new Document(selection.toString()));
	}
} else {
	valueViewer.setDocument(NO_VALUE_DOCUMENT());
}
  }
 
Example 13
private boolean checkEnabled(IStructuredSelection selection) {
	if (selection.isEmpty())
		return false;
	for (Iterator<?> iter= selection.iterator(); iter.hasNext();) {
		Object element= iter.next();
		if (element instanceof ISourceReference)
			continue;
		if (element instanceof IFile)
			continue;
		if (JavaModelUtil.isOpenableStorage(element))
			continue;
		return false;
	}
	return true;
}
 
Example 14
public String getTargetFramework() {
	IStructuredSelection selection = (IStructuredSelection) frameworkViewer.getSelection();
	if (selection.isEmpty()) {
		return ""; //$NON-NLS-1$
	}
	return (String) selection.getFirstElement();
}
 
Example 15
private static IMethod getSingleSelectedMethod(IStructuredSelection selection) {
	if (selection.isEmpty() || selection.size() != 1)
		return null;

	Object first= selection.getFirstElement();
	if (! (first instanceof IMethod))
		return null;
	return (IMethod) first;
}
 
Example 16
@Override
public void selectionChanged(IStructuredSelection selection) {
	if (!selection.isEmpty()) {
		// cannot cut top-level types. this deletes the cu and then you cannot paste because the cu is gone.
		if (!containsOnlyElementsInsideCompilationUnits(selection) || containsTopLevelTypes(selection)) {
			setEnabled(false);
			return;
		}
		fCopyToClipboardAction.selectionChanged(selection);
		setEnabled(fCopyToClipboardAction.isEnabled() && RefactoringAvailabilityTester.isDeleteAvailable(selection));
	} else
		setEnabled(false);
}
 
Example 17
Source Project: birt   File: UIUtil.java    License: Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Gets the first selected edit part in layout editor. Whenever the user has
 * deselected all edit parts, the contents edit part should be returned.
 * 
 * @return the first selected EditPart or root edit part
 */
public static EditPart getCurrentEditPart( )
{
	EditPartViewer viewer = getLayoutEditPartViewer( );
	if ( viewer == null )
		return null;
	IStructuredSelection targets = (IStructuredSelection) viewer.getSelection( );
	if ( targets.isEmpty( ) )
		return null;
	return (EditPart) targets.getFirstElement( );
}
 
Example 18
public boolean canDrop( Object transfer, Object target )
{
	if ( target != null && transfer instanceof CubeHandle )
	{
		SlotHandle targetSlot = getTargetSlotHandle( target,
				ICrosstabConstants.CROSSTAB_EXTENSION_NAME ); //$NON-NLS-1$
		if ( targetSlot != null )
		{
			if ( DNDUtil.handleValidateTargetCanContainType( targetSlot,
					"Crosstab" )
					&& DNDUtil.handleValidateTargetCanContainMore( targetSlot,
							0 ) )
				return true;
		}
		else
		{
			IStructuredSelection models = InsertInLayoutUtil.editPart2Model( new StructuredSelection( target ) );
			if ( !models.isEmpty( ) )
			{
				Object model = DNDUtil.unwrapToModel( models.getFirstElement( ) );
				if ( model instanceof DesignElementHandle )
				{
					DesignElementHandle targetHandle = (DesignElementHandle) model;
					if ( targetHandle.canContain( DEUtil.getDefaultContentName( targetHandle ),
							ICrosstabConstants.CROSSTAB_EXTENSION_NAME ) )
						return true;
				}
			}
		}

	}
	return false;
}
 
Example 19
public static boolean isInlineMethodAvailable(final IStructuredSelection selection) throws JavaModelException {
	if (selection.isEmpty() || selection.size() != 1)
		return false;
	final Object first= selection.getFirstElement();
	return (first instanceof IMethod) && isInlineMethodAvailable(((IMethod) first));
}
 
Example 20
public static boolean isIntroduceIndirectionAvailable(final IStructuredSelection selection) throws JavaModelException {
	if (selection.isEmpty() || selection.size() != 1)
		return false;
	final Object first= selection.getFirstElement();
	return (first instanceof IMethod) && isIntroduceIndirectionAvailable(((IMethod) first));
}