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

The following examples show how to use org.eclipse.jface.viewers.ISelection#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 File: ItemSelectionHelper.java    From neoscada with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Get all {@link Item} instances from the current selection
 *
 * @param selection
 *            the selection
 * @return the item instances
 */
public static Collection<Item> getSelection ( final ISelection selection )
{
    final Collection<Item> items = new LinkedList<Item> ();

    if ( selection == null || selection.isEmpty () )
    {
        return items;
    }

    if ( selection instanceof IStructuredSelection )
    {
        final Iterator<?> i = ( (IStructuredSelection)selection ).iterator ();
        while ( i.hasNext () )
        {
            final Item item = AdapterHelper.adapt ( i.next (), Item.class );
            if ( item != null )
            {
                items.add ( item );
            }
        }
    }

    return items;
}
 
Example 2
Source File: CheckConfigurationConfigureDialog.java    From eclipse-cs with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Creates a module editor for the current selection.
 *
 * @param selection
 *          the selection
 */
private void removeModule(ISelection selection) {

  if (!selection.isEmpty() && mConfigurable) {

    if (MessageDialog.openConfirm(getShell(),
            Messages.CheckConfigurationConfigureDialog_titleRemoveModules,
            Messages.CheckConfigurationConfigureDialog_msgRemoveModules)) {

      @SuppressWarnings("unchecked")
      Iterator<Module> it = ((IStructuredSelection) selection).iterator();
      while (it.hasNext()) {
        Module m = it.next();
        if (m.getMetaData().isDeletable()) {
          mModules.remove(m);
          mIsDirty = true;
          mTableViewer.refresh(true);
          refreshTableViewerState();
          mTreeViewer.refresh();
        }
      }
    }
  }
}
 
Example 3
Source File: BasicEditor.java    From neoscada with Eclipse Public License 1.0 6 votes vote down vote up
protected void handleDelete ()
{
    final ISelection sel = this.viewer.getSelection ();
    if ( sel == null || sel.isEmpty () || ! ( sel instanceof IStructuredSelection ) )
    {
        return;
    }

    final IStructuredSelection selection = (IStructuredSelection)sel;

    final Iterator<?> i = selection.iterator ();
    while ( i.hasNext () )
    {
        final Object o = i.next ();
        final Map.Entry<?, ?> entry = AdapterHelper.adapt ( o, Map.Entry.class );
        if ( entry != null )
        {
            deleteEntry ( "" + entry.getKey () );
        }
    }
}
 
Example 4
Source File: ItemSelectionHelper.java    From neoscada with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Get all {@link Item} instances from the current selection
 * 
 * @param selection
 *            the selection
 * @return the item instances
 */
public static Collection<Item> getSelection ( final ISelection selection )
{
    final Collection<Item> items = new LinkedList<Item> ();

    if ( selection == null || selection.isEmpty () )
    {
        return items;
    }

    if ( selection instanceof IStructuredSelection )
    {
        final Iterator<?> i = ( (IStructuredSelection)selection ).iterator ();
        while ( i.hasNext () )
        {
            final Item item = AdapterHelper.adapt ( i.next (), Item.class );
            if ( item != null )
            {
                items.add ( item );
            }
        }
    }

    return items;
}
 
Example 5
Source File: CrossflowInitDiagramFileAction.java    From scava with Eclipse Public License 2.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 6
Source File: VisualInterfaceEditor.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * This deals with how we want selection in the outliner to affect the other views.
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public void handleContentOutlineSelection ( ISelection selection )
{
    if ( currentViewerPane != null && !selection.isEmpty () && selection instanceof IStructuredSelection )
    {
        Iterator<?> selectedElements = ( (IStructuredSelection)selection ).iterator ();
        if ( selectedElements.hasNext () )
        {
            // Get the first selected element.
            //
            Object selectedElement = selectedElements.next ();

            // If it's the selection viewer, then we want it to select the same selection as this selection.
            //
            if ( currentViewerPane.getViewer () == selectionViewer )
            {
                ArrayList<Object> selectionList = new ArrayList<Object> ();
                selectionList.add ( selectedElement );
                while ( selectedElements.hasNext () )
                {
                    selectionList.add ( selectedElements.next () );
                }

                // Set the selection to the widget.
                //
                selectionViewer.setSelection ( new StructuredSelection ( selectionList ) );
            }
            else
            {
                // Set the input to the widget.
                //
                if ( currentViewerPane.getViewer ().getInput () != selectedElement )
                {
                    currentViewerPane.getViewer ().setInput ( selectedElement );
                    currentViewerPane.setTitle ( selectedElement );
                }
            }
        }
    }
}
 
