List of usage examples for org.eclipse.jface.viewers IStructuredSelection getFirstElement
public Object getFirstElement();
null
if the selection is empty. From source file:ch.docbox.elexis.DocboxDocumentsView.java
License:Open Source License
@Override public void createPartControl(Composite parent) { table = new Table(parent, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION); String[] colLabels = getColumnLabels(); int columnWidth[] = getColumnWidth(); SortListener sortListener = new SortListener(); TableColumn[] cols = new TableColumn[colLabels.length]; for (int i = 0; i < colLabels.length; i++) { cols[i] = new TableColumn(table, SWT.NONE); cols[i].setWidth(columnWidth[i]); cols[i].setText(colLabels[i]);// w w w .j av a 2s .c om cols[i].setData(new Integer(i)); cols[i].addSelectionListener(sortListener); } table.setHeaderVisible(true); table.setLinesVisible(true); boldFont = createBoldFont(table.getFont()); tableViewer = new TableViewer(table); tableViewer.setContentProvider(new ViewContentProvider()); tableViewer.setLabelProvider(new ViewLabelProvider()); tableViewer.setSorter(new Sorter()); tableViewer.setUseHashlookup(true); Transfer[] transferTypes = new Transfer[] { FileTransfer.getInstance() }; tableViewer.addDragSupport(DND.DROP_COPY, transferTypes, new DragSourceListener() { private CdaMessage cdaMessage; @Override public void dragStart(DragSourceEvent event) { event.doit = true; event.detail = DND.DROP_MOVE; log.log("dragStart", Log.DEBUGMSG); } @Override public void dragSetData(DragSourceEvent event) { ISelection selection = tableViewer.getSelection(); Object obj = ((IStructuredSelection) selection).getFirstElement(); if (obj != null) { cdaMessage = (CdaMessage) obj; String files[] = cdaMessage.getFiles(); for (int i = 0; i < files.length; ++i) { files[i] = cdaMessage.getPath(files[i]); log.log("dragSetData " + files[i], Log.DEBUGMSG); } event.data = files; } } @Override public void dragFinished(DragSourceEvent event) { log.log("dragFinished", Log.DEBUGMSG); if (event.detail == 1) { cdaMessage.setAssignedToOmnivore(); } } }); selectionEvent(CoreHub.actUser); tableViewer.setInput(getViewSite()); actionOpenAttachments = new Action(Messages.DocboxDocumentsView_Action_AttachmentsOpen) { public void run() { ISelection selection = tableViewer.getSelection(); Object obj = ((IStructuredSelection) selection).getFirstElement(); CdaMessage cdaMessage = (CdaMessage) obj; cdaMessage.execute(); } }; actionShowCdaDocument = new Action(Messages.DocboxDocumentsView_Action_ShowCdaDocument) { public void run() { ISelection selection = tableViewer.getSelection(); Object obj = ((IStructuredSelection) selection).getFirstElement(); CdaMessage cdaMessage = (CdaMessage) obj; TextTransfer textTransfer = TextTransfer.getInstance(); final Clipboard cb = new Clipboard(UiDesk.getDisplay()); cb.setContents(new Object[] { cdaMessage.getCda() }, new Transfer[] { textTransfer }); } }; actionDeleteDocument = new Action(Messages.DocboxDocumentsView_Action_Delete) { public void run() { ISelection selection = tableViewer.getSelection(); Object obj = ((IStructuredSelection) selection).getFirstElement(); if (obj != null) { CdaMessage cdaMessage = (CdaMessage) obj; MessageBox messageBox = new MessageBox(UiDesk.getDisplay().getActiveShell(), SWT.ICON_WARNING | SWT.OK | SWT.CANCEL); messageBox.setText(Messages.DocboxDocumentsView_Action_Delete); messageBox.setMessage(String.format(Messages.DocboxDocumentsView_Action_DeleteConfirmMsg, cdaMessage.getTitle())); if (messageBox.open() == SWT.OK) { cdaMessage.deleteDocs(); tableViewer.refresh(); } } } }; actionCreatePatient = new Action(Messages.DocboxDocumentsView_Action_CreatePatient) { public void run() { ISelection selection = tableViewer.getSelection(); Object obj = ((IStructuredSelection) selection).getFirstElement(); if (obj != null) { CdaMessage cdaMessage = (CdaMessage) obj; CdaChXPath xpath = new CdaChXPath(); String name = cdaMessage.getCda(); if (name != null) { xpath.setPatientDocument(cdaMessage.getCda()); String family = xpath.getPatientLastName(); String given = xpath.getPatientFirstName(); String streetAdressLine = xpath.getPatientStreet(); String plz = xpath.getPatientPlz(); String city = xpath.getPatientCity(); Patient p = new Patient(family, given, "", ""); p.set(Person.NAME, family); p.set(Person.FIRSTNAME, given); p.set(Kontakt.FLD_STREET, streetAdressLine); p.set(Kontakt.FLD_ZIP, plz); p.set(Kontakt.FLD_PLACE, city); p.set(Patient.FLD_E_MAIL, xpath.getPatientEmail()); if ("M".equals(xpath.getPatientGender())) { p.set(Patient.FLD_SEX, "m"); } if ("F".equals(xpath.getPatientGender())) { p.set(Patient.FLD_SEX, "w"); } p.set(Patient.FLD_PHONE1, xpath.getPatientHomePhone()); p.set(Patient.FLD_MOBILEPHONE, xpath.getPatientMobile()); p.set(Patient.FLD_PHONE2, xpath.getPatientOfficePhone()); p.set(Patient.BIRTHDATE, xpath.getPatientDateOfBirth()); String ahv = xpath.getPatientAhv13(); if (ahv != null && !"".equals(ahv)) { p.addXid(DOMAIN_AHV, xpath.getPatientAhv13(), true); } ElexisEventDispatcher.fireSelectionEvent((PersistentObject) p); ElexisEventDispatcher.reload(Patient.class); } } } }; MenuManager mgr = new MenuManager(); mgr.setRemoveAllWhenShown(true); mgr.addMenuListener(new IMenuListener() { public void menuAboutToShow(IMenuManager manager) { manager.add(actionOpenAttachments); manager.add(actionDeleteDocument); manager.add(actionShowCdaDocument); manager.add(actionCreatePatient); } }); tableViewer.getControl().setMenu(mgr.createContextMenu(tableViewer.getControl())); tableViewer.addDoubleClickListener(new IDoubleClickListener() { public void doubleClick(DoubleClickEvent event) { actionOpenAttachments.run(); } }); tableViewer.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { IStructuredSelection sel = (IStructuredSelection) event.getSelection(); if ((sel != null) && !sel.isEmpty()) { Object object = sel.getFirstElement(); if (object instanceof CdaMessage) { CdaMessage cdaMessage = (CdaMessage) object; cdaMessage.setRead(); // try to find the matchting person CdaChXPath cdaChXPath = new CdaChXPath(); String cda = cdaMessage.getCda(); if (cda != null) { cdaChXPath.setPatientDocument(cda); String lastName = cdaChXPath.getPatientLastName(); String firstName = cdaChXPath.getPatientFirstName(); String geburtsdatum = cdaChXPath.getPatientDateOfBirth(); if (cdaChXPath.getPatientNumber() != null) { String patId = new Query<Patient>(Patient.class).findSingle("PatientNr", "=", //$NON-NLS-1$//$NON-NLS-2$ cdaChXPath.getPatientNumber()); if (patId != null) { Patient elexisPatient = Patient.load(patId); if (elexisPatient != null && elexisPatient.getName().equals(lastName) && elexisPatient.getVorname().equals(firstName)) { log.log("selecting patient by id with " + lastName + ", " + firstName, Log.DEBUGMSG); ElexisEventDispatcher.fireSelectionEvent(elexisPatient); return; } } } if (KontaktMatcher.findPerson(lastName, firstName, geburtsdatum, null, null, null, null, null, CreateMode.FAIL) != null) { log.log("selecting patient by demographics " + lastName + ", " + firstName, Log.DEBUGMSG); Patient elexisPatient = KontaktMatcher.findPatient(lastName, firstName, geburtsdatum, null, null, null, null, null, CreateMode.FAIL); if (elexisPatient != null) { ElexisEventDispatcher.fireSelectionEvent(elexisPatient); } } } tableViewer.refresh(); } } } }); GlobalEventDispatcher.addActivationListener(this, getViewSite().getPart()); }
From source file:ch.elexis.agenda.views.BaseAgendaView.java
License:Open Source License
public IPlannable getSelection() { IStructuredSelection sel = (IStructuredSelection) tv.getSelection(); if ((sel == null || (sel.isEmpty()))) { return null; } else {/*from ww w. j av a 2s. com*/ IPlannable pl = (IPlannable) sel.getFirstElement(); return pl; } }
From source file:ch.elexis.agenda.views.BaseAgendaView.java
License:Open Source License
protected void makeActions() { dayLimitsAction = new Action(Messages.BaseAgendaView_dayLimits) { @Override/*from w ww .j a v a 2s . c o m*/ public void run() { new TagesgrenzenDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), agenda.getActDate().toString(TimeTool.DATE_COMPACT), agenda.getActResource()).open(); tv.refresh(true); } }; dayLimitsAction.setId("ch.elexis.agenda.actions.dayLimitsAction"); blockAction = new Action(Messages.TagesView_lockPeriod) { @Override public void run() { IStructuredSelection sel = (IStructuredSelection) tv.getSelection(); if (sel != null && !sel.isEmpty()) { IPlannable p = (IPlannable) sel.getFirstElement(); if (p instanceof Termin.Free) { new Termin(agenda.getActResource(), agenda.getActDate().toString(TimeTool.DATE_COMPACT), p.getStartMinute(), p.getDurationInMinutes() + p.getStartMinute(), Termin.typReserviert(), Termin.statusLeer()); ElexisEventDispatcher.reload(Termin.class); } } } }; terminAendernAction = new LockRequestingRestrictedAction<Termin>(ACLContributor.CHANGE_APPOINTMENTS, Messages.TagesView_changeTermin) { { setImageDescriptor(Images.IMG_EDIT.getImageDescriptor()); setToolTipText(Messages.TagesView_changeThisTermin); } @Override public Termin getTargetedObject() { return (Termin) ElexisEventDispatcher.getSelected(Termin.class); } @Override public void doRun(Termin element) { AcquireLockBlockingUi.aquireAndRun(element, new ILockHandler() { @Override public void lockFailed() { // do nothing } @Override public void lockAcquired() { TerminDialog dlg = new TerminDialog(element); dlg.open(); } }); if (tv != null) { tv.refresh(true); } } }; terminKuerzenAction = new LockRequestingRestrictedAction<Termin>(ACLContributor.CHANGE_APPOINTMENTS, Messages.TagesView_shortenTermin) { @Override public Termin getTargetedObject() { return (Termin) ElexisEventDispatcher.getSelected(Termin.class); } @Override public void doRun(Termin element) { element.setDurationInMinutes(element.getDurationInMinutes() >> 1); ElexisEventDispatcher.reload(Termin.class); } }; terminVerlaengernAction = new LockRequestingRestrictedAction<Termin>(ACLContributor.CHANGE_APPOINTMENTS, Messages.TagesView_enlargeTermin) { @Override public Termin getTargetedObject() { return (Termin) ElexisEventDispatcher.getSelected(Termin.class); } @Override public void doRun(Termin t) { agenda.setActDate(t.getDay()); Termin n = Plannables.getFollowingTermin(agenda.getActResource(), agenda.getActDate(), t); if (n != null) { t.setEndTime(n.getStartTime()); // t.setDurationInMinutes(t.getDurationInMinutes()+15); ElexisEventDispatcher.reload(Termin.class); } } }; newTerminAction = new RestrictedAction(ACLContributor.CHANGE_DAYSETTINGS, Messages.TagesView_newTermin) { { setImageDescriptor(Images.IMG_NEW.getImageDescriptor()); setToolTipText(Messages.TagesView_createNewTermin); } @Override public void doRun() { TerminDialog dlg = new TerminDialog(null); dlg.open(); if (tv != null) { tv.refresh(true); } } }; newTerminForAction = new Action("Neuer Termin fr...") { { setImageDescriptor(Images.IMG_NEW.getImageDescriptor()); setToolTipText("Dialog zum Auswhlen eines Kontakts fr den Termin ffnen"); } @Override public void run() { KontaktSelektor ksl = new KontaktSelektor(getSite().getShell(), Kontakt.class, "Terminvergabe", "Bitte whlen Sie aus, wer einen Termin braucht", Kontakt.DEFAULT_SORT); IPlannable sel = getSelection(); TerminDialog dlg = new TerminDialog(null); dlg.open(); if (tv != null) { tv.refresh(true); } } }; printAction = new Action(Messages.BaseAgendaView_printDayList) { { setImageDescriptor(Images.IMG_PRINTER.getImageDescriptor()); setToolTipText(Messages.BaseAgendaView_printListOfDay); } @Override public void run() { IPlannable[] liste = Plannables.loadDay(agenda.getActResource(), agenda.getActDate()); TerminListeDruckenDialog dlg = new TerminListeDruckenDialog(getViewSite().getShell(), liste); dlg.open(); if (tv != null) { tv.refresh(true); } } }; printPatientAction = new Action(Messages.BaseAgendaView_printPatAppointments) { { setImageDescriptor(Images.IMG_PRINTER.getImageDescriptor()); setToolTipText(Messages.BaseAgendaView_printFutureAppsOfSelectedPatient); } @Override public void run() { Patient patient = ElexisEventDispatcher.getSelectedPatient(); if (patient != null) { Query<Termin> qbe = new Query<Termin>(Termin.class); qbe.add(Termin.FLD_PATIENT, Query.EQUALS, patient.getId()); qbe.add(PersistentObject.FLD_DELETED, Query.NOT_EQUAL, StringConstants.ONE); qbe.add(Termin.FLD_TAG, Query.GREATER_OR_EQUAL, new TimeTool().toString(TimeTool.DATE_COMPACT)); qbe.orderBy(false, Termin.FLD_TAG, Termin.FLD_BEGINN); java.util.List<Termin> list = qbe.execute(); if (list != null) { boolean directPrint = CoreHub.localCfg.get( PreferenceConstants.AG_PRINT_APPOINTMENTCARD_DIRECTPRINT, PreferenceConstants.AG_PRINT_APPOINTMENTCARD_DIRECTPRINT_DEFAULT); TermineDruckenDialog dlg = new TermineDruckenDialog(getViewSite().getShell(), list.toArray(new Termin[0])); if (directPrint) { dlg.setBlockOnOpen(false); dlg.open(); if (dlg.doPrint()) { dlg.close(); } else { SWTHelper.alert(Messages.BaseAgendaView_errorWhileprinting, Messages.BaseAgendaView_errorHappendPrinting); } } else { dlg.setBlockOnOpen(true); dlg.open(); } } } } }; exportAction = new Action(Messages.BaseAgendaView_exportAgenda) { { setToolTipText(Messages.BaseAgendaView_exportAppointsments); setImageDescriptor(Images.IMG_GOFURTHER.getImageDescriptor()); } @Override public void run() { ICalTransfer ict = new ICalTransfer(); ict.doExport(agenda.getActDate(), agenda.getActDate(), agenda.getActResource()); } }; importAction = new Action(Messages.BaseAgendaView_importAgenda) { { setToolTipText(Messages.BaseAgendaView_importFromIcal); setImageDescriptor(Images.IMG_IMPORT.getImageDescriptor()); } @Override public void run() { ICalTransfer ict = new ICalTransfer(); ict.doImport(agenda.getActResource()); } }; bereichMenu = new Action(Messages.TagesView_bereich, Action.AS_DROP_DOWN_MENU) { Menu mine; { setToolTipText(Messages.TagesView_selectBereich); setMenuCreator(bmc); } }; mgr = getViewSite().getActionBars().getMenuManager(); mgr.add(bereichMenu); mgr.add(dayLimitsAction); mgr.add(newViewAction); mgr.add(exportAction); mgr.add(importAction); mgr.add(printAction); mgr.add(printPatientAction); }
From source file:ch.elexis.core.ui.contacts.dynamic.KontaktRollenSwitcher.java
License:Open Source License
@Override public void fill(Menu menu, int index) { IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); ISelection selection = window.getActivePage().getSelection(); IStructuredSelection strucSelection = (IStructuredSelection) selection; k = (IContact) strucSelection.getFirstElement(); if (k != null) { MenuItem itemMandant;// ww w . ja v a2s.c o m MenuItem itemAnwender; MenuItem itemPatient; switch (k.getContactType()) { case PERSON: // TODO: Passwort setzen beim ndern itemAnwender = new MenuItem(menu, SWT.CHECK, index); itemAnwender.setText("Anwender"); if (k.isUser()) itemAnwender.setSelection(true); itemAnwender.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { if (!k.isUser()) { // TODO Create a new Anwender, set username, pw // call preference page to set access rights } else { // Delete the Anwender, delete username and pw } k.setUser(!k.isUser()); KontaktAnzeigeTypViewerFilter.refreshViewer(); } }); itemMandant = new MenuItem(menu, SWT.CHECK, index); itemMandant.setText("Mandant"); if (k.isMandator()) itemMandant.setSelection(true); itemMandant.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { if (k.isMandator()) { // TODO: User about to remove mandant role, warn him } k.setMandator(!k.isMandator()); KontaktAnzeigeTypViewerFilter.refreshViewer(); } }); itemPatient = new MenuItem(menu, SWT.CHECK, index); itemPatient.setText("Patient"); if (k.isPatient()) itemPatient.setSelection(true); itemPatient.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { if (k.isPatient()) { // TODO User is about to delete patient role, warn him! } k.setPatient(!k.isPatient()); KontaktAnzeigeTypViewerFilter.refreshViewer(); } }); break; case ORGANIZATION: itemMandant = new MenuItem(menu, SWT.CHECK, index); itemMandant.setText("Mandant"); if (k.isMandator()) itemMandant.setSelection(true); itemMandant.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { k.setMandator(!k.isMandator()); KontaktAnzeigeTypViewerFilter.refreshViewer(); } }); break; default: MenuItem item = new MenuItem(menu, SWT.CHECK, index); item.setText("Keine Optionen"); item.setEnabled(false); break; } } }
From source file:ch.elexis.core.ui.contacts.dynamic.KontaktStickerSwitcher.java
License:Open Source License
@Override public void fill(Menu menu, int index) { IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); ISelection selection = window.getActivePage().getSelection(); IStructuredSelection strucSelection = (IStructuredSelection) selection; k = (IContact) strucSelection.getFirstElement(); // if (k != null) { // List<ISticker> stickersForClass = // IStickerFactory.eINSTANCE.findStickersForClass(k.getClass()); // List<ISticker> definedStickers = IStickerFactory.eINSTANCE.findStickersForObject(k); // /*from ww w .j av a2s.c om*/ // for (ISticker st : stickersForClass) { // MenuItem item = new MenuItem(menu, SWT.CHECK, index); // item.setText(st.getName()); // item.setData("ID", st.getId()); // for (ISticker dst : definedStickers) { // if (dst.getId().equalsIgnoreCase(st.getId())) // item.setSelection(true); // } // item.addSelectionListener(new SelectionAdapter() { // @Override // public void widgetSelected(SelectionEvent e){ // MenuItem i = (MenuItem) e.widget; // ISticker is = IStickerFactory.eINSTANCE.findById((String) i.getData("ID")); // if (i.getSelection()) { // // sticker is not set -> set // IStickerFactory.eINSTANCE.setStickerOnObject(is, k); // } else { // // sticker is set -> remove // IStickerFactory.eINSTANCE.removeStickerFromObject(is, k); // } // } // }); // } // } }
From source file:ch.elexis.core.ui.contacts.views.dnd.ContactSelectorDragListener.java
License:Open Source License
@Override public void dragSetData(DragSourceEvent event) { // Here you do the convertion to the type which is expected. IStructuredSelection selection = (IStructuredSelection) viewer.getSelection(); IContact firstElement = (IContact) selection.getFirstElement(); if (TextTransfer.getInstance().isSupportedType(event.dataType)) { event.data = firstElement.getId(); }// www. ja v a2s . c om }
From source file:ch.elexis.core.ui.dialogs.DocumentSelectDialog.java
License:Open Source License
@Override protected void okPressed() { IStructuredSelection sel = (IStructuredSelection) tv.getSelection(); if ((sel != null) && (!sel.isEmpty())) { result = (Brief) sel.getFirstElement(); if ((type & TEMPLATE) != 0) { betreff = tBetreff.getText(); }/*from w w w. j a v a 2s. co m*/ if (StringTool.isNothing(betreff)) { betreff = result.getBetreff(); } } super.okPressed(); }
From source file:ch.elexis.core.ui.dialogs.KonsZumVerrechnenWizardDialog.java
License:Open Source License
@Override protected void okPressed() { if (cbBefore.getSelection()) { ttFirstBefore = ddc1.getDate();//from ww w. j a va 2 s .c o m } if (cbTime.getSelection()) { ttLastBefore = ddc2.getDate(); } if (cbAmount.getSelection()) { mAmount = mi1.getMoney(false); } if (cbTimespan.getSelection()) { ttFrom = getDate(timespanFrom, 0, 0, 0); ttTo = getDate(timespanTo, 23, 59, 59); } if (cbAccountingSys.getSelection()) { IStructuredSelection sel = (IStructuredSelection) cAccountingSys.getSelection(); accountSys = (String) sel.getFirstElement(); } bQuartal = cbQuartal.getSelection(); bMarked = cbMarked.getSelection(); bSkip = cbSkip.getSelection(); CoreHub.globalCfg.set(CFG_SKIP, bSkip); super.okPressed(); }
From source file:ch.elexis.core.ui.dialogs.KontaktSelektor.java
License:Open Source License
private Object getBezugsKontaktSelection() { Object bezugsKontakt = null;/*from www . ja va 2 s .c om*/ if (bezugsKontaktViewer != null) { IStructuredSelection sel = (IStructuredSelection) bezugsKontaktViewer.getSelection(); if (sel.size() > 0) { bezugsKontakt = sel.getFirstElement(); } } return bezugsKontakt; }
From source file:ch.elexis.core.ui.documents.views.DocumentsView.java
License:Open Source License
/** * This is a callback that will allow us to create the viewer and initialize it. *//*from w w w. ja va 2 s . com*/ public void createPartControl(Composite parent) { parent.setLayout(new GridLayout(4, false)); final Text tSearch = new Text(parent, SWT.BORDER); tSearch.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false)); tSearch.setMessage(Messages.DocumentView_searchLabel); // Add search listener ModifyListener searchListener = new ModifyListener() { public void modifyText(ModifyEvent e) { searchTitle = tSearch.getText(); refresh(); if (searchTitle == null || searchTitle.isEmpty()) { viewer.collapseAll(); } else { viewer.expandAll(); } } }; tSearch.addModifyListener(searchListener); // Table to display documents table = new Tree(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION); TreeColumn[] cols = new TreeColumn[colLabels.length]; for (int i = 0; i < colLabels.length; i++) { cols[i] = new TreeColumn(table, SWT.NONE); cols[i].setText(colLabels[i]); cols[i].setData(new Integer(i)); } applyUsersColumnWidthSetting(); table.setHeaderVisible(true); table.setLinesVisible(true); table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 4, 1)); viewer = new TreeViewer(table); viewer.setContentProvider(new ViewContentProvider()); viewer.setLabelProvider(new ViewLabelProvider()); viewer.setUseHashlookup(true); viewer.addFilter(new ViewFilterProvider()); ovComparator = new DocumentsViewerComparator(); viewer.setComparator(ovComparator); TreeColumn[] treeCols = viewer.getTree().getColumns(); for (int i = 0; i < treeCols.length; i++) { TreeColumn tc = treeCols[i]; tc.addSelectionListener(getSelectionAdapter(tc, i)); } makeActions(); applySortDirection(); hookDoubleClickAction(); 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; ICategory category = null; if (event.item != null) { if (event.item.getData() instanceof IDocument) { IDocument dh = (IDocument) event.item.getData(); category = dh.getCategory(); } else if (event.item.getData() instanceof ICategory) { category = (ICategory) event.item.getData(); } } ICommandService commandService = (ICommandService) PlatformUI.getWorkbench() .getService(ICommandService.class); Command cmd = commandService.getCommand(DocumentCrudHandler.CMD_NEW_DOCUMENT); if (files != null) { for (String file : files) { try { Map<String, String> params = new HashMap<>(); params.put(DocumentCrudHandler.PARAM_FILE_PATH, file); if (category != null) { params.put(DocumentCrudHandler.PARAM_DOC_CATEGORY, category.getName()); } ExecutionEvent ev = new ExecutionEvent(cmd, params, null, null); cmd.executeWithChecks(ev); } catch (Exception e) { logger.error("drop error", e); } } } viewer.refresh(); } } }); final Transfer[] dragTransferTypes = new Transfer[] { FileTransfer.getInstance(), TextTransfer.getInstance() }; viewer.addDragSupport(DND.DROP_COPY, dragTransferTypes, new DragSourceAdapter() { private boolean failure; @Override public void dragStart(DragSourceEvent event) { IStructuredSelection selection = (IStructuredSelection) viewer.getSelection(); event.doit = selection.getFirstElement() instanceof IDocument; } @Override public void dragSetData(DragSourceEvent event) { failure = false; IStructuredSelection selection = (IStructuredSelection) viewer.getSelection(); IDocument dh = (IDocument) selection.getFirstElement(); if (FileTransfer.getInstance().isSupportedType(event.dataType)) { String title = dh.getTitle(); int end = dh.getTitle().lastIndexOf("."); if (end != -1) { title = (dh.getTitle()).substring(0, end); } try { String absPath = DocumentStoreServiceHolder.getService().saveContentToTempFile(dh, title, dh.getExtension(), true); if (absPath != null) { event.data = new String[] { absPath }; } else { event.doit = false; failure = true; } } catch (ElexisException e) { event.doit = false; failure = true; logger.error("drag error", e); } } } @Override public void dragFinished(DragSourceEvent event) { if (!failure) { super.dragFinished(event); } else { SWTHelper.showError(Messages.DocumentView_exportErrorCaption, Messages.DocumentView_exportErrorEmptyText); } } }); GlobalEventDispatcher.addActivationListener(this, this); MenuManager menuManager = new MenuManager(); viewer.getControl().setMenu(menuManager.createContextMenu(viewer.getControl())); getSite().registerContextMenu(menuManager, viewer); getSite().setSelectionProvider(viewer); viewer.setInput(ElexisEventDispatcher.getSelectedPatient()); }