Search in sources :

Example 1 with CallerCombineWizard

use of de.janrufmonitor.ui.jface.wizards.CallerCombineWizard in project janrufmonitor by tbrandt77.

the class CombineAction method run.

public void run() {
    Viewer v = this.m_app.getApplication().getViewer();
    if (v != null) {
        IStructuredSelection selection = (IStructuredSelection) v.getSelection();
        if (!selection.isEmpty()) {
            Iterator i = selection.iterator();
            ICallerList list = getRuntime().getCallerFactory().createCallerList();
            ICallerList olist = getRuntime().getCallerFactory().createCallerList();
            Object o = null;
            while (i.hasNext()) {
                o = i.next();
                olist.add((ICaller) o);
                if (o instanceof IMultiPhoneCaller) {
                    list.add((IMultiPhoneCaller) o);
                } else if (o instanceof ICaller) {
                    list.add(getRuntime().getCallerFactory().toMultiPhoneCaller((ICaller) o));
                }
            }
            if (list.size() < 2)
                return;
            Display display = DisplayManager.getDefaultDisplay();
            Shell shell = new Shell(display);
            WizardDialog.setDefaultImage(SWTImageManager.getInstance(this.getRuntime()).get(IJAMConst.IMAGE_KEY_PIM_ICON));
            CallerCombineWizard callerWiz = new CallerCombineWizard(list);
            WizardDialog dlg = new WizardDialog(shell, callerWiz);
            dlg.open();
            if (dlg.getReturnCode() == WizardDialog.OK) {
                IMultiPhoneCaller c = callerWiz.getResult();
                if (c != null) {
                    // remove merged contact from olist
                    ICaller ca, rmc = null;
                    for (int j = olist.size() - 1; j >= 0; j--) {
                        ca = olist.get(j);
                        if (ca.getUUID().equalsIgnoreCase(c.getUUID())) {
                            rmc = ca;
                            m_logger.info("Merged user detected: " + rmc);
                        }
                    }
                    if (rmc != null)
                        olist.remove(rmc);
                    this.m_app.getController().deleteElements(olist);
                    this.m_app.getController().updateElement(c);
                    this.m_app.updateViews(true);
                }
            }
        }
    }
}
Also used : ICaller(de.janrufmonitor.framework.ICaller) Shell(org.eclipse.swt.widgets.Shell) ICallerList(de.janrufmonitor.framework.ICallerList) Iterator(java.util.Iterator) Viewer(org.eclipse.jface.viewers.Viewer) IMultiPhoneCaller(de.janrufmonitor.framework.IMultiPhoneCaller) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) CallerCombineWizard(de.janrufmonitor.ui.jface.wizards.CallerCombineWizard) WizardDialog(org.eclipse.jface.wizard.WizardDialog) Display(org.eclipse.swt.widgets.Display)

Aggregations

ICaller (de.janrufmonitor.framework.ICaller)1 ICallerList (de.janrufmonitor.framework.ICallerList)1 IMultiPhoneCaller (de.janrufmonitor.framework.IMultiPhoneCaller)1 CallerCombineWizard (de.janrufmonitor.ui.jface.wizards.CallerCombineWizard)1 Iterator (java.util.Iterator)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 Viewer (org.eclipse.jface.viewers.Viewer)1 WizardDialog (org.eclipse.jface.wizard.WizardDialog)1 Display (org.eclipse.swt.widgets.Display)1 Shell (org.eclipse.swt.widgets.Shell)1