Example 7
Source File: ComponentEditor.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * This deals with how we want selection in the outliner to affect the other views.
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public void handleContentOutlineSelection ( ISelection selection )
{
    if ( currentViewerPane != null && !selection.isEmpty () && selection instanceof IStructuredSelection )
    {
        Iterator<?> selectedElements = ( (IStructuredSelection)selection ).iterator ();
        if ( selectedElements.hasNext () )
        {
            // Get the first selected element.
            //
            Object selectedElement = selectedElements.next ();

            // If it's the selection viewer, then we want it to select the same selection as this selection.
            //
            if ( currentViewerPane.getViewer () == selectionViewer )
            {
                ArrayList<Object> selectionList = new ArrayList<Object> ();
                selectionList.add ( selectedElement );
                while ( selectedElements.hasNext () )
                {
                    selectionList.add ( selectedElements.next () );
                }

                // Set the selection to the widget.
                //
                selectionViewer.setSelection ( new StructuredSelection ( selectionList ) );
            }
            else
            {
                // Set the input to the widget.
                //
                if ( currentViewerPane.getViewer ().getInput () != selectedElement )
                {
                    currentViewerPane.getViewer ().setInput ( selectedElement );
                    currentViewerPane.setTitle ( selectedElement );
                }
            }
        }
    }
}
 
Example 8
Source File: GlobalizeEditor.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * This deals with how we want selection in the outliner to affect the other views.
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public void handleContentOutlineSelection ( ISelection selection )
{
    if ( currentViewerPane != null && !selection.isEmpty () && selection instanceof IStructuredSelection )
    {
        Iterator<?> selectedElements = ( (IStructuredSelection)selection ).iterator ();
        if ( selectedElements.hasNext () )
        {
            // Get the first selected element.
            //
            Object selectedElement = selectedElements.next ();

            // If it's the selection viewer, then we want it to select the same selection as this selection.
            //
            if ( currentViewerPane.getViewer () == selectionViewer )
            {
                ArrayList<Object> selectionList = new ArrayList<Object> ();
                selectionList.add ( selectedElement );
                while ( selectedElements.hasNext () )
                {
                    selectionList.add ( selectedElements.next () );
                }

                // Set the selection to the widget.
                //
                selectionViewer.setSelection ( new StructuredSelection ( selectionList ) );
            }
            else
            {
                // Set the input to the widget.
                //
                if ( currentViewerPane.getViewer ().getInput () != selectedElement )
                {
                    currentViewerPane.getViewer ().setInput ( selectedElement );
                    currentViewerPane.setTitle ( selectedElement );
                }
            }
        }
    }
}
 
Example 9
Source File: DetailViewEditor.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * This deals with how we want selection in the outliner to affect the other views.
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public void handleContentOutlineSelection ( ISelection selection )
{
    if ( currentViewerPane != null && !selection.isEmpty () && selection instanceof IStructuredSelection )
    {
        Iterator<?> selectedElements = ( (IStructuredSelection)selection ).iterator ();
        if ( selectedElements.hasNext () )
        {
            // Get the first selected element.
            //
            Object selectedElement = selectedElements.next ();

            // If it's the selection viewer, then we want it to select the same selection as this selection.
            //
            if ( currentViewerPane.getViewer () == selectionViewer )
            {
                ArrayList<Object> selectionList = new ArrayList<Object> ();
                selectionList.add ( selectedElement );
                while ( selectedElements.hasNext () )
                {
                    selectionList.add ( selectedElements.next () );
                }

                // Set the selection to the widget.
                //
                selectionViewer.setSelection ( new StructuredSelection ( selectionList ) );
            }
            else
            {
                // Set the input to the widget.
                //
                if ( currentViewerPane.getViewer ().getInput () != selectedElement )
                {
                    currentViewerPane.getViewer ().setInput ( selectedElement );
                    currentViewerPane.setTitle ( selectedElement );
                }
            }
        }
    }
}
 
Example 10
Source File: OsgiEditor.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * This deals with how we want selection in the outliner to affect the other views.
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public void handleContentOutlineSelection ( ISelection selection )
{
    if ( currentViewerPane != null && !selection.isEmpty () && selection instanceof IStructuredSelection )
    {
        Iterator<?> selectedElements = ( (IStructuredSelection)selection ).iterator ();
        if ( selectedElements.hasNext () )
        {
            // Get the first selected element.
            //
            Object selectedElement = selectedElements.next ();

            // If it's the selection viewer, then we want it to select the same selection as this selection.
            //
            if ( currentViewerPane.getViewer () == selectionViewer )
            {
                ArrayList<Object> selectionList = new ArrayList<Object> ();
                selectionList.add ( selectedElement );
                while ( selectedElements.hasNext () )
                {
                    selectionList.add ( selectedElements.next () );
                }

                // Set the selection to the widget.
                //
                selectionViewer.setSelection ( new StructuredSelection ( selectionList ) );
            }
            else
            {
                // Set the input to the widget.
                //
                if ( currentViewerPane.getViewer ().getInput () != selectedElement )
                {
                    currentViewerPane.getViewer ().setInput ( selectedElement );
                    currentViewerPane.setTitle ( selectedElement );
                }
            }
        }
    }
}
 
