Search in sources :

Example 1 with IConfigurable

use of de.janrufmonitor.framework.configuration.IConfigurable in project janrufmonitor by tbrandt77.

the class AbstractPhonesPage method createControl.

public void createControl(Composite parent) {
    setTitle(this.m_i18n.getString(getNamespace(), "title", "label", this.m_language));
    setDescription(this.m_i18n.getString(getNamespace(), "description", "label", this.m_language));
    Composite c = new Composite(parent, SWT.NONE);
    c.setLayout(new GridLayout(1, false));
    c.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    all = new Button(c, SWT.CHECK);
    all.setText(this.m_i18n.getString(this.getNamespace(), "*", "label", this.m_language));
    all.setSelection((this.getCallers().size() == 0 ? true : false));
    Label ln = new Label(c, SWT.LEFT);
    Composite select = new Composite(c, SWT.NONE);
    select.setLayout(new GridLayout(3, false));
    select.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    ln = new Label(select, SWT.LEFT);
    ln.setText(this.m_i18n.getString(this.getNamespace(), "allphones", "label", this.m_language));
    ln = new Label(select, SWT.LEFT);
    ln = new Label(select, SWT.LEFT);
    ln.setText(this.m_i18n.getString(this.getNamespace(), "selectedphones", "label", this.m_language));
    final CheckboxTableViewer call = CheckboxTableViewer.newCheckList(select, SWT.CHECK | SWT.BORDER | SWT.V_SCROLL);
    call.setLabelProvider(new CallerLabelProvider());
    call.setContentProvider(new CallerContentProvider());
    call.setInput(null);
    ProgressMonitorDialog pmd = new ProgressMonitorDialog(getShell());
    try {
        IRunnableWithProgress r = new IRunnableWithProgress() {

            public void run(IProgressMonitor progressMonitor) {
                progressMonitor.beginTask(m_i18n.getString("ui.jface.wizards.pages.AbstractPhonesPage", "refreshprogress", "label", m_language), IProgressMonitor.UNKNOWN);
                final List callers = new ArrayList();
                Thread t = new Thread() {

                    public void run() {
                        // preload data
                        try {
                            callers.addAll(getAllCallers());
                        } catch (Exception ex) {
                            m_logger.log(Level.SEVERE, ex.getMessage(), ex);
                        }
                    }
                };
                t.setName("JAM-ContactsRead-Thread-(non-deamon)");
                t.start();
                int lastamount = -1;
                do {
                    try {
                        Thread.sleep(500);
                    } catch (InterruptedException e) {
                    }
                    m_currentCallerManager = CallerReaderFactory.getInstance().getCurrent();
                    if (m_currentCallerManager != null && m_currentCallerManager instanceof ITracker) {
                        int leftover = Math.max(0, (((ITracker) m_currentCallerManager).getTotal() - ((ITracker) m_currentCallerManager).getCurrent()));
                        if (lastamount == leftover) {
                            String msg = m_i18n.getString("ui.jface.wizards.pages.AbstractPhonesPage", "working", "label", m_language);
                            progressMonitor.subTask(msg);
                        } else {
                            String msg = m_i18n.getString("ui.jface.wizards.pages.AbstractPhonesPage", "tracking", "label", m_language);
                            msg = StringUtils.replaceString(msg, "{%1}", Integer.toString(leftover));
                            if (m_currentCallerManager instanceof IConfigurable) {
                                msg = StringUtils.replaceString(msg, "{%2}", m_i18n.getString(((IConfigurable) m_currentCallerManager).getNamespace(), "title", "label", m_language));
                            } else {
                                msg = StringUtils.replaceString(msg, "{%2}", m_i18n.getString("ui.jface.wizards.pages.AbstractPhonesPage", "nocallermanager", "label", m_language));
                            }
                            progressMonitor.subTask(msg);
                        }
                        lastamount = leftover;
                    } else {
                        String msg = m_i18n.getString("ui.jface.wizards.pages.AbstractPhonesPage", "notracking", "label", m_language);
                        if (m_currentCallerManager instanceof IConfigurable) {
                            msg = StringUtils.replaceString(msg, "{%1}", m_i18n.getString(((IConfigurable) m_currentCallerManager).getNamespace(), "title", "label", m_language));
                        } else {
                            msg = StringUtils.replaceString(msg, "{%1}", m_i18n.getString("ui.jface.wizards.pages.AbstractPhonesPage", "nocallermanager", "label", m_language));
                        }
                        progressMonitor.subTask(msg);
                    }
                } while (t.isAlive());
                SWTExecuter tt = new SWTExecuter("ContactsRefresh") {

                    protected void execute() {
                        call.setInput(callers);
                    }
                };
                tt.start();
                progressMonitor.done();
            }
        };
        pmd.setBlockOnOpen(false);
        pmd.run(true, false, r);
    // ModalContext.run(r, true, pmd.getProgressMonitor(), DisplayManager.getDefaultDisplay());
    } catch (InterruptedException e) {
        m_logger.log(Level.SEVERE, e.getMessage(), e);
    } catch (InvocationTargetException e) {
        m_logger.log(Level.SEVERE, e.getMessage(), e);
    }
    GridData gd = new GridData(200, 200);
    call.getTable().setLayoutData(gd);
    Composite btns = new Composite(select, SWT.NONE);
    btns.setLayout(new GridLayout(1, false));
    btns.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    final Button add = new Button(btns, SWT.PUSH);
    add.setText(this.m_i18n.getString(this.getNamespace(), "add", "label", this.m_language));
    final Button remove = new Button(btns, SWT.PUSH);
    remove.setText(this.m_i18n.getString(this.getNamespace(), "remove", "label", this.m_language));
    final CheckboxTableViewer cselect = CheckboxTableViewer.newCheckList(select, SWT.CHECK | SWT.BORDER);
    cselect.setLabelProvider(new CallerLabelProvider());
    cselect.setContentProvider(new CallerContentProvider());
    List selected = this.getCallers();
    cselect.setInput(selected);
    gd = new GridData(200, 200);
    cselect.getTable().setLayoutData(gd);
    all.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            add.setEnabled(!all.getSelection());
            remove.setEnabled(!all.getSelection());
            call.setAllGrayed(all.getSelection());
            cselect.setAllGrayed(all.getSelection());
        }
    });
    add.setEnabled(!all.getSelection());
    remove.setEnabled(!all.getSelection());
    call.setAllGrayed(all.getSelection());
    cselect.setAllGrayed(all.getSelection());
    add.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            Object[] checked = call.getCheckedElements();
            if (checked != null && checked.length > 0) {
                for (int i = 0; i < checked.length; i++) {
                    if (!m_selectedCallers.contains(checked[i]))
                        m_selectedCallers.add(checked[i]);
                }
                cselect.setInput(m_selectedCallers);
            }
        }
    });
    remove.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            Object[] checked = cselect.getCheckedElements();
            if (checked != null && checked.length > 0) {
                for (int i = 0; i < checked.length; i++) {
                    if (m_selectedCallers.contains(checked[i]))
                        m_selectedCallers.remove(checked[i]);
                }
                cselect.setInput(m_selectedCallers);
            }
        }
    });
    setPageComplete(true);
    setControl(c);
}
Also used : ITracker(de.janrufmonitor.repository.imexport.ITracker) Composite(org.eclipse.swt.widgets.Composite) CheckboxTableViewer(org.eclipse.jface.viewers.CheckboxTableViewer) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) ArrayList(java.util.ArrayList) IConfigurable(de.janrufmonitor.framework.configuration.IConfigurable) CallerNotFoundException(de.janrufmonitor.repository.CallerNotFoundException) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) GridLayout(org.eclipse.swt.layout.GridLayout) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ArrayList(java.util.ArrayList) List(java.util.List) SWTExecuter(de.janrufmonitor.ui.swt.SWTExecuter)

