Search in sources :

Example 1 with ITableCellRenderer

use of de.janrufmonitor.ui.jface.application.rendering.ITableCellRenderer in project janrufmonitor by tbrandt77.

the class JournalBuilder method parseRenderer.

private static String parseRenderer(String text, ICall call) {
    String prefix = "%r:";
    String postfix = "%";
    if (text.indexOf(prefix) > -1) {
        String id = text.substring(text.indexOf(prefix) + prefix.length(), text.indexOf(postfix, text.indexOf(prefix) + prefix.length()));
        ITableCellRenderer r = RendererRegistry.getInstance().getRenderer(id.toLowerCase());
        if (r != null) {
            r.updateData(call);
            text = StringUtils.replaceString(text, prefix + id + postfix, r.renderAsText());
        } else {
            text = StringUtils.replaceString(text, prefix + id + postfix, "");
        }
    }
    return text;
}
Also used : ITableCellRenderer(de.janrufmonitor.ui.jface.application.rendering.ITableCellRenderer)

Example 2 with ITableCellRenderer

use of de.janrufmonitor.ui.jface.application.rendering.ITableCellRenderer in project janrufmonitor by tbrandt77.

the class BalloonDialog method createDialog.

public void createDialog() {
    final Color color = new Color(getShell().getDisplay(), 255, 255, 225);
    boolean hasCallerImage = this.hasCallerImage();
    Composite c = this.getContents();
    c.setLayout(new GridLayout((hasCallerImage ? 2 : 1), false));
    if (hasCallerImage) {
        Label image = new Label(c, SWT.BORDER | SWT.RIGHT);
        GridData gd = new GridData();
        gd.verticalSpan = 5;
        image.setVisible(false);
        gd.widthHint = 92;
        gd.heightHint = 110;
        gd.horizontalIndent = 10;
        image.setVisible(true);
        image.setImage(this.getCallerImage());
        image.setLayoutData(gd);
    }
    // date
    Label l = new Label(c, SWT.NONE);
    l.setText(this.getI18nManager().getString(this.getNamespace(), "date_label", "label", this.getLanguage()) + this.getParsedDate());
    Font initialFont = l.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]);
    l.setFont(newFont);
    l.setBackground(color);
    // MSN
    l = new Label(c, SWT.NONE);
    l.setText(this.getI18nManager().getString(this.getNamespace(), "msn_label", "label", this.getLanguage()) + this.getParsedMsn());
    initialFont = l.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]);
    l.setFont(newFont);
    l.setBackground(color);
    // caller name +  additional
    l = new Label(c, SWT.LEFT);
    l.setText(this.getParsedCaller());
    l.setBackground(color);
    l.setForeground(new Color(DisplayManager.getDefaultDisplay(), this.getColor()));
    initialFont = l.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]);
    l.setFont(newFont);
    l.pack();
    this.checkCallerLength(l);
    l.pack();
    // number
    // added 2008/04/08: add provider image if present
    Composite numberbar = new Composite(c, SWT.NONE);
    numberbar.setBackground(color);
    ITableCellRenderer tr = RendererRegistry.getInstance().getRenderer("ProviderLogo".toLowerCase());
    Image img = 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.setBackground(color);
        l.setImage(new Image(DisplayManager.getDefaultDisplay(), img.getImageData().scaledTo(32, 32)));
    }
    l = new Label(numberbar, SWT.LEFT);
    l.setText(this.getParsedNumber());
    l.setBackground(color);
    l.setForeground(new Color(DisplayManager.getDefaultDisplay(), this.getColor()));
    initialFont = l.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]);
    l.setFont(newFont);
    l.pack();
    // CIP
    l = new Label(c, SWT.LEFT);
    l.setText(this.getParsedCip());
    l.setBackground(color);
    l.pack();
    // Buttons
    Composite buttonBar = new Composite(c, SWT.NONE);
    GridData gd = new GridData();
    gd.horizontalSpan = 2;
    // 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);
    // Label la = new Label(buttonBar, SWT.LEFT);
    // la.setText("       ");
    // la.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(BalloonDialog.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 : HyperLink(de.janrufmonitor.ui.jface.application.controls.HyperLink) GridLayout(org.eclipse.swt.layout.GridLayout) List(java.util.List) IService(de.janrufmonitor.service.IService) ITableCellRenderer(de.janrufmonitor.ui.jface.application.rendering.ITableCellRenderer) MouseEvent(org.eclipse.swt.events.MouseEvent) MouseAdapter(org.eclipse.swt.events.MouseAdapter) GridData(org.eclipse.swt.layout.GridData)

