List of usage examples for org.eclipse.jface.viewers StructuredSelection EMPTY
StructuredSelection EMPTY
To view the source code for org.eclipse.jface.viewers StructuredSelection EMPTY.
Click Source Link
From source file:net.rim.ejde.internal.menu.NewResourceFileCommandHandler.java
License:Open Source License
private void execute() { IWorkbench workbench = PlatformUI.getWorkbench(); NewResourceFileWizard bbResWiz = new NewResourceFileWizard(); bbResWiz.init(workbench, StructuredSelection.EMPTY); WizardDialog dialog = new WizardDialog(Display.getDefault().getShells()[0], bbResWiz); dialog.create();//from w ww .j av a 2 s . co m dialog.open(); }
From source file:net.rim.ejde.internal.menu.NewScreenCommandHandler.java
License:Open Source License
private void execute() { IWorkbench workbench = PlatformUI.getWorkbench(); NewScreenWizard bbScrWiz = new NewScreenWizard(); bbScrWiz.init(workbench, StructuredSelection.EMPTY); WizardDialog dialog = new WizardDialog(Display.getDefault().getShells()[0], bbScrWiz); dialog.create();//from ww w . ja va 2 s . c o m dialog.open(); }
From source file:net.rim.ejde.internal.menu.RunConfigurationsCommandHandler.java
License:Open Source License
@Override public Object execute(ExecutionEvent event) throws ExecutionException { StructuredSelection selection = (StructuredSelection) HandlerUtil.getCurrentSelection(event); if (selection != null && !selection.isEmpty()) { AbstractLaunchShortcut ls = new FledgeLaunchShortcut(); ls.openLaunchConfiguration(selection, "run"); } else {//w w w . j av a 2s.c om DebugUITools.openLaunchConfigurationDialog(Display.getDefault().getShells()[0], StructuredSelection.EMPTY, "run"); } return null; }
From source file:net.sf.eclipsensis.editor.NSISEditor.java
License:Open Source License
public void selectionChanged(SelectionChangedEvent event) { Object source = event.getSource(); ISelection selection = event.getSelection(); ISourceViewer sourceViewer = getSourceViewer(); boolean acquiredMutex = mMutex.acquireWithoutBlocking(source); try {/*from ww w . j a v a2 s. c o m*/ if (source.equals(sourceViewer) && selection instanceof ITextSelection) { IAction action = getAction(INSISEditorConstants.ADD_BLOCK_COMMENT); if (action != null) { action.setEnabled(sourceViewer.getSelectedRange().y > 0); } if (mOutlineContentProvider != null) { if (acquiredMutex) { ITextSelection textSelection = (ITextSelection) selection; IStructuredSelection sel = StructuredSelection.EMPTY; NSISOutlineElement element = mOutlineContentProvider.findElement(textSelection.getOffset(), textSelection.getLength()); if (element != null) { Position position = element.getPosition(); if (position.equals(mCurrentPosition)) { return; } else { if (mOutlinePage != null) { if (!mOutlinePage.isDisposed()) { sel = new StructuredSelection(element); mOutlinePage.setSelection(sel); return; } else { mOutlinePage = null; } } mCurrentPosition = position; setHighlightRange(mCurrentPosition.getOffset(), mCurrentPosition.getLength(), false); } } } else { return; } } mCurrentPosition = null; } else if (source instanceof TreeViewer) { if (selection.isEmpty()) { mCurrentPosition = null; resetHighlightRange(); } else { NSISOutlineElement element = (NSISOutlineElement) ((IStructuredSelection) selection) .getFirstElement(); Position position = element.getPosition(); if (mCurrentPosition == null || !position.equals(mCurrentPosition)) { mCurrentPosition = position; try { boolean moveCursor = acquiredMutex; // ISelection sel = getSelectionProvider().getSelection(); // if(sel != null && sel instanceof ITextSelection) { // int offset = ((ITextSelection)sel).getOffset(); // if(position.includes(offset)) { // moveCursor = false; // } // } setHighlightRange(mCurrentPosition.getOffset(), mCurrentPosition.getLength(), moveCursor); } catch (IllegalArgumentException x) { resetHighlightRange(); } } if (acquiredMutex) { Position selectPosition = element.getSelectPosition(); if (selectPosition != null) { sourceViewer.setSelectedRange(selectPosition.getOffset(), selectPosition.getLength()); } } } } } finally { if (acquiredMutex) { mMutex.release(source); } } }
From source file:net.sf.eclipsensis.help.commands.NSISCommandView.java
License:Open Source License
@Override public void createPartControl(Composite parent) { mFlatMode = NSISPreferences.getInstance().getBoolean(INSISPreferenceConstants.NSIS_COMMAND_VIEW_FLAT_MODE); mControl = new Composite(parent, SWT.NONE); GridLayout l = new GridLayout(1, true); // l.verticalSpacing = 0; mControl.setLayout(l);//w w w .j a v a 2 s . c om mFilterPanel = new Composite(mControl, SWT.NONE); mFilterPanel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); l = new GridLayout(3, false); l.marginWidth = l.marginHeight = 0; mFilterPanel.setLayout(l); mFilterPanel.setVisible(mShowFilter); ((GridData) mFilterPanel.getLayoutData()).exclude = !mShowFilter; Label temp = new Label(mFilterPanel, SWT.NONE); temp.setText("Filter:"); temp.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); FieldDecoration dec = FieldDecorationRegistry.getDefault() .getFieldDecoration(FieldDecorationRegistry.DEC_CONTENT_PROPOSAL); Rectangle bounds = dec.getImage().getBounds(); final Combo filterCombo = new Combo(mFilterPanel, SWT.BORDER | SWT.DROP_DOWN); GridData gd = new GridData(SWT.FILL, SWT.FILL, true, false); gd.horizontalIndent = bounds.width; filterCombo.setLayoutData(gd); final ComboViewer filterComboViewer = new ComboViewer(filterCombo); filterComboViewer.setContentProvider(new CollectionContentProvider(true)); filterComboViewer.setInput(mSavedFilterSettings); filterComboViewer.setSelection( mFilterSetting == null ? StructuredSelection.EMPTY : new StructuredSelection(mFilterSetting)); final Button regexp = new Button(mFilterPanel, SWT.CHECK); regexp.setText("Regular Expression"); regexp.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); regexp.setSelection(mFilterSetting != null && mFilterSetting.regexp); temp = new Label(mFilterPanel, SWT.NONE); temp.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); Composite c = new Composite(mFilterPanel, SWT.NONE); c.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); ((GridData) c.getLayoutData()).horizontalSpan = 2; l = new GridLayout(2, false); l.marginWidth = l.marginHeight = 0; c.setLayout(l); final String helpText = "(* = any string, ? = any character, \\ = escape for literals: * ? \\)"; final Label helpLabel = new Label(c, SWT.NONE); helpLabel.setText(helpText); gd = new GridData(SWT.FILL, SWT.FILL, true, false); gd.horizontalIndent = bounds.width; helpLabel.setLayoutData(gd); c = new Composite(c, SWT.None); c.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); l = new GridLayout(2, true); l.marginWidth = l.marginHeight = 0; c.setLayout(l); final Button clear = new Button(c, SWT.PUSH); clear.setText("Clear"); clear.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); final Button apply = new Button(c, SWT.PUSH); apply.setText("Apply"); apply.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); Tree tree = new Tree(mControl, SWT.BORDER | SWT.SINGLE | SWT.V_SCROLL | SWT.H_SCROLL | SWT.HIDE_SELECTION); tree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); tree.setLinesVisible(false); mViewer = new TreeViewer(tree); mViewer.setAutoExpandLevel(AbstractTreeViewer.ALL_LEVELS); mViewer.setContentProvider(new TreeContentProvider()); mViewer.setLabelProvider(new LabelProvider() { @Override public String getText(Object element) { if (element instanceof TreeNode) { return ((TreeNode) element).getName(); } return super.getText(element); } @Override public Image getImage(Object element) { if (element instanceof TreeNode) { if (((TreeNode) element).getCommand() != null) { return COMMAND_IMAGE; } else { return mViewer.getExpandedState(element) ? OPEN_CATEGORY_IMAGE : CATEGORY_IMAGE; } } return super.getImage(element); } }); mViewer.addTreeListener(new ITreeViewerListener() { public void treeCollapsed(TreeExpansionEvent event) { updateLabels(event); } /** * @param treeViewer * @param event */ private void updateLabels(TreeExpansionEvent event) { final Object element = event.getElement(); if (element instanceof TreeNode && ((TreeNode) element).getCommand() == null) { mViewer.getTree().getDisplay().asyncExec(new Runnable() { public void run() { mViewer.update(element, null); } }); } } public void treeExpanded(TreeExpansionEvent event) { updateLabels(event); } }); NSISPreferences.getInstance().addListener(this); mViewer.addDragSupport(DND.DROP_COPY, new Transfer[] { NSISCommandTransfer.INSTANCE }, new DragSourceAdapter() { @Override public void dragStart(DragSourceEvent e) { IEditorPart editor = getSite().getWorkbenchWindow().getActivePage().getActiveEditor(); if (!(editor instanceof NSISEditor)) { e.doit = false; } IStructuredSelection sel = (IStructuredSelection) mViewer.getSelection(); if (sel == null || sel.isEmpty() || !(sel.getFirstElement() instanceof TreeNode) || ((TreeNode) sel.getFirstElement()).getCommand() == null) { e.doit = false; } } @Override public void dragSetData(DragSourceEvent e) { IStructuredSelection sel = (IStructuredSelection) mViewer.getSelection(); if (sel != null && !sel.isEmpty() && sel.getFirstElement() instanceof TreeNode && ((TreeNode) sel.getFirstElement()).getCommand() != null) { e.data = ((TreeNode) sel.getFirstElement()).getCommand(); } else { e.data = null; } } }); mViewer.getTree().addKeyListener(new KeyAdapter() { @Override public void keyReleased(KeyEvent e) { if ((e.character == SWT.CR || e.character == SWT.LF) && e.stateMask == 0) { insertCommand(mViewer.getSelection()); } } }); mViewer.addDoubleClickListener(new IDoubleClickListener() { public void doubleClick(DoubleClickEvent event) { if (!insertCommand(event.getSelection())) { if (event.getSelection() instanceof IStructuredSelection && !event.getSelection().isEmpty()) { Object element = ((IStructuredSelection) event.getSelection()).getFirstElement(); if (element instanceof TreeNode) { TreeNode node = (TreeNode) element; mViewer.setExpandedState(node, !mViewer.getExpandedState(node)); } } } } }); final boolean[] stopListening = { false }; filterCombo.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) { if (!stopListening[0]) { mFilterSetting = createFilterSetting(filterCombo.getText(), regexp.getSelection()); apply.setEnabled(mFilterSetting != null); } } }); filterCombo.addFocusListener(new FocusAdapter() { @Override public void focusGained(FocusEvent e) { if (mContentAssistFindField == null) { createFilterContentAssist(filterCombo, helpLabel); } mContentAssistFindField.setEnabled(regexp.getSelection()); } }); regexp.addFocusListener(new FocusAdapter() { @Override public void focusGained(FocusEvent e) { if (mContentAssistFindField == null) { createFilterContentAssist(filterCombo, helpLabel); } mContentAssistFindField.setEnabled(regexp.getSelection()); } }); regexp.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { if (mContentAssistFindField == null) { createFilterContentAssist(filterCombo, helpLabel); } mContentAssistFindField.setEnabled(regexp.getSelection()); mFilterPanel.layout(new Control[] { filterCombo, helpLabel }); helpLabel.setVisible(!regexp.getSelection()); if (mContentAssistFindField != null) { mContentAssistFindField.setEnabled(regexp.getSelection()); } if (!stopListening[0]) { mFilterSetting = createFilterSetting(filterCombo.getText(), regexp.getSelection()); apply.setEnabled(mFilterSetting != null); } } }); clear.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { try { stopListening[0] = true; filterComboViewer.setSelection(StructuredSelection.EMPTY); regexp.setSelection(false); mFilterSetting = null; updateInput(); } finally { stopListening[0] = false; } } }); final Runnable applyFilterRunnable = new Runnable() { public void run() { updateInput(); FilterSetting filterSetting = mFilterSetting; mSavedFilterSettings.add(filterSetting); filterComboViewer.refresh(); filterComboViewer.setSelection(new StructuredSelection(filterSetting)); filterComboViewer.getCombo().clearSelection(); } }; apply.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { applyFilterRunnable.run(); } }); filterCombo.addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { if ((e.character == SWT.CR || e.character == SWT.LF) && e.stateMask == 0) { if (apply.isEnabled()) { applyFilterRunnable.run(); } } } }); filterComboViewer.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { if (!event.getSelection().isEmpty()) { IStructuredSelection sel = (IStructuredSelection) event.getSelection(); FilterSetting filterSetting = (FilterSetting) sel.getFirstElement(); try { stopListening[0] = true; mFilterSetting = filterSetting; regexp.setSelection(mFilterSetting.regexp); apply.setEnabled(true); } finally { stopListening[0] = false; } } } }); makeActions(); updateInput(); PlatformUI.getWorkbench().getHelpSystem().setHelp(mViewer.getControl(), INSISConstants.PLUGIN_CONTEXT_PREFIX + "nsis_cmdview_context"); }
From source file:net.sf.eclipsensis.help.NSISHTMLHelp.java
License:Open Source License
/** * @param toc/*from www .j a v a 2 s .c o m*/ * @param location */ private void synch(String location) { if (mSynched && mContentsViewer != null) { String url = location; try { new URL(url); } catch (MalformedURLException mue) { String suffix = ""; //$NON-NLS-1$ int n = url.lastIndexOf('#'); if (n > 0) { suffix = url.substring(n); url = url.substring(0, n); } File f = new File(url); url = IOUtility.getFileURLString(f) + suffix; } NSISHelpTOC toc = NSISHelpURLProvider.getInstance().getCachedHelpTOC(); NSISHelpTOCNode node = toc == null ? null : toc.getNode(url); if (node == null) { int n = url.lastIndexOf('#'); if (toc != null && n >= 0) { url = url.substring(0, n + 1); node = toc.getNode(url); if (node == null) { url = url.substring(0, n); node = toc.getNode(url); } } else { node = toc == null ? null : toc.getNode(url + "#"); //$NON-NLS-1$ } } if (node != null) { ISelection sel = mContentsViewer.getSelection(); if (sel.isEmpty() || !Common.objectsAreEqual(node, ((StructuredSelection) sel).getFirstElement())) { mContentsViewer.setSelection(new StructuredSelection(node)); } } else { mContentsViewer.setSelection(StructuredSelection.EMPTY); } } }
From source file:net.sf.eclipsensis.installoptions.actions.InstallOptionsWizardAction.java
License:Open Source License
@Override public void run() { final IWorkbench workbench = PlatformUI.getWorkbench(); final Shell shell = workbench.getActiveWorkbenchWindow().getShell(); final WizardDialog[] wizardDialog = new WizardDialog[1]; BusyIndicator.showWhile(shell.getDisplay(), new Runnable() { public void run() { InstallOptionsWizard wizard = new InstallOptionsWizard(); wizard.init(workbench, StructuredSelection.EMPTY); wizardDialog[0] = new WizardDialog(shell, wizard); wizardDialog[0].create();//from w w w. j a v a 2 s. com } }); wizardDialog[0].open(); }
From source file:net.sf.eclipsensis.installoptions.dialogs.InstallOptionsWidgetEditorDialog.java
License:Open Source License
@Override protected Control createControl(Composite parent) { Composite propertyComposite = new Composite(parent, SWT.BORDER); GridLayout layout = new GridLayout(1, false); layout.marginWidth = layout.marginHeight = 0; propertyComposite.setLayout(layout); if (mPage instanceof Page) { ((Page) mPage).init(new IPageSite() { public void registerContextMenu(String menuId, MenuManager menuManager, ISelectionProvider selectionProvider) { }/*from w ww .j a v a 2 s . c o m*/ public IActionBars getActionBars() { return null; } public IWorkbenchPage getPage() { return getWorkbenchWindow().getActivePage(); } public ISelectionProvider getSelectionProvider() { return null; } public Shell getShell() { return getWorkbenchWindow().getShell(); } public IWorkbenchWindow getWorkbenchWindow() { return PlatformUI.getWorkbench().getActiveWorkbenchWindow(); } public void setSelectionProvider(ISelectionProvider provider) { } @SuppressWarnings("unchecked") public Object getAdapter(Class adapter) { return null; } @SuppressWarnings("unchecked") public Object getService(Class api) { return null; } @SuppressWarnings("unchecked") public boolean hasService(Class api) { return false; } }); } if (mPage instanceof PropertySheetPage) { ((PropertySheetPage) mPage).setPropertySourceProvider(this); } mPage.createControl(propertyComposite); mPage.setActionBars(new DummyActionBars()); final Control control = mPage.getControl(); GridData data = new GridData(SWT.FILL, SWT.FILL, true, true); if (control instanceof Tree) { final Tree tree = (Tree) control; data.heightHint = tree.getItemHeight() * 13 + (tree.getLinesVisible() ? 12 * tree.getGridLineWidth() : 0) + (tree.getHeaderVisible() ? tree.getHeaderHeight() : 0) + 2 * tree.getBorderWidth() + (tree.getHorizontalBar() != null ? tree.getHorizontalBar().getSize().x : 0); tree.addControlListener(new ControlAdapter() { @Override public void controlResized(ControlEvent e) { Rectangle area = tree.getClientArea(); TreeColumn[] columns = tree.getColumns(); if (area.width > 0) { columns[0].setWidth(area.width * 40 / 100); columns[1].setWidth(area.width - columns[0].getWidth() - 4); } } }); } else if (control instanceof Composite) { control.addControlListener(new ControlAdapter() { @Override public void controlResized(ControlEvent e) { ((Composite) control).layout(true, true); } }); } control.setLayoutData(data); ISelection selection; if (mCurrentWidget == null) { Collection<InstallOptionsModelTypeDef> typeDefs = InstallOptionsModel.INSTANCE.getControlTypeDefs(); if (typeDefs.size() > 0) { InstallOptionsModelTypeDef typeDef = typeDefs.iterator().next(); InstallOptionsElementFactory factory = InstallOptionsElementFactory.getFactory(typeDef.getType()); mCurrentWidget = (InstallOptionsWidget) factory.getNewObject(); mDialog.addChild(mCurrentWidget); } } if (mCurrentWidget != null) { mCurrentWidget.addModelCommandListener(InstallOptionsWidgetEditorDialog.this); mCurrentWidget.addPropertyChangeListener(InstallOptionsWidgetEditorDialog.this); if (mCurrentWidget.getParent() != null) { mCurrentWidget.getParent().addPropertyChangeListener(InstallOptionsWidgetEditorDialog.this); } selection = new StructuredSelection(mCurrentWidget); } else { selection = StructuredSelection.EMPTY; } mPage.selectionChanged(null, selection); PlatformUI.getWorkbench().getHelpSystem().setHelp(mPage.getControl(), HELP_CONTEXT); PlatformUI.getWorkbench().getHelpSystem().setHelp(propertyComposite, HELP_CONTEXT); return propertyComposite; }
From source file:net.sf.eclipsensis.installoptions.properties.labelproviders.InstallOptionsElementLabelProvider.java
License:Open Source License
/** * @see org.eclipse.jface.viewers.ILabelProvider#getImage(java.lang.Object) *//* w w w . j a v a 2 s .c o m*/ @Override public Image getImage(Object objects) { if (objects == null || objects.equals(StructuredSelection.EMPTY)) { return null; } final boolean multiple[] = { false }; Object object = getObject(objects, multiple); if (object == null) { return InstallOptionsDialog.INSTALLOPTIONS_ICON; } else { InstallOptionsElement element = getInstallOptionsElement(object); if (element != null) { return element.getIcon(); } else { return super.getImage(object); } } }
From source file:net.sf.eclipsensis.installoptions.properties.labelproviders.InstallOptionsElementLabelProvider.java
License:Open Source License
/** * @see org.eclipse.jface.viewers.ILabelProvider#getText(java.lang.Object) *//*from w w w. j a v a2 s. c o m*/ @Override public String getText(Object objects) { if (objects == null || objects.equals(StructuredSelection.EMPTY)) { return InstallOptionsPlugin.getResourceString("no.items.selected.message"); //$NON-NLS-1$ } final boolean multiple[] = { false }; final Object object = getObject(objects, multiple); if (object == null || ((IStructuredSelection) objects).size() > 1) { return InstallOptionsPlugin.getFormattedString("multiple.items.selected.message", //$NON-NLS-1$ new Object[] { new Integer(((IStructuredSelection) objects).size()) }); } else { InstallOptionsElement element = getInstallOptionsElement(object); if (element != null) { return element.getType(); } else { return super.getText(object); } } }