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:com.nokia.tools.variant.editor.summary.ImageGallery.java
License:Open Source License
public ISelection getSelection() { if (selected == null) { return StructuredSelection.EMPTY; } else {/*from w ww .j a va 2 s .c o m*/ return new StructuredSelection(selected.getData()); } }
From source file:com.nokia.tools.variant.navigator.views.NavigatorViewer.java
License:Open Source License
public NavigatorViewer(Composite parent) { scrolled = new ScrolledComposite(parent, SWT.V_SCROLL); scrolled.setExpandHorizontal(true);/* ww w. java 2 s . c o m*/ scrolled.setExpandVertical(true); control = new NavigatorComposite(scrolled, SWT.NONE, this); scrolled.setContent(control); scrolled.addControlListener(new ControlAdapter() { @Override public void controlResized(ControlEvent e) { Point size; Rectangle ca = ((ScrolledComposite) control.getParent()).getClientArea(); size = control.computeSize(ca.width, SWT.DEFAULT); // size.y = Math.max(size.y, getSize().y); ((ScrolledComposite) control.getParent()).setMinSize(size); control.setSize(size); control.layout(true, true); control.redraw(); } }); scrolled.getVerticalBar().setIncrement(new PixelConverter(scrolled).convertHeightInCharsToPixels(1)); control.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { Object selected = null; if (e.item != null) { selected = e.item.getData(); } ISelection sel = selected == null ? StructuredSelection.EMPTY : new StructuredSelection(selected); fireSelectionChanged(new SelectionChangedEvent(NavigatorViewer.this, sel)); } }); }
From source file:com.nokia.tools.variant.preview.ui.PreviewViewPage.java
License:Open Source License
@Override public void dispose() { setSelection(StructuredSelection.EMPTY); listeners.clear();// w w w . ja v a 2 s .c o m getSite().setSelectionProvider(null); disposePreviewControl(); if (contributor != null) { contributor = null; } if (topComposite != null) { topComposite.dispose(); topComposite = null; } super.dispose(); }
From source file:com.nokia.tools.variant.resourcelibrary.views.ResourceLibraryPage.java
License:Open Source License
/** * This is a callback that will allow us to create the viewer and initialize * it.// w w w . ja v a 2 s . co m */ public void createControl(Composite parent) { // Create new composite for nesting the tree & its layout data treeComposite = new Composite(parent, SWT.NONE); // Create tree viewer viewer = new TreeViewer(treeComposite, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL); viewer.setContentProvider(provider); viewer.setLabelProvider(new ResourceLibraryTableLabelProvider()); final Tree resourceTree = viewer.getTree(); resourceTree.addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent event) { actionGroup.handleKeyPressed(event); } }); // Create columns TreeColumn nameCol = new TreeColumn(resourceTree, SWT.NONE); nameCol.setAlignment(SWT.LEFT); nameCol.setText(NAME_COLUMN_TEXT); nameCol.setWidth(150); TreeColumn typeCol = new TreeColumn(resourceTree, SWT.NONE); typeCol.setAlignment(SWT.RIGHT); typeCol.setText(SIZE_COLUMN_TEXT); typeCol.setWidth(50); TreeColumn noteCol = new TreeColumn(resourceTree, SWT.NONE); noteCol.setAlignment(SWT.CENTER); noteCol.setText(NOTE_COLUMN_TEXT); noteCol.setWidth(9); // Hook up column selection listeners for sorting sortProvider = new SimpleResourceComparator(viewer); viewer.setComparator(sortProvider); nameCol.addSelectionListener(sortProvider); typeCol.addSelectionListener(sortProvider); noteCol.addSelectionListener(sortProvider); // Set tree layout properties resourceTree.setHeaderVisible(true); resourceTree.setLinesVisible(true); TreeColumnLayout treeLayout = new TreeColumnLayout(); treeComposite.setLayout(treeLayout); treeLayout.setColumnData(nameCol, new ColumnWeightData(80, 100, true)); treeLayout.setColumnData(typeCol, new ColumnWeightData(20, 50, true)); treeLayout.setColumnData(noteCol, new ColumnWeightData(9, 9, true)); // Fetch a handle to file system. // viewer.setInput(this.getSite()); hookDoubleClickAction(); // Add drag & drop capability initDragAndDrop(); // Set the selection to first element in the tree resorceModelRoot = (ResourceModelRoot) contributor.getAdapter(ResourceModelRoot.class); if (resorceModelRoot != null) { viewer.setInput(resorceModelRoot); } // Set selection provider viewer.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(final SelectionChangedEvent event) { ISelection selection = createAdaptableSelection(event.getSelection()); sendSelectionEvent(selection); updateMainMenu(selection); } private void updateMainMenu(ISelection selection2) { if (selection2.isEmpty()) { actionGroup.getDeleteResourceAction().setEnabled(false); actionGroup.getCopyResourceAction().setEnabled(false); actionGroup.getMoveResourceAction().setEnabled(false); } else { if (selection2 instanceof IStructuredSelection) { IStructuredSelection structuredSelection = (IStructuredSelection) selection2; Object object = structuredSelection.getFirstElement(); if (object instanceof ResourceStorage) { ResourceStorage resourceStorage = (ResourceStorage) object; if (!resourceStorage.getFileSystemElement().isReadOnly()) { // actionGroup.getDeleteResourceAction() // .setEnabled(true); // actionGroup.getMoveResourceAction().setEnabled( // true); } actionGroup.getCopyResourceAction().setEnabled(true); } } } } }); viewer.addPostSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(final SelectionChangedEvent event) { sendPostSelectionEvent(createAdaptableSelection(event.getSelection())); } }); // Create context menu menuMgr = new MenuManager("#PopupMenu"); menuMgr.setRemoveAllWhenShown(true); menuMgr.addMenuListener(new IMenuListener() { public void menuAboutToShow(IMenuManager manager) { populateMenu(manager); } }); Menu menu = menuMgr.createContextMenu(viewer.getControl()); viewer.getControl().setMenu(menu); getSite().registerContextMenu("#PopupMenu", menuMgr, this); contributeToActionBars(); viewer.setSelection(StructuredSelection.EMPTY); final TreeEditor editor = new TreeEditor(viewer.getTree()); editor.horizontalAlignment = SWT.LEFT; editor.grabHorizontal = true; viewer.getControl().addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent event) { if (event.keyCode == SWT.F2 && event.stateMask == 0 && viewer.getTree().getSelectionCount() == 1) { event.doit = false; final TreeItem item = viewer.getTree().getSelection()[0]; final FileSystemElement fes = (FileSystemElement) item.getData(); if (!canRenameElement(fes)) { return; } final Text text = new Text(viewer.getTree(), SWT.NONE); text.setText(item.getText()); text.selectAll(); text.setFocus(); text.addFocusListener(new FocusAdapter() { public void focusLost(FocusEvent event) { updateElementName(fes, text.getText()); text.dispose(); } }); text.addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent event) { switch (event.keyCode) { case SWT.CR: updateElementName(fes, text.getText()); case SWT.ESC: text.dispose(); break; } } }); editor.setEditor(text, item); } } }); getCommandStack().addCommandStackEventListener(commandStackEventListener); }
From source file:com.nokia.tools.variant.resourcelibrary.views.ResourceLibraryPage.java
License:Open Source License
public ISelection getSelection() { if (viewer != null) { return createAdaptableSelection(viewer.getSelection()); } else {// w w w . ja v a 2 s. c o m return StructuredSelection.EMPTY; } }
From source file:com.nokia.tools.variant.resourcelibrary.views.ResourceLibraryPage.java
License:Open Source License
@Override public void init(IPageSite pageSite) { super.init(pageSite); this.actionGroup = new ResourceLibraryActionGroup(this); this.actionGroup.setContext(new ActionContext(StructuredSelection.EMPTY)); pageSite.setSelectionProvider(this); pageSite.getActionBars().setGlobalActionHandler("cut", actionGroup.getMoveResourceAction()); pageSite.getActionBars().setGlobalActionHandler("delete", actionGroup.getDeleteResourceAction()); pageSite.getActionBars().setGlobalActionHandler("copy", actionGroup.getCopyResourceAction()); }
From source file:com.nokia.tools.variant.resourcelibrary.views.ResourceLibraryPage.java
License:Open Source License
/** * Synchronize resource view selection with the give selection object... *///www .j a v a2s. c o m public void selectionChanged(IWorkbenchPart part, ISelection selection) { if (part != contributor) { return; } Object firstElement = ((IStructuredSelection) selection).getFirstElement(); String sourcePath = null; if (firstElement instanceof FilePath) { FilePath setting = (FilePath) firstElement; FilePath sourceFilePath = setting.getParent().getSourceFilePath(); if (setting != sourceFilePath) { // there was selected target path to which we don't react return; } String choosenOption = sourceFilePath.getChoosenOption(); if (choosenOption != null) { sourcePath = choosenOption; } else { sourcePath = sourceFilePath.getPath(); if (sourcePath == null) { sourcePath = setting.getParent().getSourceFilePath().getDefaultPath(); } } } else if (firstElement instanceof SimpleSetting) { SimpleSetting ss = (SimpleSetting) firstElement; switch (ss.getType()) { case FILE: case FOLDER: case SIMPLE_FILE: case SIMPLE_FOLDER: String choosenOption = ss.getChoosenOption(); if (choosenOption != null) { sourcePath = choosenOption; } else { sourcePath = ss.getValue(); } if (sourcePath == null) { sourcePath = ss.getDefaultValue(); } } } if (sourcePath != null) { FileSystemElement element = ResourceUtil.getFileSystemElement((ResourceModelRoot) viewer.getInput(), sourcePath); if (element != null) { viewer.setSelection(new StructuredSelection(element), true); viewer.expandToLevel(element, 1); } else { viewer.setSelection(new StructuredSelection(StructuredSelection.EMPTY), true); } } }
From source file:com.nokia.tools.variant.viewer.viewer.SettingsViewer.java
License:Open Source License
/** * Deselect all widgets and fire selection changed event *///from w w w . j ava 2 s . c o m public void deselectAllWidgets() { internalDeselectAllWidgets(); fireSelectionChanged(new SelectionChangedEvent(SettingsViewer.this, StructuredSelection.EMPTY)); }
From source file:com.nokia.tools.vct.confml.editor.view.ViewsEditor.java
License:Open Source License
private void createContextMenu() { final OpenConfMLViewEditor openViewAction = new OpenConfMLViewEditor(this); final DeleteAction deleteAction = new DeleteAction(this); final RenameAction renameAction = new RenameAction(getCommandStack(), viewTv); final AddGroupAction addSubGroupAction = new AddGroupAction(this, GroupType.CHILD_GROUP); final AddGroupAction addGroupAction = new AddGroupAction(this, GroupType.SIBLING_GROUP); final PropertiesAction propertiesAction = new PropertiesAction(viewTv); final ExpandSettingRefAction expandSettingRef = new ExpandSettingRefAction(this); final AddPropertyAction addPropertyAction = new AddPropertyAction(this); final AddOptionAction addOptionAction = new AddOptionAction(this); final MenuManager subMenu = new MenuManager(Messages.Add_new); subMenu.addMenuListener(new IMenuListener() { public void menuAboutToShow(IMenuManager manager) { if (viewTv.getSelection().equals(StructuredSelection.EMPTY)) { return; }// w ww. ja v a 2s .co m TreeItem te = viewTv.getTree().getSelection()[0]; if (te.getData() instanceof EView) { subMenu.removeAll(); subMenu.add(addSubGroupAction); if (te.getParentItem() == null) addSubGroupAction.setEnabled(true); else addSubGroupAction.setEnabled(false); } else if ((te.getData() instanceof EGroup) && (te.getParentItem().getData() instanceof EView)) { subMenu.removeAll(); subMenu.add(addSubGroupAction); subMenu.add(addGroupAction); addSubGroupAction.setEnabled(true); } else if ((te.getData() instanceof ESettingRef)) { subMenu.removeAll(); manager.add(addOptionAction); manager.add(addPropertyAction); } else { subMenu.removeAll(); subMenu.add(addGroupAction); } } }); subMenu.add(addGroupAction); MenuManager popupMenu = new MenuManager(); popupMenu.setRemoveAllWhenShown(true); popupMenu.addMenuListener(new IMenuListener() { public void menuAboutToShow(IMenuManager manager) { if (viewTv.getSelection().equals(StructuredSelection.EMPTY)) { return; } TreeItem te = viewTv.getTree().getSelection()[0]; if ((te.getData() instanceof EView)) { // View manager.removeAll(); if (isFromRootView((EView) te.getData())) { manager.add(subMenu); manager.add(new Separator()); } else if (isViewUnderRoot((EView) te.getData())) { manager.add(openViewAction); manager.add(deleteAction); } else manager.add(openViewAction); manager.add(propertiesAction); } else if ((te.getData() instanceof EGroup) // Group && (te.getParentItem().getData() instanceof EView)) { manager.removeAll(); if (isFromRootView((EGroup) te.getData())) { manager.add(subMenu); manager.add(renameAction); manager.add(deleteAction); manager.add(new Separator()); } manager.add(propertiesAction); } else if ((te.getData() instanceof EGroup)) { // SubGroup manager.removeAll(); if (isFromRootView((EGroup) te.getData())) { manager.add(subMenu); manager.add(renameAction); manager.add(deleteAction); manager.add(new Separator()); } manager.add(propertiesAction); } else if ((te.getData() instanceof ERefOption)) { // Option manager.removeAll(); if (isFromRootView((ERefOption) te.getData())) { manager.add(deleteAction); manager.add(new Separator()); } manager.add(propertiesAction); } else if ((te.getData() instanceof ERefProperty)) { // Option manager.removeAll(); if (isFromRootView((ERefProperty) te.getData())) { manager.add(deleteAction); manager.add(new Separator()); } manager.add(propertiesAction); } else if ((te.getData() instanceof ESettingRef)) { // Ref manager.removeAll(); if (isFromRootView((ESettingRef) te.getData())) { manager.add(subMenu); manager.add(deleteAction); ESettingRef ref = (ESettingRef) te.getData(); if (ref.getSettingId().equals("*")) { manager.add(expandSettingRef); } else { } manager.add(new Separator()); } manager.add(propertiesAction); } else { // Setting manager.removeAll(); // manager.add(deleteAction); //manager.add(new Separator()); manager.add(propertiesAction); } } }); Menu menu = popupMenu.createContextMenu(viewTv.getControl()); viewTv.getControl().setMenu(menu); }
From source file:com.pip.propertysheet.PropertySheetViewer.java
License:Open Source License
/** * The <code>PropertySheetViewer</code> implementation of this * <code>ISelectionProvider</code> method returns the result as a * <code>StructuredSelection</code>. * <p>/*from w w w . j av a2 s . c om*/ * Note that this method only includes <code>IPropertySheetEntry</code> in * the selection (no categories). * </p> */ public ISelection getSelection() { if (tree.getSelectionCount() == 0) { return StructuredSelection.EMPTY; } TreeItem[] sel = tree.getSelection(); List entries = new ArrayList(sel.length); for (int i = 0; i < sel.length; i++) { TreeItem ti = sel[i]; Object data = ti.getData(); if (data instanceof IPropertySheetEntry) { entries.add(data); } } return new StructuredSelection(entries); }