Example 3 with ITableCellRenderer

use of de.janrufmonitor.ui.jface.application.rendering.ITableCellRenderer in project janrufmonitor by tbrandt77.

the class RendererRegistry method getAllRendererIDsForApplication.

public List getAllRendererIDsForApplication(AbstractApplication a) {
    List l = new ArrayList();
    Iterator iter = this.m_renderer.keySet().iterator();
    String key = null;
    ITableCellRenderer tr = null;
    while (iter.hasNext()) {
        key = (String) iter.next();
        tr = this.getRenderer(key);
        if (tr != null && a.isSupportingRenderer(tr))
            l.add(key);
    }
    return l;
}
Also used : ITableCellRenderer(de.janrufmonitor.ui.jface.application.rendering.ITableCellRenderer) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List)

Example 4 with ITableCellRenderer

use of de.janrufmonitor.ui.jface.application.rendering.ITableCellRenderer in project janrufmonitor by tbrandt77.

the class RendererRegistry method setConfiguration.

public void setConfiguration(Properties configuration) {
    this.m_configuration = configuration;
    this.m_renderer = Collections.synchronizedMap(new HashMap(this.m_configuration.size()));
    Iterator iter = this.m_configuration.keySet().iterator();
    while (iter.hasNext()) {
        String key = (String) iter.next();
        // check for .class attribute in properties file
        if (key.startsWith(PARAMETERNAME)) {
            String className = this.m_configuration.getProperty(key);
            try {
                Class classObject = Thread.currentThread().getContextClassLoader().loadClass(className);
                // add a renderer to renderer list
                ITableCellRenderer is = (ITableCellRenderer) classObject.newInstance();
                // check for external IDs
                String id = key.substring(PARAMETERNAME.length());
                if (this.m_configuration.getProperty(id + "_id") != null) {
                    is.setID(this.m_configuration.getProperty(id + "_id"));
                }
                this.m_renderer.put(is.getID().toLowerCase(), is);
                this.m_logger.info("Registered new renderer <" + is.getID().toLowerCase() + ">.");
            } catch (ClassNotFoundException ex) {
                this.m_logger.severe("Could not find class: " + className);
            } catch (InstantiationException ex) {
                this.m_logger.severe("Could not instantiate class: " + className);
            } catch (IllegalAccessException ex) {
                this.m_logger.severe("Could not access class: " + className);
            } catch (Exception ex) {
                this.m_logger.log(Level.SEVERE, ex.getMessage(), ex);
            }
        }
    }
}
Also used : ITableCellRenderer(de.janrufmonitor.ui.jface.application.rendering.ITableCellRenderer) HashMap(java.util.HashMap) Iterator(java.util.Iterator)

Example 5 with ITableCellRenderer

use of de.janrufmonitor.ui.jface.application.rendering.ITableCellRenderer in project janrufmonitor by tbrandt77.

the class AbstractTableApplication method buildTableColumns.

