List of usage examples for org.eclipse.jface.viewers StructuredSelection getFirstElement
@Override
public Object getFirstElement()
From source file:ac.soton.fmusim.components.diagram.part.CustomAction.java
License:Open Source License
/** * @generated NOT// ww w .j a v a2s .c o m */ public Object execute(ExecutionEvent event) throws ExecutionException { ISelection selection = HandlerUtil.getCurrentSelection(event); StructuredSelection stselec = (StructuredSelection) selection; Object element = stselec.getFirstElement(); if (element instanceof FMUComponentEditPart) { FMUComponentEditPart editpart = (FMUComponentEditPart) element; FMUComponent comp = (FMUComponent) editpart.resolveSemanticElement(); String path = comp.getPath(); if (path != null) { WizardDialog dial = new WizardDialog(new Shell(), new ac.soton.fmusim.components.ui.wizardmenu.WizardStart()); dial.open(); } TransactionalEditingDomain editingDomain = editpart.getEditingDomain(); /*org.eclipse.emf.edit.ui.action.LoadResourceAction.LoadResourceDialog loadResourceDialog = new org.eclipse.emf.edit.ui.action.LoadResourceAction.LoadResourceDialog( shell, editingDomain); loadResourceDialog.open();*/ } return null; }
From source file:ac.soton.fmusim.components.diagram.part.LoadResourceAction2.java
License:Open Source License
/** * @generated NOT/*from www . ja v a 2 s. c o m*/ */ public Object execute(ExecutionEvent event) throws ExecutionException { ISelection selection = HandlerUtil.getCurrentSelection(event); StructuredSelection stselec = (StructuredSelection) selection; Object element = stselec.getFirstElement(); if (element instanceof FMUComponentEditPart) { FMUComponentEditPart editpart = (FMUComponentEditPart) element; FMUComponent comp = (FMUComponent) editpart.resolveSemanticElement(); String path = comp.getPath(); if (path != null) { WizardDialog dial = new WizardDialog(new Shell(), new ac.soton.fmusim.components.ui.wizardmenu.WizardStart()); dial.open(); } TransactionalEditingDomain editingDomain = editpart.getEditingDomain(); System.out.println(path); /*org.eclipse.emf.edit.ui.action.LoadResourceAction.LoadResourceDialog loadResourceDialog = new org.eclipse.emf.edit.ui.action.LoadResourceAction.LoadResourceDialog( shell, editingDomain); loadResourceDialog.open();*/ } return null; }
From source file:ar.com.tadp.prolog.core.actions.ConsultInConsoleAction.java
License:Open Source License
@Override public void run(final IAction action) { final PluginAction pAction = (PluginAction) action; final StructuredSelection selection = (StructuredSelection) pAction.getSelection(); final List<String> files = new LinkedList<String>(); IScriptProject project = null;//from ww w . j a v a 2 s . c om if (selection instanceof TreeSelection) { final TreeSelection treeSelection = (TreeSelection) selection; for (final TreePath path : treeSelection.getPaths()) { final Object segment = path.getLastSegment(); if (segment instanceof SourceModule) { final SourceModule sourceModule = (SourceModule) segment; files.add(sourceModule.getResource().getLocation().toPortableString()); project = sourceModule.getScriptProject(); } } } else { final FileEditorInput firstElement = (FileEditorInput) selection.getFirstElement(); files.add(firstElement.getFile().getLocation().toPortableString()); project = getProject(); } final PrologConsoleFactory consoleFactory = new PrologConsoleFactory(); consoleFactory.openConsole(files, project); }
From source file:at.medevit.ch.artikelstamm.elexis.common.ui.cv.ArtikelstammCodeSelectorFactory.java
License:Open Source License
@Override public ViewerConfigurer createViewerConfigurer(CommonViewer cv) { final CommonViewer cov = cv; cov.setSelectionChangedListener(selChange); FieldDescriptor<?>[] fields = { new FieldDescriptor<ArtikelstammItem>(DISP_NAME, ArtikelstammItem.FLD_DSCR, Typ.STRING, null), }; // add keyListener to search field Listener keyListener = new Listener() { @Override/* www . ja v a 2 s . co m*/ public void handleEvent(Event event) { if (event.type == eventType) { if (event.keyCode == SWT.CR || event.keyCode == SWT.KEYPAD_CR) { slp.fireChangedEvent(); } } } }; for (FieldDescriptor<?> fd : fields) { fd.setAssignedListener(eventType, keyListener); } slp = new SelectorPanelProvider(fields, true); slp.addChangeListener(new AControlFieldListener(slp)); Query<ArtikelstammItem> qbe = new Query<ArtikelstammItem>(ArtikelstammItem.class); ArtikelstammFlatDataLoader fdl = new ArtikelstammFlatDataLoader(cv, qbe, slp); List<IAction> actionList = new ArrayList<>(); populateSelectorPanel(slp, fdl, actionList); slp.addActions(actionList.toArray(new IAction[actionList.size()])); SimpleWidgetProvider swp = new SimpleWidgetProvider(SimpleWidgetProvider.TYPE_LAZYLIST, SWT.NONE, null); ILabelDecorator decorator = PlatformUI.getWorkbench().getDecoratorManager().getLabelDecorator(); String atcLang = CoreHub.globalCfg.get(PreferenceConstants.PREF_ATC_CODE_LANGUAGE, ATCCodeLanguageConstants.ATC_LANGUAGE_VAL_GERMAN); ATCArtikelstammDecoratingLabelProvider adlp = new ATCArtikelstammDecoratingLabelProvider( new LagerhaltungArtikelstammLabelProvider(), decorator, atcLang); ViewerConfigurer vc = new ViewerConfigurer(fdl, adlp, // new MedINDEXArticleControlFieldProvider(cv), slp, new ViewerConfigurer.DefaultButtonProvider(), swp, fdl); // the dropdown menu on the viewer MenuManager menu = new MenuManager(); menu.add(new Action(ch.elexis.core.ui.views.artikel.Messages.ArtikelContextMenu_propertiesAction) { { setImageDescriptor(Images.IMG_EDIT.getImageDescriptor()); setToolTipText(ch.elexis.core.ui.views.artikel.Messages.ArtikelContextMenu_propertiesTooltip); } @Override public void run() { StructuredSelection structuredSelection = new StructuredSelection(cov.getSelection()); Object element = structuredSelection.getFirstElement(); ArtikelstammDetailDialog dd = new ArtikelstammDetailDialog(UiDesk.getTopShell(), (IArtikelstammItem) element); dd.open(); } }); // menu.add(new AddVerrechenbarContributionItem(cov)); MenuManager subMenu = new MenuManager("ATC Gruppen-Selektion", Images.IMG_CATEGORY_GROUP.getImageDescriptor(), null) { @Override public boolean isDynamic() { return true; } @Override public boolean isVisible() { StructuredSelection structuredSelection = new StructuredSelection(cov.getSelection()); Object element = structuredSelection.getFirstElement(); if (element instanceof ArtikelstammItem) { ArtikelstammItem ai = (ArtikelstammItem) element; return (ai.getATCCode() != null && ai.getATCCode().length() > 0); } return false; } }; subMenu.add(new ATCMenuContributionItem(cov, fdl)); menu.add(subMenu); menu.add(tvfa); menu.add(new Separator()); menu.add(new VATMenuContributionItem(cov)); cv.setContextMenu(menu); return vc; }
From source file:at.medevit.ch.artikelstamm.elexis.common.ui.cv.ArtikelstammFlatDataLoader.java
License:Open Source License
@Override public void doubleClick(DoubleClickEvent event) { StructuredSelection selection = (StructuredSelection) event.getSelection(); if (selection.getFirstElement() == null) return;//from w ww . j a v a 2 s .c o m if (selection.getFirstElement() instanceof ATCCode) { filterValueStore = slp.getValues()[0]; slp.clearValues(); ATCCode a = (ATCCode) selection.getFirstElement(); setAtcQueryFilterValue(a.atcCode); } else if (selection.getFirstElement() instanceof ATCFilterInfoListElement) { slp.clearValues(); ActiveControl ac = slp.getPanel().getControls().get(0); ac.setText((filterValueStore != null) ? filterValueStore : ""); setAtcQueryFilterValue(null); } }
From source file:at.medevit.ch.artikelstamm.elexis.common.ui.cv.ATCMenuContributionItem.java
License:Open Source License
@Override public void fill(Menu menu, int index) { StructuredSelection structuredSelection = new StructuredSelection(cov.getSelection()); Object element = structuredSelection.getFirstElement(); ATCCodeService atcCodeService = ATCCodeServiceConsumer.getATCCodeService(); if (atcCodeService == null) return;/*from w ww . j a v a 2 s . co m*/ if (element instanceof ArtikelstammItem) { final ArtikelstammItem ai = (ArtikelstammItem) element; List<ATCCode> atcHierarchy = atcCodeService.getHierarchyForATCCode(ai.getATCCode()); for (ATCCode atcCode : atcHierarchy) { MenuItem temp = new MenuItem(menu, SWT.PUSH); if (prefAtcLanguage.equals(ATCCodeLanguageConstants.ATC_LANGUAGE_VAL_GERMAN)) { temp.setText(atcCode.atcCode + " " + atcCode.name_german); } else { temp.setText(atcCode.atcCode + " " + atcCode.name); } final ATCCode tempC = atcCode; temp.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { fdl.setUseAtcQueryFilter(true); fdl.setAtcQueryFilterValue(tempC.atcCode); } }); } } }
From source file:at.medevit.ch.artikelstamm.elexis.common.ui.cv.VATMenuContributionItem.java
License:Open Source License
@Override public void fill(Menu menu, int index) { StructuredSelection structuredSelection = new StructuredSelection(cv.getSelection()); Object element = structuredSelection.getFirstElement(); if (element instanceof ArtikelstammItem) { final ArtikelstammItem ai = (ArtikelstammItem) element; VatInfo vatInfo = ai.getVatInfo(); MenuItem mi = new MenuItem(menu, SWT.None); mi.setText("MWSt. Satz fr Artikel festlegen"); mi.setEnabled(false);/* w w w .j ava 2s . c o m*/ MenuItem vatNormal = new MenuItem(menu, SWT.RADIO); vatNormal.setText("Normal"); vatNormal.setSelection(vatInfo.equals(VatInfo.VAT_CH_NOTMEDICAMENT)); vatNormal.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { if (vatNormal.getSelection()) { ai.overrideVatInfo(VatInfo.VAT_CH_NOTMEDICAMENT); } } }); MenuItem vatReduced = new MenuItem(menu, SWT.RADIO); vatReduced.setText("Reduziert"); vatReduced.setSelection(vatInfo.equals(VatInfo.VAT_CH_ISMEDICAMENT)); vatReduced.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { if (vatReduced.getSelection()) { ai.overrideVatInfo(VatInfo.VAT_CH_ISMEDICAMENT); } } }); MenuItem vatNone = new MenuItem(menu, SWT.RADIO); vatNone.setText("Keine (0%)"); vatNone.setSelection(vatInfo.equals(VatInfo.VAT_NONE)); vatNone.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { if (vatNone.getSelection()) { ai.overrideVatInfo(VatInfo.VAT_NONE); } } }); } }
From source file:at.medevit.elexis.inbox.ui.part.InboxView.java
License:Open Source License
@Override public void createPartControl(Composite parent) { Composite composite = new Composite(parent, SWT.NONE); composite.setLayout(new GridLayout(1, false)); Composite filterComposite = new Composite(composite, SWT.NONE); GridData data = new GridData(GridData.FILL_HORIZONTAL); filterComposite.setLayoutData(data); filterComposite.setLayout(new GridLayout(2, false)); filterText = new Text(filterComposite, SWT.SEARCH); filterText.setMessage("Filter"); data = new GridData(GridData.FILL_HORIZONTAL); filterText.setLayoutData(data);/*ww w . j av a 2s .c om*/ filterText.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) { if (filterText.getText().length() > 1) { filter.setSearchText(filterText.getText()); viewer.refresh(); } else { filter.setSearchText(""); viewer.refresh(); } } }); ToolBarManager menuManager = new ToolBarManager(SWT.FLAT | SWT.HORIZONTAL | SWT.WRAP); menuManager.createControl(filterComposite); viewer = new CheckboxTreeViewer(composite, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER); GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1); viewer.getControl().setLayoutData(gd); ViewerFilter[] filters = new ViewerFilter[1]; filters[0] = filter; viewer.setFilters(filters); contentProvider = new InboxElementContentProvider(); viewer.setContentProvider(contentProvider); viewer.setLabelProvider(new InboxElementLabelProvider()); viewer.addCheckStateListener(new ICheckStateListener() { public void checkStateChanged(CheckStateChangedEvent event) { if (event.getElement() instanceof PatientInboxElements) { PatientInboxElements patientInbox = (PatientInboxElements) event.getElement(); for (InboxElement inboxElement : patientInbox.getElements()) { if (!filter.isActive() || filter.isSelect(inboxElement)) { State newState = toggleInboxElementState(inboxElement); if (newState == State.NEW) { viewer.setChecked(inboxElement, false); } else { viewer.setChecked(inboxElement, true); } contentProvider.refreshElement(inboxElement); } } contentProvider.refreshElement(patientInbox); } else if (event.getElement() instanceof InboxElement) { InboxElement inboxElement = (InboxElement) event.getElement(); if (!filter.isActive() || filter.isSelect(inboxElement)) { toggleInboxElementState(inboxElement); contentProvider.refreshElement(inboxElement); } } viewer.refresh(false); } }); viewer.addDoubleClickListener(new IDoubleClickListener() { @Override public void doubleClick(DoubleClickEvent event) { StructuredSelection selection = (StructuredSelection) viewer.getSelection(); if (!selection.isEmpty()) { Object selectedObj = selection.getFirstElement(); if (selectedObj instanceof InboxElement) { InboxElementUiExtension extension = new InboxElementUiExtension(); extension.fireDoubleClicked((InboxElement) selectedObj); } } } }); viewer.addSelectionChangedListener(new ISelectionChangedListener() { @Override public void selectionChanged(SelectionChangedEvent event) { ISelection selection = event.getSelection(); if (selection instanceof StructuredSelection && !selection.isEmpty()) { if (setAutoSelectPatient) { Object selectedElement = ((StructuredSelection) selection).getFirstElement(); if (selectedElement instanceof InboxElement) { ElexisEventDispatcher.fireSelectionEvent(((InboxElement) selectedElement).getPatient()); } else if (selectedElement instanceof PatientInboxElements) { ElexisEventDispatcher .fireSelectionEvent(((PatientInboxElements) selectedElement).getPatient()); } } } } }); final Transfer[] dropTransferTypes = new Transfer[] { FileTransfer.getInstance() }; viewer.addDropSupport(DND.DROP_COPY, dropTransferTypes, new DropTargetAdapter() { @Override public void dragEnter(DropTargetEvent event) { event.detail = DND.DROP_COPY; } @Override public void drop(DropTargetEvent event) { if (dropTransferTypes[0].isSupportedType(event.currentDataType)) { String[] files = (String[]) event.data; Patient patient = null; if (event.item != null) { Object data = event.item.getData(); if (data instanceof InboxElement) { patient = ((InboxElement) data).getPatient(); } else if (data instanceof PatientInboxElements) { patient = ((PatientInboxElements) data).getPatient(); } } if (patient == null) { // fallback patient = ElexisEventDispatcher.getSelectedPatient(); } if (patient != null) { if (files != null) { for (String file : files) { try { InboxServiceComponent.getService().createInboxElement(patient, ElexisEventDispatcher.getSelectedMandator(), file, true); } catch (Exception e) { LoggerFactory.getLogger(InboxView.class).warn("drop error", e); } } } viewer.refresh(); } else { MessageDialog.openWarning(Display.getCurrent().getActiveShell(), "Warnung", "Bitte whlen Sie zuerst einen Patienten aus."); } } } }); addFilterActions(menuManager); InboxServiceComponent.getService().addUpdateListener(new IInboxUpdateListener() { public void update(final InboxElement element) { Display.getDefault().asyncExec(new Runnable() { public void run() { contentProvider.refreshElement(element); viewer.refresh(); } }); } }); reload(); MenuManager ctxtMenuManager = new MenuManager(); Menu menu = ctxtMenuManager.createContextMenu(viewer.getTree()); viewer.getTree().setMenu(menu); getSite().registerContextMenu(ctxtMenuManager, viewer); ElexisEventDispatcher.getInstance().addListeners(mandantChanged); getSite().setSelectionProvider(viewer); setAutoSelectPatientState(CoreHub.userCfg.get(Preferences.INBOX_PATIENT_AUTOSELECT, false)); }
From source file:at.spardat.xma.guidesign.presentation.GuidesignEditor.java
License:Open Source License
/** * Handles what to do with changed resources on activation. *//*from w w w.j ava2s . c om*/ protected void handleChangedResources(Resource changedResource) { if (!isDirty() || handleDirtyConflict()) { // remember old selection before we reload the model ISelection isel = getSelection(); Resource mainResource = (Resource) editingDomain.getResourceSet().getResources().get(0); //for (Iterator i = changedResources.iterator(); i.hasNext(); ) { Resource resource = changedResource; // main resource changed? boolean isMainRes = mainResource.equals(resource); if (resource.isLoaded()) { resource.unload(); } try { resource.load(Collections.EMPTY_MAP); component = (XMAComponent) resource.getContents().get(0); } catch (IOException exception) { GUIDesignerPlugin.INSTANCE.log(exception); } // main resource changed? if (isMainRes) { // Determine the new selection final ISelection newSel; if (isel instanceof StructuredSelection) { EList eList = resource.getContents(); newSel = createNewSelection((StructuredSelection) isel, eList); } else { newSel = StructuredSelection.EMPTY; } // Take the new selection as input when possible (to avoid flickering) Object input = resource; if (newSel instanceof StructuredSelection) { StructuredSelection structSel = (StructuredSelection) newSel; if (structSel.getFirstElement() instanceof XMAWidget) { input = (XMAWidget) structSel.getFirstElement(); } } // force viewer to reload graphViewer.invalidateOldInput(); graphViewer.setInput(input); // we only care about structured selections (there should not be somethin else) if (isel instanceof StructuredSelection) { // asyncExec to avoid timing problems getSite().getShell().getDisplay().asyncExec(new Runnable() { public void run() { //set the selection to the composite setSelection(newSel); } }); } } //} ((BasicCommandStack) editingDomain.getCommandStack()).saveIsDone(); dirty = false; firePropertyChange(IEditorPart.PROP_DIRTY); } }
From source file:bndtools.jareditor.internal.JARContentTreePart.java
License:Open Source License
public JARContentTreePart(final Composite parent, final IManagedForm managedForm) { this.managedForm = managedForm; FormToolkit toolkit = managedForm.getToolkit(); Section section = toolkit.createSection(parent, ExpandableComposite.TITLE_BAR | ExpandableComposite.EXPANDED); section.setText("Content Tree"); tree = toolkit.createTree(section, SWT.FULL_SELECTION | SWT.SINGLE); tree.setData(FormToolkit.KEY_DRAW_BORDER, FormToolkit.TREE_BORDER); section.setClient(tree);/* w ww .j a v a 2 s . com*/ toolkit.paintBordersFor(section); viewer = new TreeViewer(tree); viewer.setContentProvider(contentProvider); viewer.setLabelProvider(new JARTreeLabelProvider()); managedForm.addPart(this); viewer.addSelectionChangedListener(new ISelectionChangedListener() { @Override public void selectionChanged(final SelectionChangedEvent event) { JARContentTreePart.this.managedForm.fireSelectionChanged(JARContentTreePart.this, event.getSelection()); } }); viewer.addDoubleClickListener(new IDoubleClickListener() { @Override public void doubleClick(final DoubleClickEvent event) { StructuredSelection selection = (StructuredSelection) event.getSelection(); ZipTreeNode node = (ZipTreeNode) selection.getFirstElement(); if (node.hasChildren()) { viewer.setExpandedState(node, !viewer.getExpandedState(node)); } } }); parent.setLayout(new GridLayout()); section.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); }