Example 11
Source File: SetupEditor.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * This deals with how we want selection in the outliner to affect the other views.
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public void handleContentOutlineSelection ( ISelection selection )
{
    if ( currentViewerPane != null && !selection.isEmpty () && selection instanceof IStructuredSelection )
    {
        Iterator<?> selectedElements = ( (IStructuredSelection)selection ).iterator ();
        if ( selectedElements.hasNext () )
        {
            // Get the first selected element.
            //
            Object selectedElement = selectedElements.next ();

            // If it's the selection viewer, then we want it to select the same selection as this selection.
            //
            if ( currentViewerPane.getViewer () == selectionViewer )
            {
                ArrayList<Object> selectionList = new ArrayList<Object> ();
                selectionList.add ( selectedElement );
                while ( selectedElements.hasNext () )
                {
                    selectionList.add ( selectedElements.next () );
                }

                // Set the selection to the widget.
                //
                selectionViewer.setSelection ( new StructuredSelection ( selectionList ) );
            }
            else
            {
                // Set the input to the widget.
                //
                if ( currentViewerPane.getViewer ().getInput () != selectedElement )
                {
                    currentViewerPane.getViewer ().setInput ( selectedElement );
                    currentViewerPane.setTitle ( selectedElement );
                }
            }
        }
    }
}
 
Example 12
Source File: CodewindNavigatorDropAssistant.java    From codewind-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public IStatus validateDrop(Object target, int operation, TransferData transferData) {
	targetConn = null;
	sourceApp = null;
	if (!(target instanceof CodewindConnection) || !((CodewindConnection)target).isConnected()) {
		return Status.CANCEL_STATUS;
	}
	targetConn = (CodewindConnection)target;
	
	// Check that the source is an application that is not already added to this connection
	if (LocalSelectionTransfer.getTransfer().isSupportedType(transferData)) {
		ISelection s = LocalSelectionTransfer.getTransfer().getSelection();
		if (!s.isEmpty() && s instanceof IStructuredSelection) {
			IStructuredSelection sel = (IStructuredSelection) s;
			Object obj = sel.getFirstElement();
			if (obj instanceof CodewindApplication) {
				CodewindApplication app = targetConn.getAppByName(((CodewindApplication)obj).name);
				if (app != null) {
					return Status.CANCEL_STATUS;
				}
				sourceApp = (CodewindApplication)obj;
				return Status.OK_STATUS;
			}
		}
	}
	return Status.CANCEL_STATUS;
}
 
Example 13
Source File: ProtocolEditor.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * This deals with how we want selection in the outliner to affect the other views.
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public void handleContentOutlineSelection ( ISelection selection )
{
    if ( currentViewerPane != null && !selection.isEmpty () && selection instanceof IStructuredSelection )
    {
        Iterator<?> selectedElements = ( (IStructuredSelection)selection ).iterator ();
        if ( selectedElements.hasNext () )
        {
            // Get the first selected element.
            //
            Object selectedElement = selectedElements.next ();

            // If it's the selection viewer, then we want it to select the same selection as this selection.
            //
            if ( currentViewerPane.getViewer () == selectionViewer )
            {
                ArrayList<Object> selectionList = new ArrayList<Object> ();
                selectionList.add ( selectedElement );
                while ( selectedElements.hasNext () )
                {
                    selectionList.add ( selectedElements.next () );
                }

                // Set the selection to the widget.
                //
                selectionViewer.setSelection ( new StructuredSelection ( selectionList ) );
            }
            else
            {
                // Set the input to the widget.
                //
                if ( currentViewerPane.getViewer ().getInput () != selectedElement )
                {
                    currentViewerPane.getViewer ().setInput ( selectedElement );
                    currentViewerPane.setTitle ( selectedElement );
                }
            }
        }
    }
}
 
Example 14
Source File: DashboardComposite.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/** removes selected graph or all graphs if nothing selected */
public void removeSelectedGraphs(boolean removeAllIfNothingSelected) {
	ISelection sel = listViewer.getSelection();
	if (!sel.isEmpty()) {
		removeEntries(((IStructuredSelection) sel).toList());
	} else {
		// empty selection:
		if (removeAllIfNothingSelected)
			removeEntries(new ArrayList<>(entries));
	}
}
 