private void buildTableColumns() {
    Table t = ((TableViewer) viewer).getTable();
    int columnCount = this.getTableColumnCount();
    String[] columnHeader = new String[columnCount];
    CellEditor[] editors = new CellEditor[columnCount];
    ITableCellRenderer r = null;
    for (int i = 0; i < columnCount; i++) {
        columnHeader[i] = this.getColumnID(i);
        // check renderer type
        r = RendererRegistry.getInstance().getRenderer(columnHeader[i]);
        if (r instanceof ITableCellEditorRenderer) {
            switch(((ITableCellEditorRenderer) r).getType()) {
                case 1:
                    editors[i] = new ComboBoxCellEditor(t, ((ITableCellEditorRenderer) r).getValues(), SWT.READ_ONLY);
                    break;
                case 2:
                    editors[i] = new CheckboxCellEditor(t);
                    break;
                default:
                    // editors[i] = new TextCellEditor(t);
                    editors[i] = new TextCellEditor(t);
            }
        } else {
            // editors[i] = new TextCellEditor(t);
            editors[i] = new TextCellEditor(t, SWT.WRAP);
        }
    }
    ((TableViewer) this.viewer).setColumnProperties(columnHeader);
    ((TableViewer) this.viewer).setCellEditors(editors);
    ((TableViewer) this.viewer).setCellModifier(new TableCellModifier(((TableViewer) viewer), this));
    TableColumn[] cols = t.getColumns();
    for (int i = 0; i < cols.length; i++) {
        cols[i].dispose();
    }
    int columns = this.getTableColumnCount();
    String id = "";
    for (int i = 0; i < columns; i++) {
        TableViewerColumn tc = new TableViewerColumn(((TableViewer) this.viewer), SWT.LEFT);
        id = getColumnID(i);
        ITableCellRenderer tr = RendererRegistry.getInstance().getRenderer(id);
        tc.getColumn().setText((tr != null ? tr.getHeader() : ""));
        tc.getColumn().setData(id);
        if (tr != null && tr.isRenderImage())
            tc.setLabelProvider(this.getImageCellLabelProvider(id));
        else
            tc.setLabelProvider(this.getTextCellLabelProvider(id));
        tc.getColumn().addSelectionListener(new SelectionAdapter() {

            public void widgetSelected(SelectionEvent e) {
                de.janrufmonitor.ui.jface.application.action.IAction action = getOrderAction();
                if (action != null && action instanceof org.eclipse.jface.action.IAction) {
                    Event ev = new Event();
                    ev.widget = e.widget;
                    ((org.eclipse.jface.action.IAction) action).runWithEvent(ev);
                }
            }
        });
        int width = Integer.parseInt(getConfiguration().getProperty(CFG_COLUMN_SIZE + id, "50"));
        if (width > -1) {
            tc.getColumn().setWidth(width);
        }
        tc.getColumn().addControlListener(new ControlAdapter() {

            public void controlResized(ControlEvent e) {
                if (e.widget instanceof TableColumn) {
                    TableColumn tc = (TableColumn) e.widget;
                    if (tc.getData() != null) {
                        String column = (String) tc.getData();
                        int width = tc.getWidth();
                        getConfiguration().setProperty(CFG_COLUMN_SIZE + column, Integer.toString(width));
                        storeConfiguration();
                        m_logger.info("Set column size to " + width);
                    }
                }
            }
        });
    }
    OwnerDrawLabelProvider.setUpOwnerDraw(((TableViewer) this.viewer));
}
Also used : CheckboxCellEditor(org.eclipse.jface.viewers.CheckboxCellEditor) CellEditor(org.eclipse.jface.viewers.CellEditor) CheckboxCellEditor(org.eclipse.jface.viewers.CheckboxCellEditor) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) ComboBoxCellEditor(org.eclipse.jface.viewers.ComboBoxCellEditor) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn) ITableCellRenderer(de.janrufmonitor.ui.jface.application.rendering.ITableCellRenderer) IAction(de.janrufmonitor.ui.jface.application.action.IAction) ITableCellEditorRenderer(de.janrufmonitor.ui.jface.application.rendering.ITableCellEditorRenderer) ComboBoxCellEditor(org.eclipse.jface.viewers.ComboBoxCellEditor) DropTargetEvent(org.eclipse.swt.dnd.DropTargetEvent) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) TableViewer(org.eclipse.jface.viewers.TableViewer)

Aggregations

ITableCellRenderer (de.janrufmonitor.ui.jface.application.rendering.ITableCellRenderer)19 List (java.util.List)8 ArrayList (java.util.ArrayList)5 ICall (de.janrufmonitor.framework.ICall)4 FileOutputStream (java.io.FileOutputStream)4 IOException (java.io.IOException)4 StringTokenizer (java.util.StringTokenizer)4 GridLayout (org.eclipse.swt.layout.GridLayout)4 Document (com.lowagie.text.Document)3 DocumentException (com.lowagie.text.DocumentException)3 Paragraph (com.lowagie.text.Paragraph)3 PdfPCell (com.lowagie.text.pdf.PdfPCell)3 PdfPTable (com.lowagie.text.pdf.PdfPTable)3 ICallList (de.janrufmonitor.framework.ICallList)3 Color (java.awt.Color)3 File (java.io.File)3 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)3 Viewer (org.eclipse.jface.viewers.Viewer)3 Clipboard (org.eclipse.swt.dnd.Clipboard)3 TextTransfer (org.eclipse.swt.dnd.TextTransfer)3