Search in sources :

Example 11 with IService

use of de.janrufmonitor.service.IService in project janrufmonitor by tbrandt77.

the class Activator method execute.

public void execute() {
    IMonitorListener ml = PIMRuntime.getInstance().getMonitorListener();
    if (ml.isRunning()) {
        ml.stop();
    } else {
        ml.start();
    }
    IService tray = this.getRuntime().getServiceFactory().getService("TrayIcon");
    if (tray != null && tray instanceof TrayIcon) {
        ((TrayIcon) tray).setIconStateMonitorListener();
    }
    getRuntime().getEventBroker().register(this);
    getRuntime().getEventBroker().send(this, getRuntime().getEventBroker().createEvent(IEventConst.EVENT_TYPE_APPLICATION_READY));
    getRuntime().getEventBroker().unregister(this);
}
Also used : IMonitorListener(de.janrufmonitor.framework.monitor.IMonitorListener) IService(de.janrufmonitor.service.IService)

Example 12 with IService

use of de.janrufmonitor.service.IService in project janrufmonitor by tbrandt77.

the class Dialog method createContents.

protected Control createContents(Composite parent) {
    Composite composite = new Composite(parent, SWT.NONE);
    composite.setLayout(new GridLayout(1, false));
    Group g = new Group(composite, SWT.SHADOW_ETCHED_IN);
    g.setLayout(new GridLayout(2, false));
    Label date = new Label(g, SWT.NONE);
    date.setText(this.getI18nManager().getString(this.getNamespace(), "date_label", "label", this.getLanguage()) + this.getParsedDate());
    Font initialFont = date.getFont();
    FontData[] fontData = initialFont.getFontData();
    for (int i = 0; i < fontData.length; i++) {
        fontData[i].setHeight(this.getFontSize() - 3);
    }
    Font newFont = new Font(DisplayManager.getDefaultDisplay(), fontData[0]);
    date.setFont(newFont);
    boolean hasCallerImage = this.hasCallerImage();
    Label image = new Label(g, SWT.BORDER | SWT.RIGHT);
    GridData gd = new GridData();
    gd.verticalSpan = 6;
    image.setVisible(false);
    if (hasCallerImage) {
        gd.widthHint = 92;
        gd.heightHint = 110;
        gd.horizontalIndent = 10;
        image.setVisible(true);
        image.setImage(this.getCallerImage());
    }
    image.setLayoutData(gd);
    Label msn = new Label(g, SWT.NONE);
    msn.setText(this.getI18nManager().getString(this.getNamespace(), "msn_label", "label", this.getLanguage()) + this.getParsedMsn());
    initialFont = msn.getFont();
    fontData = initialFont.getFontData();
    for (int i = 0; i < fontData.length; i++) {
        fontData[i].setHeight(this.getFontSize() - 3);
        fontData[i].setStyle(SWT.BOLD);
    }
    newFont = new Font(DisplayManager.getDefaultDisplay(), fontData[0]);
    msn.setFont(newFont);
    Label callerLabel = new Label(g, SWT.NONE);
    callerLabel.setText(this.getI18nManager().getString(this.getNamespace(), "caller_label", "label", this.getLanguage()));
    initialFont = callerLabel.getFont();
    fontData = initialFont.getFontData();
    for (int i = 0; i < fontData.length; i++) {
        fontData[i].setHeight(this.getFontSize() - 3);
    }
    newFont = new Font(DisplayManager.getDefaultDisplay(), fontData[0]);
    callerLabel.setFont(newFont);
    caller = new Label(g, SWT.WRAP);
    caller.setText(this.getParsedCaller());
    caller.setForeground(new Color(DisplayManager.getDefaultDisplay(), this.getColor()));
    initialFont = caller.getFont();
    fontData = initialFont.getFontData();
    for (int i = 0; i < fontData.length; i++) {
        fontData[i].setHeight(this.getFontSize());
        fontData[i].setStyle(SWT.BOLD);
    }
    newFont = new Font(DisplayManager.getDefaultDisplay(), fontData[0]);
    caller.setFont(newFont);
    caller.pack();
    this.checkCallerLength(caller);
    caller.pack();
    // added 2008/04/08: add provider image if present
    Composite numberbar = new Composite(g, SWT.NONE);
    ITableCellRenderer tr = RendererRegistry.getInstance().getRenderer("ProviderLogo".toLowerCase());
    Image img = null;
    Label l = null;
    if (tr != null && this.m_call != null && !isCliredCaller()) {
        tr.updateData(this.m_call);
        img = tr.renderAsImage();
    }
    numberbar.setLayout(new GridLayout((img != null ? 2 : 1), false));
    if (img != null) {
        l = new Label(numberbar, SWT.LEFT);
        l.setImage(new Image(DisplayManager.getDefaultDisplay(), img.getImageData().scaledTo(32, 32)));
    }
    Label number = new Label(numberbar, SWT.NONE);
    number.setText(this.getParsedNumber());
    number.setForeground(new Color(DisplayManager.getDefaultDisplay(), this.getColor()));
    initialFont = number.getFont();
    fontData = initialFont.getFontData();
    for (int i = 0; i < fontData.length; i++) {
        fontData[i].setHeight(this.getFontSize() - 3);
        fontData[i].setStyle(SWT.BOLD);
    }
    newFont = new Font(DisplayManager.getDefaultDisplay(), fontData[0]);
    number.setFont(newFont);
    new Label(g, SWT.NONE).setText(this.getParsedCip());
    // check for plugins
    List plugins = this.getPlugins(this.getConfiguration().getProperty("pluginlist", ""));
    Composite buttonbar = new Composite(composite, SWT.NONE);
    buttonbar.setLayout(new GridLayout(Math.max(4, (plugins.size() + 2)), false));
    // check for active reject service
    IService rejectService = this.getRuntime().getServiceFactory().getService("Reject");
    if (rejectService != null && rejectService.isEnabled()) {
        reject = new Button(buttonbar, SWT.PUSH);
        reject.setText(this.getI18nManager().getString(this.getNamespace(), "reject", "label", this.getLanguage()));
        reject.addSelectionListener(new SelectionAdapter() {

            public void widgetSelected(SelectionEvent e) {
                if (e.widget instanceof Button) {
                    reject.setEnabled(false);
                    IEventBroker eventBroker = getRuntime().getEventBroker();
                    if (getCall() != null)
                        getCall().setAttribute(getRuntime().getCallFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_CALLSTATUS, IJAMConst.ATTRIBUTE_VALUE_REJECTED));
                    eventBroker.send(Dialog.this, eventBroker.createEvent(IEventConst.EVENT_TYPE_CALLREJECTED, getCall()));
                }
            }
        });
    }
    // dialog close manually
    if (this.getShowTime() == -2) {
        Button close = new Button(buttonbar, SWT.PUSH);
        close.setText(this.getI18nManager().getString(this.getNamespace(), "close", "label", this.getLanguage()));
        close.addSelectionListener(new SelectionAdapter() {

            public void widgetSelected(SelectionEvent e) {
                if (e.widget instanceof Button) {
                    close();
                }
            }
        });
    }
    // name assign is active
    if (this.isAssignement() && !this.isCliredCaller()) {
        Button assign = new Button(buttonbar, SWT.PUSH);
        assign.setText(this.getI18nManager().getString(this.getNamespace(), "assign", "label", this.getLanguage()));
        assign.addSelectionListener(new SelectionAdapter() {

            public void widgetSelected(SelectionEvent e) {
                if (e.widget instanceof Button) {
                    Thread thread = new Thread() {

                        public void run() {
                            DisplayManager.getDefaultDisplay().asyncExec(new NameAssignDialog(getCaller()));
                        }
                    };
                    thread.setName(getID());
                    thread.start();
                }
            }
        });
    }
    // add plugins
    String classString = null;
    for (int i = 0, j = plugins.size(); i < j; i++) {
        classString = this.getConfiguration().getProperty((String) plugins.get(i));
        if (classString != null && classString.trim().length() > 0) {
            try {
                Class classObject = Thread.currentThread().getContextClassLoader().loadClass(classString);
                final IDialogPlugin plugin = (IDialogPlugin) classObject.newInstance();
                plugin.setDialog(this);
                plugin.setID((String) plugins.get(i));
                if (plugin.isEnabled()) {
                    Button button = new Button(buttonbar, SWT.PUSH);
                    button.setText(plugin.getLabel());
                    button.pack();
                    button.addSelectionListener(new SelectionAdapter() {

                        public void widgetSelected(SelectionEvent e) {
                            if (e.widget instanceof Button) {
                                plugin.run();
                            }
                        }
                    });
                }
            } catch (ClassNotFoundException e) {
                this.m_logger.warning("Class not found: " + classString);
            } catch (InstantiationException e) {
                this.m_logger.log(Level.SEVERE, e.getMessage(), e);
            } catch (IllegalAccessException e) {
                this.m_logger.log(Level.SEVERE, e.getMessage(), e);
            }
        }
    }
    if (this.getShowTime() > 0) {
        Timer aTimer = new Timer();
        aTimer.schedule(new TimerTask() {

            public void run() {
                new SWTExecuter(getID()) {

                    protected void execute() {
                        close();
                    }
                }.start();
            }
        }, (long) ((this.getShowDuration() + 1) * 1000));
    }
    gd = new GridData();
    if (!hasCallerImage) {
        gd.widthHint = Math.max(350, this.caller.getBounds().width + 10);
    }
    g.setLayoutData(gd);
    parent.getShell().pack();
    return composite;
}
Also used : GridLayout(org.eclipse.swt.layout.GridLayout) SelectionEvent(org.eclipse.swt.events.SelectionEvent) List(java.util.List) SWTExecuter(de.janrufmonitor.ui.swt.SWTExecuter) IService(de.janrufmonitor.service.IService) ITableCellRenderer(de.janrufmonitor.ui.jface.application.rendering.ITableCellRenderer) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) GridData(org.eclipse.swt.layout.GridData)