Example 2 with IConfigurable

use of de.janrufmonitor.framework.configuration.IConfigurable in project janrufmonitor by tbrandt77.

the class CallManagerFactory method shutdown.

public void shutdown() {
    this.m_logger.entering(CallManagerFactory.class.getName(), "shutdown");
    List mgrs = this.getAllCallManagers();
    ICallManager mgr = null;
    for (int i = 0; i < mgrs.size(); i++) {
        mgr = (ICallManager) mgrs.get(i);
        mgr.shutdown();
        if (mgr instanceof IConfigurable)
            PIMRuntime.getInstance().getConfigurableNotifier().unregister((IConfigurable) mgr);
    }
    this.m_callManagers.clear();
    PIMRuntime.getInstance().getConfigurableNotifier().unregister(this);
    m_instance = null;
    this.m_logger.exiting(CallManagerFactory.class.getName(), "shutdown");
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) IConfigurable(de.janrufmonitor.framework.configuration.IConfigurable)

Example 3 with IConfigurable

use of de.janrufmonitor.framework.configuration.IConfigurable in project janrufmonitor by tbrandt77.

the class CallerManagerFactory method shutdown.

public void shutdown() {
    this.m_logger.entering(CallerManagerFactory.class.getName(), "shutdown");
    List mgrs = this.getAllCallerManagers();
    ICallerManager mgr = null;
    for (int i = 0; i < mgrs.size(); i++) {
        mgr = (ICallerManager) mgrs.get(i);
        mgr.shutdown();
        if (mgr instanceof IConfigurable)
            PIMRuntime.getInstance().getConfigurableNotifier().unregister((IConfigurable) mgr);
    }
    this.m_callerManagers.clear();
    PIMRuntime.getInstance().getConfigurableNotifier().unregister(this);
    m_instance = null;
    this.m_logger.exiting(CallerManagerFactory.class.getName(), "shutdown");
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) IConfigurable(de.janrufmonitor.framework.configuration.IConfigurable)