Example 15
Source File: GraphList.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
public void removeSelectedGraphs(boolean removeAllIfNothingSelected) {
	ISelection sel = listViewer.getSelection();
	if (!sel.isEmpty()) {
		removeEntries(((IStructuredSelection) sel).toList());
	} else {
		// empty selection:
		if (removeAllIfNothingSelected)
			removeEntries(new ArrayList<>(entries));
	}
}
 
Example 16
Source File: WorldEditor.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * This deals with how we want selection in the outliner to affect the other views.
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public void handleContentOutlineSelection ( ISelection selection )
{
    if ( currentViewerPane != null && !selection.isEmpty () && selection instanceof IStructuredSelection )
    {
        Iterator<?> selectedElements = ( (IStructuredSelection)selection ).iterator ();
        if ( selectedElements.hasNext () )
        {
            // Get the first selected element.
            //
            Object selectedElement = selectedElements.next ();

            // If it's the selection viewer, then we want it to select the same selection as this selection.
            //
            if ( currentViewerPane.getViewer () == selectionViewer )
            {
                ArrayList<Object> selectionList = new ArrayList<Object> ();
                selectionList.add ( selectedElement );
                while ( selectedElements.hasNext () )
                {
                    selectionList.add ( selectedElements.next () );
                }

                // Set the selection to the widget.
                //
                selectionViewer.setSelection ( new StructuredSelection ( selectionList ) );
            }
            else
            {
                // Set the input to the widget.
                //
                if ( currentViewerPane.getViewer ().getInput () != selectedElement )
                {
                    currentViewerPane.getViewer ().setInput ( selectedElement );
                    currentViewerPane.setTitle ( selectedElement );
                }
            }
        }
    }
}
 
Example 17
Source File: OpenGeneratedSourceInEditorHandler.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {

	final ISelection selection = getCurrentSelection(event);
	if (null == selection) {
		return null;
	}

	if (selection.isEmpty()) {
		return null;
	}

	final AtomicReference<IFile> fileRef = new AtomicReference<>();

	if (selection instanceof IStructuredSelection) {
		final Object element = ((IStructuredSelection) selection).getFirstElement();
		if (element instanceof IFile) {
			fileRef.set((IFile) element);
		}
	} else if (selection instanceof ITextSelection) {
		final IEditorPart editorPart = getActiveEditor(event);
		if (null != editorPart) {
			final IEditorInput input = editorPart.getEditorInput();
			if (input instanceof IFileEditorInput) {
				fileRef.set(((IFileEditorInput) input).getFile());
			}
		}
	}

	if (null != fileRef.get()) {
		final Optional<IFile> generatedSource = fileLocator.tryGetGeneratedSourceForN4jsFile(fileRef.get());
		if (generatedSource.isPresent()) {
			tryOpenFileInEditor(fileRef.get(), generatedSource.get());
		}
	}

	return null;
}
 
Example 18
Source File: CDateTimeSelectionProvider.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
public void setSelection(ISelection selection) {
	if(!selection.isEmpty() && (selection instanceof IStructuredSelection)) {
		Object obj = ((IStructuredSelection) selection).getFirstElement();
		if(obj instanceof Date) {
			cdt.setSelection((Date) obj);
		}
	}
}
 
Example 19
Source File: CDateTimeSelectionProvider.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
public void setSelection(ISelection selection) {
	if(!selection.isEmpty() && (selection instanceof IStructuredSelection)) {
		Object obj = ((IStructuredSelection) selection).getFirstElement();
		if(obj instanceof Date) {
			cdt.setSelection((Date) obj);
		}
	}
}
 
Example 20
Source File: FactoryEditor.java    From neoscada with Eclipse Public License 1.0 4 votes vote down vote up
public void handleDelete ()
{
    final ISelection sel = this.viewer.getSelection ();
    if ( sel == null || sel.isEmpty () || ! ( sel instanceof IStructuredSelection ) )
    {
        return;
    }

    final IStructuredSelection selection = (IStructuredSelection)sel;

    final Collection<String> items = new LinkedList<String> ();

    final Iterator<?> i = selection.iterator ();
    while ( i.hasNext () )
    {
        final ConfigurationDescriptor info = (ConfigurationDescriptor)i.next ();
        items.add ( info.getConfigurationInformation ().getId () );
    }

    if ( items.isEmpty () )
    {
        return;
    }

    if ( !MessageDialog.openConfirm ( this.viewer.getControl ().getShell (), "Delete configurations", String.format ( "Delete %s configuration entries", items.size () ) ) )
    {
        return;
    }

    final org.eclipse.core.runtime.jobs.Job job = this.factoryInput.createDeleteJob ( items );
    job.addJobChangeListener ( new JobChangeAdapter () {

        @Override
        public void done ( final IJobChangeEvent event )
        {
            refresh ();
        }

    } );
    job.schedule ();
}