Example 13 with IService

use of de.janrufmonitor.service.IService in project janrufmonitor by tbrandt77.

the class ExtendedBalloonDialog method createDialog.

public synchronized void createDialog() {
    Composite c = this.getContents();
    prepareDialog(c, getShell());
    final Color color = new Color(getShell().getDisplay(), 255, 255, 225);
    // Buttons
    Composite buttonBar = new Composite(c, SWT.NONE);
    GridData gd = new GridData();
    gd.horizontalSpan = this.m_columnCount;
    // check for plugins
    List plugins = this.getPlugins(this.getConfiguration().getProperty("pluginlist", ""));
    GridLayout gl = new GridLayout(Math.max(5, (plugins.size() + 2)), false);
    gl.marginRight = 20;
    buttonBar.setLayout(gl);
    buttonBar.setLayoutData(gd);
    buttonBar.setBackground(color);
    // check for active reject service
    IService rejectService = this.getRuntime().getServiceFactory().getService("Reject");
    if (rejectService != null && rejectService.isEnabled()) {
        final HyperLink reject = new HyperLink(buttonBar, SWT.LEFT);
        reject.setBackground(color);
        reject.setText(this.getI18nManager().getString(this.getNamespace(), "reject", "label", this.getLanguage()));
        reject.pack();
        reject.addMouseListener(new MouseAdapter() {

            public void mouseDown(MouseEvent e) {
                if (e.button == 1) {
                    reject.setEnabled(false);
                    reject.setText(getI18nManager().getString(getNamespace(), "rejected", "label", getLanguage()));
                    reject.setUnderline(color);
                    reject.setActiveUnderline(color);
                    reject.setHoverUnderline(color);
                    reject.pack(true);
                    IEventBroker eventBroker = getRuntime().getEventBroker();
                    if (m_call != null)
                        m_call.setAttribute(getRuntime().getCallFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_CALLSTATUS, IJAMConst.ATTRIBUTE_VALUE_REJECTED));
                    eventBroker.send(ExtendedBalloonDialog.this, eventBroker.createEvent(IEventConst.EVENT_TYPE_CALLREJECTED, m_call));
                }
            }
        });
    }
    if (this.isAssignement() && !this.isCliredCaller()) {
        final IDialogPlugin assignPlugin = new AssignPlugin();
        assignPlugin.setDialog(this);
        HyperLink hl = new HyperLink(buttonBar, SWT.LEFT);
        hl.setText(assignPlugin.getLabel());
        hl.setBackground(color);
        hl.pack();
        hl.addMouseListener(new MouseAdapter() {

            public void mouseDown(MouseEvent e) {
                if (e.button == 1) {
                    assignPlugin.run();
                }
            }
        });
    }
    // add plugins
    String classString = null;
    for (int i = 0, j = plugins.size(); i < j; i++) {
        classString = this.getConfiguration().getProperty((String) plugins.get(i));
        if (classString != null && classString.trim().length() > 0) {
            try {
                Class classObject = Thread.currentThread().getContextClassLoader().loadClass(classString);
                final IDialogPlugin plugin = (IDialogPlugin) classObject.newInstance();
                plugin.setDialog(this);
                plugin.setID((String) plugins.get(i));
                if (plugin.isEnabled()) {
                    HyperLink hl = new HyperLink(buttonBar, SWT.LEFT);
                    hl.setText(plugin.getLabel());
                    hl.setBackground(color);
                    hl.pack();
                    hl.addMouseListener(new MouseAdapter() {

                        public void mouseDown(MouseEvent e) {
                            if (e.button == 1) {
                                plugin.run();
                            }
                        }
                    });
                }
            } catch (ClassNotFoundException e) {
                this.m_logger.warning("Class not found: " + classString);
            } catch (InstantiationException e) {
                this.m_logger.log(Level.SEVERE, e.getMessage(), e);
            } catch (IllegalAccessException e) {
                this.m_logger.log(Level.SEVERE, e.getMessage(), e);
            }
        }
    }
    color.dispose();
    c.pack();
}
Also used : MouseEvent(org.eclipse.swt.events.MouseEvent) Color(org.eclipse.swt.graphics.Color) MouseAdapter(org.eclipse.swt.events.MouseAdapter) HyperLink(de.janrufmonitor.ui.jface.application.controls.HyperLink) GridLayout(org.eclipse.swt.layout.GridLayout) GridData(org.eclipse.swt.layout.GridData) List(java.util.List) IService(de.janrufmonitor.service.IService)