Example 4 with IConfigurable

use of de.janrufmonitor.framework.configuration.IConfigurable in project janrufmonitor by tbrandt77.

the class ServiceFactory method shutdown.

public void shutdown() {
    this.m_logger.entering(ServiceFactory.class.getName(), "shutdown");
    List services = this.getAllServices();
    for (int i = 0; i < services.size(); i++) {
        IService is = (IService) services.get(i);
        try {
            if (is.isRunning()) {
                is.shutdown();
                this.m_logger.info("Shutdown service: " + is.getServiceID());
            } else {
                this.m_logger.info("Service " + is.getServiceID() + " could not be shut down because it is not running.");
            }
            if (is instanceof IConfigurable)
                PIMRuntime.getInstance().getConfigurableNotifier().unregister((IConfigurable) is);
        } catch (Exception ex) {
            this.m_logger.severe("Service shutdown <" + is + ">: " + ex.toString() + ": " + ex.getMessage());
            this.m_logger.log(Level.SEVERE, ex.getMessage(), ex);
        }
    }
    PIMRuntime.getInstance().getConfigurableNotifier().unregister(this);
    m_instance = null;
    this.m_logger.exiting(ServiceFactory.class.getName(), "shutdown");
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) IConfigurable(de.janrufmonitor.framework.configuration.IConfigurable)

Example 5 with IConfigurable

use of de.janrufmonitor.framework.configuration.IConfigurable in project janrufmonitor by tbrandt77.

the class Caller method performOk.

public boolean performOk() {
    if (this.managers != null && this.managers.size() > 0) {
        IConfigurable conf = null;
        ICallerManager o;
        for (int i = 0; i < managers.size(); i++) {
            o = this.getRuntime().getCallerManagerFactory().getCallerManager((String) managers.get(i));
            if (o != null && o instanceof IConfigurable) {
                conf = (IConfigurable) o;
                this.getPreferenceStore().setValue(conf.getNamespace() + SEPARATOR + "priority", i + 10);
            }
        }
    }
    boolean ok = super.performOk();
    if (ok) {
        // notify all changed namespaces
        if (this.managers != null && this.managers.size() > 0) {
            IConfigurable conf = null;
            ICallerManager o = null;
            for (int i = 0; i < managers.size(); i++) {
                o = this.getRuntime().getCallerManagerFactory().getCallerManager((String) managers.get(i));
                if (o != null && o instanceof IConfigurable) {
                    conf = (IConfigurable) o;
                    this.getRuntime().getConfigurableNotifier().notifyByNamespace(conf.getNamespace());
                }
            }
        }
    }
    return ok;
}
Also used : IConfigurable(de.janrufmonitor.framework.configuration.IConfigurable) ICallerManager(de.janrufmonitor.repository.ICallerManager)

Aggregations

IConfigurable (de.janrufmonitor.framework.configuration.IConfigurable)7 ArrayList (java.util.ArrayList)4 List (java.util.List)4 ICallerManager (de.janrufmonitor.repository.ICallerManager)2 ILocalRepository (de.janrufmonitor.repository.types.ILocalRepository)2 IRemoteRepository (de.janrufmonitor.repository.types.IRemoteRepository)2 CallerNotFoundException (de.janrufmonitor.repository.CallerNotFoundException)1 ICallManager (de.janrufmonitor.repository.ICallManager)1 ITracker (de.janrufmonitor.repository.imexport.ITracker)1 SWTExecuter (de.janrufmonitor.ui.swt.SWTExecuter)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 ProgressMonitorDialog (org.eclipse.jface.dialogs.ProgressMonitorDialog)1 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)1 CheckboxTableViewer (org.eclipse.jface.viewers.CheckboxTableViewer)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 GridData (org.eclipse.swt.layout.GridData)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 Button (org.eclipse.swt.widgets.Button)1