Java Code Examples for org.eclipse.jface.viewers.StructuredSelection#size()

The following examples show how to use org.eclipse.jface.viewers.StructuredSelection#size() . 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: FilteredItemsSelectionDialog.java    From tlaplus with MIT License 6 votes vote down vote up
/**
 * Refreshes the details field according to the current selection in the
 * items list.
 */
private void refreshDetails() {
	StructuredSelection selection = getSelectedItems();

	switch (selection.size()) {
	case 0:
		details.setInput(null);
		break;
	case 1:
		details.setInput(selection.getFirstElement());
		break;
	default:
		details
				.setInput(NLS
						.bind(
								WorkbenchMessages.FilteredItemsSelectionDialog_nItemsSelected,
								new Integer(selection.size())));
		break;
	}

}
 
Example 2
Source File: SuperInterfaceSelectionDialog.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected void handleSelected(StructuredSelection selection) {
	super.handleSelected(selection);

	if (selection.size() == 0 && fTypeWizardPage.getSuperInterfaces().size() > fOldContent.size()) {
		// overrides updateStatus() from handleSelected() if
		// list of super interfaces was modified
		// the <code>super.handleSelected(selection)</code> has to be
		// called, because superclass implementation of this class updates
		// state of the table.

		updateStatus(Status.OK_STATUS);

		getButton(ADD_ID).setEnabled(false);
	} else {
		// if selection isn't empty, the add button should be enabled in
		// exactly the same scenarios as the OK button
		getButton(ADD_ID).setEnabled(getButton(OK).isEnabled());
	}
}
 
Example 3
Source File: AbstractSuperTypeSelectionDialog.java    From sarl with Apache License 2.0 6 votes vote down vote up
@Override
protected void handleSelected(StructuredSelection selection) {
	super.handleSelected(selection);

	if (selection.size() == 0 && getSuperTypeCount(this.typeWizardPage) > this.oldContent.size()) {
		// overrides updateStatus() from handleSelected() if
		// list of super interfaces was modified
		// the <code>super.handleSelected(selection)</code> has to be
		// called, because superclass implementation of this class updates
		// state of the table.

		updateStatus(Status.OK_STATUS);

		getButton(ADD_ID).setEnabled(false);
	} else {
		// if selection isn't empty, the add button should be enabled in
		// exactly the same scenarios as the OK button
		getButton(ADD_ID).setEnabled(getButton(OK).isEnabled());
	}
}
 
Example 4
Source File: AddElementtoReport.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
public Object getTarget( )
{
	IViewPart viewPart = UIUtil.getView( IPageLayout.ID_OUTLINE );
	if ( !( viewPart instanceof ContentOutline ) )
	{
		return null;
	}
	ContentOutline outlineView = (ContentOutline) viewPart;

	ISelection selection = outlineView.getSelection( );
	if ( selection instanceof StructuredSelection )
	{
		StructuredSelection strSelection = (StructuredSelection) selection;
		if ( strSelection.size( ) == 1 )
		{
			return strSelection.getFirstElement( );
		}
	}
	return null;
}
 
Example 5
Source File: CascadingParametersDialog.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
private void updateDynamicTableButtons( )
{
	StructuredSelection selection = (StructuredSelection) defaultValueViewer.getSelection( );
	boolean enable = ( selection.size( ) == 1 );
	editValueBtn.setEnabled( enable );
	delValueBtn.setEnabled( !selection.isEmpty( ) );
	delAllValuesBtn.setEnabled( defaultValueViewer.getTable( )
			.getItemCount( ) > 0 );

	Expression expression = ExpressionButtonUtil.getExpression( defaultValueChooser );
	if ( defaultValueChooser.getText( ).trim( ).length( ) == 0 )
	{
		addValueButton.setEnabled( false );
	}
	else
	{
		if ( defaultValueList != null
				&& defaultValueList.contains( expression ) )
			addValueButton.setEnabled( false );
		else
			addValueButton.setEnabled( true );
	}
}
 
Example 6
Source File: GoNavigatorActionProvider.java    From goclipse with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public boolean isEnabled() {
	ISelection selection = selectionProvider.getSelection();
	if(selection.isEmpty() || !(selection instanceof StructuredSelection)) {
		return false;
	}
	StructuredSelection ss = (StructuredSelection) selection;
	if(ss.size() == 1 && ss.getFirstElement() instanceof IFileStore) {
		IFileStore fileStore = (IFileStore) ss.getFirstElement();
		if(!fileStore.fetchInfo().isDirectory()) {
			this.fileStore = fileStore;
			return true;
		}
		return false;
	}
	return false;
}
 