Example 14 with IService

use of de.janrufmonitor.service.IService in project janrufmonitor by tbrandt77.

the class CommentDialog method getHandler.

private CommentCallerHandler getHandler() {
    IService service = PIMRuntime.getInstance().getServiceFactory().getService("CommentService");
    if (service != null) {
        if (service instanceof CommentService) {
            CommentService commentService = (CommentService) service;
            CommentCallerHandler cch = commentService.getHandler();
            return cch;
        }
    }
    return null;
}
Also used : CommentService(de.janrufmonitor.service.comment.CommentService) CommentCallerHandler(de.janrufmonitor.service.comment.CommentCallerHandler) IService(de.janrufmonitor.service.IService)

Example 15 with IService

use of de.janrufmonitor.service.IService in project janrufmonitor by tbrandt77.

the class Refresh method run.

public void run() {
    ProgressMonitorDialog pmd = new ProgressMonitorDialog(DisplayManager.getDefaultDisplay().getActiveShell());
    try {
        IRunnableWithProgress r = new IRunnableWithProgress() {

            public void run(IProgressMonitor progressMonitor) {
                IService srv = getRuntime().getServiceFactory().getService(SynchronizerService.ID);
                if (srv != null && srv instanceof SynchronizerService && srv.isEnabled()) {
                    ((SynchronizerService) srv).synchronize(progressMonitor);
                }
            }
        };
        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);
    }
    m_app.updateViews(true);
    return;
}
Also used : SynchronizerService(de.janrufmonitor.service.fritzbox.SynchronizerService) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) IService(de.janrufmonitor.service.IService) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress)

Aggregations

IService (de.janrufmonitor.service.IService)18 List (java.util.List)6 ICaller (de.janrufmonitor.framework.ICaller)5 CommentService (de.janrufmonitor.service.comment.CommentService)5 GridData (org.eclipse.swt.layout.GridData)4 GridLayout (org.eclipse.swt.layout.GridLayout)4 ICall (de.janrufmonitor.framework.ICall)3 CommentCallerHandler (de.janrufmonitor.service.comment.CommentCallerHandler)3 SWTExecuter (de.janrufmonitor.ui.swt.SWTExecuter)3 Color (org.eclipse.swt.graphics.Color)3 Shell (org.eclipse.swt.widgets.Shell)3 Message (de.janrufmonitor.exception.Message)2 IMonitorListener (de.janrufmonitor.framework.monitor.IMonitorListener)2 Comment (de.janrufmonitor.ui.jface.application.comment.Comment)2 HyperLink (de.janrufmonitor.ui.jface.application.controls.HyperLink)2 ITableCellRenderer (de.janrufmonitor.ui.jface.application.rendering.ITableCellRenderer)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 Method (java.lang.reflect.Method)2 ArrayList (java.util.ArrayList)2 Properties (java.util.Properties)2