List of usage examples for org.eclipse.jface.viewers IStructuredSelection size
public int size();
From source file:com.openlegacy.enterprise.ide.eclipse.editors.pages.details.rpc.FieldsRpcEnumFieldDetailsPage.java
License:Open Source License
private void createEnumValuesSection(FormToolkit toolkit, Composite parent) { Section section = toolkit.createSection(parent, ExpandableComposite.TWISTIE | Section.DESCRIPTION); section.setActiveToggleColor(toolkit.getHyperlinkGroup().getActiveForeground()); section.setToggleColor(toolkit.getColors().getColor(IFormColors.SEPARATOR)); toolkit.createCompositeSeparator(section); Composite client = toolkit.createComposite(section, SWT.WRAP); GridLayout layout = new GridLayout(); layout.numColumns = 2;//from w w w . j ava 2s . c o m client.setLayout(layout); // create table Table t = createTable(toolkit, client); tableViewer = new TableViewer(t); tableViewer.setContentProvider(new RpcEnumValuesTableContentProvider()); tableViewer.setInput(fieldModel); tableViewer.setData(FormRowCreator.ID_KEY, Constants.ENUM_FIELD_ENTRIES); createColumns(toolkit, tableViewer); // create buttons Composite panel = toolkit.createComposite(client); GridLayout gl = new GridLayout(); gl.numColumns = 1; gl.marginWidth = 2; gl.marginHeight = 0; panel.setLayout(gl); GridData gd = new GridData(GridData.FILL_VERTICAL); gd.widthHint = 100; panel.setLayoutData(gd); Button b = toolkit.createButton(panel, Messages.getString("Button.add"), SWT.PUSH); //$NON-NLS-1$ gd = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING); b.setLayoutData(gd); b.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { EnumEntryModel enumEntryModel = new EnumEntryModel(fieldModel); enumEntryModel.setName( MessageFormat.format("{0}{1}", fieldModel.getFieldName(), getSeedForNewEnumEntry())); fieldModel.getEntries().add(enumEntryModel); tableViewer.setInput(fieldModel); updateModel(Constants.ENUM_FIELD_ENTRIES); tableViewer.getTable().select(tableViewer.getTable().getItemCount() - 1); } }); b = toolkit.createButton(panel, Messages.getString("Button.remove"), SWT.PUSH); //$NON-NLS-1$ gd = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING); b.setLayoutData(gd); b.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { IStructuredSelection selection = (IStructuredSelection) tableViewer.getSelection(); if (selection.size() == 1) { EnumEntryModel model = (EnumEntryModel) selection.getFirstElement(); fieldModel.getEntries().remove(model); tableViewer.setInput(fieldModel); updateModel(Constants.ENUM_FIELD_ENTRIES); tableViewer.getTable().select(tableViewer.getTable().getItemCount() - 1); } } }); section.setText(Messages.getString("rpc.field.enum.properties"));//$NON-NLS-1$ section.setClient(client); section.setExpanded(true); gd = new GridData(GridData.FILL_BOTH); gd.horizontalSpan = 2; section.setLayoutData(gd); }
From source file:com.openlegacy.enterprise.ide.eclipse.editors.pages.jpa.ActionsPape.java
License:Open Source License
private void addPanelWithButtons(FormToolkit toolkit, Composite parent) { Composite panel = toolkit.createComposite(parent); GridLayout gl = new GridLayout(); gl.numColumns = 1;/*from www.j a v a2 s.c o m*/ gl.marginWidth = 2; gl.marginHeight = 0; panel.setLayout(gl); GridData gd = new GridData(GridData.FILL_VERTICAL); gd.widthHint = 100; panel.setLayoutData(gd); // add button Button addButton = toolkit.createButton(panel, Messages.getString("Button.add"), SWT.PUSH);//$NON-NLS-1$ gd = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING); addButton.setLayoutData(gd); addButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { actionsModel.getActions().add(new ActionModel("", "", true, "", ""));//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ tableViewer.setInput(actionsModel); updateModel(); tableViewer.getTable().select(tableViewer.getTable().getItemCount() - 1); } }); // remove button Button removeButton = toolkit.createButton(panel, Messages.getString("Button.remove"), SWT.PUSH);//$NON-NLS-1$ gd = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING); removeButton.setLayoutData(gd); removeButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { IStructuredSelection structuredSelection = (IStructuredSelection) tableViewer.getSelection(); if (structuredSelection.size() == 1) { ActionModel model = (ActionModel) structuredSelection.getFirstElement(); actionsModel.getActions().remove(model); tableViewer.setInput(actionsModel); updateModel(); tableViewer.getTable().select(tableViewer.getTable().getItemCount() - 1); } } }); }
From source file:com.opera.widgets.ui.editor.IconDetailsPage.java
License:Open Source License
@Override public void selectionChanged(IFormPart part, ISelection selection) { IStructuredSelection sel = (IStructuredSelection) selection; if (sel.size() == 1) { fIcon = (Icon) sel.getFirstElement(); }// ww w . j a v a 2 s . c o m update(); }
From source file:com.python.pydev.refactoring.refactorer.search.copied.NewTextSearchActionGroup.java
License:Open Source License
private void addOpenWithMenu(IMenuManager menu, IStructuredSelection selection) { if (selection == null) { return;/*from w w w. jav a 2s .c o m*/ } fOpenAction.selectionChanged(selection); if (fOpenAction.isEnabled()) { menu.appendToGroup(IContextMenuConstants.GROUP_OPEN, fOpenAction); } if (selection.size() != 1) { return; } Object o = selection.getFirstElement(); if (!(o instanceof IAdaptable)) { return; } // Create menu IMenuManager submenu = new MenuManager(SearchMessages.OpenWithMenu_label); submenu.add(new OpenWithMenu(fPage, (IAdaptable) o)); // Add the submenu. menu.appendToGroup(IContextMenuConstants.GROUP_OPEN, submenu); }
From source file:com.python.pydev.ui.search.ReplaceDialog2.java
License:Open Source License
private void selectEntry(Match marker) { ISelection sel = fPage.getViewer().getSelection(); if (!(sel instanceof IStructuredSelection)) return;//w ww . j a va 2s . c o m IStructuredSelection ss = (IStructuredSelection) sel; IFile file = (IFile) marker.getElement(); if (ss.size() == 1 && file.equals(ss.getFirstElement())) return; fPage.getViewer().setSelection(new StructuredSelection(marker.getElement())); }
From source file:com.quantcomponents.ui.marketdata.MarketDataManagersView.java
License:Open Source License
@Override public void createPartControl(Composite parent) { this.parent = parent; dataManagerTree = new TreeViewer(parent); dataManagerTree.setContentProvider(new BaseWorkbenchContentProvider() { @SuppressWarnings("unchecked") @Override/* www . j av a 2 s.co m*/ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { super.inputChanged(viewer, oldInput, newInput); if (oldInput != null) { ((IMonitorableContainer<MarketDataManagerPresentationWrapper>) oldInput) .removeListener(marketDataManagerContainerListener); } if (newInput != null) { IMonitorableContainer<MarketDataManagerPresentationWrapper> container = (IMonitorableContainer<MarketDataManagerPresentationWrapper>) newInput; container.addListener(marketDataManagerContainerListener); for (MarketDataManagerPresentationWrapper manager : container.getElements()) { marketDataManagerContainerListener.onElementAdded(manager); } } } }); ILabelDecorator decorator = PlatformUI.getWorkbench().getDecoratorManager().getLabelDecorator(); dataManagerTree.setLabelProvider(new DecoratingLabelProvider(new WorkbenchLabelProvider(), decorator)); Platform.getAdapterManager().registerAdapters(adapterFactory, IMarketDataManagerContainer.class); Platform.getAdapterManager().registerAdapters(adapterFactory, MarketDataManagerPresentationWrapper.class); Platform.getAdapterManager().registerAdapters(adapterFactory, StockDatabasePresentationWrapper.class); dataManagerTree.setInput(marketDataManagerContainer); dataManagerTree.addSelectionChangedListener(new ISelectionChangedListener() { @Override public void selectionChanged(SelectionChangedEvent event) { multipleStockDatabaseSelection.clear(); ISelection selection = event.getSelection(); if (selection instanceof IStructuredSelection) { IStructuredSelection structuredSelection = (IStructuredSelection) selection; Object o = structuredSelection.getFirstElement(); if (o instanceof MarketDataManagerPresentationWrapper) { selectedMarketDataManager = (MarketDataManagerPresentationWrapper) o; openViewAction.setEnabled(false); addStockDatabaseAction.setEnabled(true); removeStockDatabaseAction.setEnabled(false); if (selectedMarketDataManager instanceof RealTimeMarketDataManagerPresentationWrapper) { startAutoUpdateAction.setEnabled(false); stopAutoUpdateAction.setEnabled(false); } } else if (o instanceof StockDatabasePresentationWrapper) { openViewAction.setEnabled(true); addStockDatabaseAction.setEnabled(true); removeStockDatabaseAction.setEnabled(true); if (selectedMarketDataManager instanceof RealTimeMarketDataManagerPresentationWrapper) { startAutoUpdateAction.setEnabled(true); stopAutoUpdateAction.setEnabled(true); } if (structuredSelection.size() > 0) { Iterator<?> iterator = structuredSelection.iterator(); while (iterator.hasNext()) { Object sel = iterator.next(); if (sel instanceof StockDatabasePresentationWrapper) { StockDatabasePresentationWrapper stockDatabaseWrapper = (StockDatabasePresentationWrapper) sel; selectedMarketDataManager = stockDatabaseWrapper.getParent(); multipleStockDatabaseSelection.add(stockDatabaseWrapper); } } } } else { openViewAction.setEnabled(false); addStockDatabaseAction.setEnabled(false); removeStockDatabaseAction.setEnabled(false); startAutoUpdateAction.setEnabled(false); stopAutoUpdateAction.setEnabled(false); } } } }); dataManagerTree.addDoubleClickListener(new IDoubleClickListener() { @Override public void doubleClick(DoubleClickEvent event) { ISelection selection = event.getSelection(); if (selection instanceof IStructuredSelection) { IStructuredSelection structuredSelection = (IStructuredSelection) selection; Object o = structuredSelection.getFirstElement(); if (o instanceof StockDatabasePresentationWrapper) { StockDatabasePresentationWrapper selectedStockDatabase = (StockDatabasePresentationWrapper) o; try { getSite().getPage().showView(StockDatabaseChartView.MULTI_STOCK_DB_VIEW_ID, selectedStockDatabase.getPrettyName(), IWorkbenchPage.VIEW_VISIBLE); } catch (PartInitException e) { MessageDialog.openError(MarketDataManagersView.this.parent.getShell(), "Error", "A problem occurred while opening view for: " + selectedStockDatabase.getPrettyName() + "[" + LangUtils.exceptionMessage(e) + "]"); } } } } }); getSite().setSelectionProvider(dataManagerTree); hookGlobalActions(); createContextMenu(); }
From source file:com.questoid.sqlitebrowser.SqliteBrowserPluginStartup.java
License:Open Source License
private void createsqlitebrowserAction(final IWorkbenchPart part) { final IViewPart view = (IViewPart) part.getAdapter(IViewPart.class); if (view != null && view.getViewSite().getId().indexOf(FILEEXPLORERVIEW_ID) > -1) { if (!actionAdded) { actionAdded = true; //don't add action more than once createsqlitebrowserActionGui(view); // Listen to mTreeViewer SelectionChanged final DeviceExplorer mExplorer = (DeviceExplorer) com.questelement.api.reflection.PrivateAccessor .getPrivateField(view, "mExplorer"); final TreeViewer mTreeViewer = (TreeViewer) com.questelement.api.reflection.PrivateAccessor .getPrivateField(mExplorer, "mTreeViewer"); mTreeViewer.addSelectionChangedListener(new ISelectionChangedListener() { @Override/*from www. j a va2s. c o m*/ public void selectionChanged(SelectionChangedEvent event) { ISelection selection = event.getSelection(); if (selection.isEmpty()) { sqlitebrowserAction.setEnabled(false); return; } if (selection instanceof IStructuredSelection) { IStructuredSelection structuredSelection = (IStructuredSelection) selection; Object element = structuredSelection.getFirstElement(); if (element == null) return; if (element instanceof FileEntry) { if (structuredSelection.size() == 1 && SqliteUtil.isSqliteDbFile((FileEntry) element)) { sqlitebrowserAction.setEnabled(true); } else { sqlitebrowserAction.setEnabled(false); } } } } }); } } }
From source file:com.quui.tc.TCPage.java
License:Open Source License
/** * Tests if the current workbench selection is a suitable container to use. *///from w w w. jav a 2 s.c om private void initialize() { if (selection != null && selection.isEmpty() == false && selection instanceof IStructuredSelection) { IStructuredSelection ssel = (IStructuredSelection) selection; if (ssel.size() > 1) return; Object obj = ssel.getFirstElement(); if (obj instanceof IJavaProject) { containerTextWidget.setText(((IJavaProject) obj).getPath().toPortableString()); } problemTextWidget.setFocus(); } problemTextWidget.setText(""); }
From source file:com.rcpcompany.uibindings.utils.SelectionUtils.java
License:Open Source License
/** * Computes and returns a list with the objects of the selection that are - or can adapt to - * the specified base class.//from w w w . j av a 2s . co m * * @param <T> the type of the baseClass * @param selection the selection to handle * @param baseClass the wanted base class * @return a list with the found objects */ public static <T> List<T> computeSelection(ISelection selection, Class<T> baseClass) { if (!(selection instanceof IStructuredSelection)) return EMPTY_LIST; final IStructuredSelection ss = (IStructuredSelection) selection; List<T> list = null; for (final Iterator e = ss.iterator(); e.hasNext();) { final Object next = e.next(); T c = (T) Platform.getAdapterManager().getAdapter(next, baseClass); if (c != null) { // OK } else if (baseClass.isInstance(next)) { c = (T) next; } else if (next instanceof IAdaptable) { c = (T) ((IAdaptable) next).getAdapter(baseClass); } if (c != null) { if (list == null) { list = new ArrayList<T>(ss.size()); } list.add(c); } } if (list == null) return EMPTY_LIST; return list; }
From source file:com.rcpcompany.utils.selection.SelectionUtils.java
License:Open Source License
/** * Computes and returns a list with the objects of the selection that are - * or can adapt to - the specified base class. * //from w ww . j ava 2 s . co m * @param <T> * the type of the baseClass * @param selection * the selection to handle * @param baseClass * the wanted base class * @return a list with the found objects */ @SuppressWarnings("unchecked") public static <T> List<T> computeSelection(ISelection selection, Class<T> baseClass) { if (!(selection instanceof IStructuredSelection)) return Collections.EMPTY_LIST; final IStructuredSelection ss = (IStructuredSelection) selection; List<T> list = null; for (final Iterator<?> e = ss.iterator(); e.hasNext();) { final Object next = e.next(); T c = (T) Platform.getAdapterManager().getAdapter(next, baseClass); if (c != null) { // OK } else if (baseClass.isInstance(next)) { c = (T) next; } else if (next instanceof IAdaptable) { c = (T) ((IAdaptable) next).getAdapter(baseClass); } if (c != null) { if (list == null) { list = new ArrayList<T>(ss.size()); } list.add(c); } } if (list == null) return Collections.EMPTY_LIST; return list; }