Example 7
Source File: SelectModulaSourceFileDialog.java    From xds-ide with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected void updateButtonsEnableState(IStatus status) {
    Button okButton = getOkButton();
    StructuredSelection ss = getSelectedItems();
    if (ss.size() == 0 || (ss.getFirstElement() instanceof ListItem && ((ListItem)ss.getFirstElement()).isDelimiter())) {
        if (okButton != null && !okButton.isDisposed()) {
            okButton.setEnabled(false);
        }
    } else {
        super.updateButtonsEnableState(status);
    }
}
 
Example 8
Source File: ParameterDialog.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
private void updateDynamicTableButtons( )
{
	StructuredSelection selection = (StructuredSelection) defaultValueViewer.getSelection( );
	boolean enable = ( selection.size( ) == 1 );
	editBtn.setEnabled( enable );
	delBtn.setEnabled( !selection.isEmpty( ) );
	delAllBtn.setEnabled( defaultValueViewer.getTable( ).getItemCount( ) > 0 );

	String type = (String) defaultValueChooser.getData( ExpressionButtonUtil.EXPR_TYPE );
	String value = UIUtil.convertToModelString( defaultValueChooser.getText( ),
			false );
	if ( value != null )
	{
		if ( value.equals( EMPTY_VALUE ) )
			value = ""; //$NON-NLS-1$
		else if ( value.equals( NULL_VALUE ) )
			value = null;
	}
	Expression expression = null;
	if ( value != null )
		expression = new Expression( value, type );

	if ( defaultValueChooser.getText( ).trim( ).length( ) == 0 )
	{
		addButton.setEnabled( false );
	}
	else
	{
		if ( defaultValueList != null
				&& defaultValueList.contains( expression ) )
			addButton.setEnabled( false );
		else
			addButton.setEnabled( true );
	}
	updateMessageLine( );
}
 
Example 9
Source File: CommonViewer.java    From elexis-3-core with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @return the {@link #getViewerWidget()} current selections first element or <code>null</code>
 * @since 3.2.0
 */
public Object getViewerWidgetFirstSelection() {
	StructuredSelection  selection = (StructuredSelection) viewer.getSelection();
	if(selection==null || selection.size()==0) {
		return null;
	}
	return selection.getFirstElement();
}
 
Example 10
Source File: DiagnoseListComposite.java    From elexis-3-core with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void menuAboutToShow(IMenuManager manager){
	ISelection currentSelection = natTableWrapper.getSelection();
	if (currentSelection instanceof StructuredSelection) {
		StructuredSelection sSelection = (StructuredSelection) currentSelection;
		if (sSelection.size() == 1) {
			ICondition selectedCondition = (ICondition) sSelection.getFirstElement();
			ConditionStatus selectionStatus = selectedCondition.getStatus();
			if (selectionStatus != ConditionStatus.ACTIVE) {
				manager
					.add(new ToggleStatusAction(selectedCondition, ConditionStatus.ACTIVE));
			}
			if (selectionStatus != ConditionStatus.RESOLVED) {
				manager.add(
					new ToggleStatusAction(selectedCondition, ConditionStatus.RESOLVED));
			}
			if (selectionStatus != ConditionStatus.RELAPSE) {
				manager.add(
					new ToggleStatusAction(selectedCondition, ConditionStatus.RELAPSE));
			}
			if (selectionStatus != ConditionStatus.REMISSION) {
				manager.add(
					new ToggleStatusAction(selectedCondition, ConditionStatus.REMISSION));
			}
		}
		if (!sSelection.isEmpty()) {
			manager.add(new RemoveConditionAction());
		}
	}
}
 
Example 11
Source File: ProjectBuildPathPropertyPage.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Handle table selection. In case it's a single selection, enable/disable the 'Up' and 'Down' buttons according to
 * the selection. We only allow up and down for checked items.
 */
private void handleTableSelection()
{
	ISelection selection = tableViewer.getSelection();
	if (selection instanceof StructuredSelection)
	{
		StructuredSelection structuredSelection = (StructuredSelection) selection;
		Table table = tableViewer.getTable();
		if (structuredSelection.size() == 1 && table.getItemCount() > 1)
		{
			int selectionIndex = table.getSelectionIndex();
			TableItem item = table.getItem(selectionIndex);
			IBuildPathEntry data = (IBuildPathEntry) item.getData();
			if (item.getChecked())
			{
				upButton.setEnabled(selectionIndex != 0);
				downButton.setEnabled(selectionIndex < table.getItemCount() - 1
						&& selectionIndex < tableViewer.getCheckedElements().length - 1);
				if (!selectedEntries.contains(data))
				{
					selectedEntries.add(data);
					tableViewer.refresh();
				}
			}
			else
			{
				if (selectedEntries.contains(data))
				{
					selectedEntries.remove(data);
					tableViewer.refresh();
				}
				upButton.setEnabled(false);
				downButton.setEnabled(false);
			}
		}
		else
		{
			upButton.setEnabled(false);
			downButton.setEnabled(false);
		}
	}
}