Search in sources :

Example 11 with ITableCellRenderer

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

the class NotesClipboardAction method run.

public void run() {
    Viewer v = this.m_app.getApplication().getViewer();
    if (v != null && v instanceof Viewer) {
        IStructuredSelection selection = (IStructuredSelection) v.getSelection();
        if (!selection.isEmpty()) {
            Object o = selection.getFirstElement();
            ITableCellRenderer tcr = RendererRegistry.getInstance().getRenderer("notes");
            if (tcr != null) {
                tcr.updateData(o);
                Clipboard cb = new Clipboard(DisplayManager.getDefaultDisplay());
                String textData = tcr.renderAsText();
                TextTransfer textTransfer = TextTransfer.getInstance();
                cb.setContents(new Object[] { (textData != null ? textData : "") }, new Transfer[] { textTransfer });
            }
        }
    }
}
Also used : ITableCellRenderer(de.janrufmonitor.ui.jface.application.rendering.ITableCellRenderer) Viewer(org.eclipse.jface.viewers.Viewer) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Clipboard(org.eclipse.swt.dnd.Clipboard) TextTransfer(org.eclipse.swt.dnd.TextTransfer)

Example 12 with ITableCellRenderer

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

the class PDFCallerListFilter method doExport.

public boolean doExport() {
    Document document = new Document(PageSize.A4.rotate());
    document.addCreationDate();
    document.addCreator("jAnrufmonitor");
    try {
        PdfWriter.getInstance(document, new FileOutputStream(this.m_filename));
        document.open();
        // get renderers
        List renderer = new ArrayList();
        String renderer_config = this.getRuntime().getConfigManagerFactory().getConfigManager().getProperty("ui.jface.application.editor.Editor", "renderer");
        if (renderer_config != null && renderer_config.length() > 0) {
            StringTokenizer s = new StringTokenizer(renderer_config, ",");
            while (s.hasMoreTokens()) {
                renderer.add(RendererRegistry.getInstance().getRenderer(s.nextToken()));
            }
        }
        // get column width
        float totalWidth = 0;
        String[] cWidth = new String[renderer.size()];
        for (int i = 0, j = renderer.size(); i < j; i++) {
            cWidth[i] = getRuntime().getConfigManagerFactory().getConfigManager().getProperty("ui.jface.application.editor.Editor", "col_size_" + ((ITableCellRenderer) renderer.get(i)).getID());
            if (cWidth[i] != null && cWidth[i].length() > 0) {
                totalWidth += Float.parseFloat(cWidth[i]);
            }
            if (cWidth[i] != null && cWidth[i].length() == 0) {
                cWidth[i] = "0";
            }
        }
        float[] widths = new float[renderer.size()];
        for (int i = 0, j = renderer.size(); i < j; i++) {
            widths[i] = Float.parseFloat(cWidth[i]) / totalWidth;
        }
        PdfPTable table = new PdfPTable(widths);
        table.setHeaderRows(1);
        table.setWidthPercentage(100f);
        ITableCellRenderer t = null;
        PdfPCell cell = null;
        for (int i = 0, j = renderer.size(); i < j; i++) {
            t = (ITableCellRenderer) renderer.get(i);
            if (t == null) {
                this.m_logger.severe("No renderer found for ID: " + (String) renderer.get(i));
                this.m_logger.severe("Export to PDF format canceled...");
                return false;
            }
            cell = new PdfPCell(new Paragraph(t.getHeader()));
            cell.setBackgroundColor(new Color(0xC0, 0xC0, 0xC0));
            table.addCell(cell);
        }
        ICaller c = null;
        String cellContent = null;
        Color iterateColor1 = new Color(0xDD, 0xDD, 0xDD);
        Color iterateColor2 = new Color(0xFF, 0xFF, 0xFF);
        cell = null;
        int type_col = -1, num_col = -1;
        for (int i = 0, j = this.m_callerList.size(); i < j; i++) {
            c = this.m_callerList.get(i);
            for (int k = 0, m = renderer.size(); k < m; k++) {
                t = (ITableCellRenderer) renderer.get(k);
                t.updateData(c);
                // find number and typ column for multiline callers
                if (t.getID().equalsIgnoreCase("NumberType"))
                    type_col = k;
                if (t.getID().equalsIgnoreCase("Number"))
                    num_col = k;
                cellContent = t.renderAsText();
                if (cellContent != null && cellContent.length() > 0) {
                    cell = new PdfPCell(new Phrase(cellContent));
                    cell.setBackgroundColor((i % 2 == 0 ? iterateColor1 : iterateColor2));
                    table.addCell(cell);
                } else {
                    cellContent = t.renderAsImageID();
                    if (cellContent != null && cellContent.length() > 0) {
                        if (cellContent.startsWith("db://")) {
                            InputStream in = ImageHandler.getInstance().getImageStream(c);
                            if (in != null) {
                                ByteArrayOutputStream out = new ByteArrayOutputStream();
                                Stream.copy(in, out, true);
                                in.close();
                                out.close();
                                Image pdfImage = Image.getInstance(out.toByteArray());
                                // pdfImage.scaleAbsolute(90.0f, 45.0f);
                                table.addCell(pdfImage);
                            } else {
                                table.addCell(" ");
                            }
                        } else if (new File(cellContent).exists()) {
                            Image pdfImage = Image.getInstance(cellContent);
                            table.addCell(pdfImage);
                        } else {
                            Image pdfImage = Image.getInstance(SWTImageManager.getInstance(PIMRuntime.getInstance()).getImagePath(cellContent));
                            table.addCell(pdfImage);
                        }
                    // ((Image pdfImage = Image.getInstance(cellContent);
                    // cell = new PdfPCell(pdfImage);
                    // cell.setBackgroundColor((i%2==0 ? iterateColor1 : iterateColor2));
                    // table.addCell(pdfImage);
                    } else {
                        cell = new PdfPCell(new Phrase(" "));
                        cell.setBackgroundColor((i % 2 == 0 ? iterateColor1 : iterateColor2));
                        table.addCell(cell);
                    }
                }
                // last column reached check for multiline caller
                if (k == m - 1 && (type_col > -1 || num_col > -1) && (c instanceof IMultiPhoneCaller) && (((IMultiPhoneCaller) c).getPhonenumbers().size() > 1)) {
                    List phones = ((IMultiPhoneCaller) c).getPhonenumbers();
                    IPhonenumber pn = null;
                    for (int y = 1, z = phones.size(); y < z; y++) {
                        pn = (IPhonenumber) phones.get(y);
                        for (int w = 0, x = renderer.size(); w < x; w++) {
                            t = (ITableCellRenderer) renderer.get(w);
                            if (t.getID().equalsIgnoreCase("NumberType") || t.getID().equalsIgnoreCase("Number")) {
                                if (t.getID().equalsIgnoreCase("NumberType")) {
                                    final IPhonenumber lpn = pn;
                                    final IAttributeMap lam = c.getAttributes();
                                    t.updateData(new ITreeItemCallerData() {

                                        public IAttributeMap getAttributes() {
                                            return lam;
                                        }

                                        public IPhonenumber getPhone() {
                                            return lpn;
                                        }
                                    });
                                } else
                                    t.updateData(pn);
                                cellContent = t.renderAsText();
                                if (cellContent != null && cellContent.length() > 0) {
                                    cell = new PdfPCell(new Phrase(cellContent));
                                    cell.setBackgroundColor((i % 2 == 0 ? iterateColor1 : iterateColor2));
                                    table.addCell(cell);
                                } else {
                                    cell = new PdfPCell(new Phrase(" "));
                                    cell.setBackgroundColor((i % 2 == 0 ? iterateColor1 : iterateColor2));
                                    table.addCell(cell);
                                }
                            } else {
                                cell = new PdfPCell(new Phrase(" "));
                                cell.setBackgroundColor((i % 2 == 0 ? iterateColor1 : iterateColor2));
                                table.addCell(cell);
                            }
                        }
                    }
                }
            }
        }
        document.add(table);
    } catch (DocumentException de) {
        this.m_logger.severe(de.getMessage());
        return false;
    } catch (IOException ioe) {
        this.m_logger.severe(ioe.getMessage());
        return false;
    } finally {
        document.close();
    }
    return true;
}
Also used : ArrayList(java.util.ArrayList) Document(com.lowagie.text.Document) Image(com.lowagie.text.Image) PdfPTable(com.lowagie.text.pdf.PdfPTable) DocumentException(com.lowagie.text.DocumentException) IAttributeMap(de.janrufmonitor.framework.IAttributeMap) ArrayList(java.util.ArrayList) ICallerList(de.janrufmonitor.framework.ICallerList) List(java.util.List) IMultiPhoneCaller(de.janrufmonitor.framework.IMultiPhoneCaller) ITableCellRenderer(de.janrufmonitor.ui.jface.application.rendering.ITableCellRenderer) PdfPCell(com.lowagie.text.pdf.PdfPCell) InputStream(java.io.InputStream) Color(java.awt.Color) Phrase(com.lowagie.text.Phrase) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) Paragraph(com.lowagie.text.Paragraph) ICaller(de.janrufmonitor.framework.ICaller) StringTokenizer(java.util.StringTokenizer) FileOutputStream(java.io.FileOutputStream) File(java.io.File) ITreeItemCallerData(de.janrufmonitor.ui.jface.application.ITreeItemCallerData) IPhonenumber(de.janrufmonitor.framework.IPhonenumber)

Example 13 with ITableCellRenderer

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

the class MessageBuilder method parseRenderer.

private static String parseRenderer(String text, ICall call) {
    String prefix = "%r:";
    String postfix = "%";
    while (text.indexOf(prefix) >= 0) {
        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 14 with ITableCellRenderer

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

the class AbstractTreeTableApplication method buildTableColumns.

private void buildTableColumns() {
    Tree t = ((TreeViewer) viewer).getTree();
    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);
        }
    }
    ((TreeViewer) this.viewer).setColumnProperties(columnHeader);
    ((TreeViewer) this.viewer).setCellEditors(editors);
    ((TreeViewer) this.viewer).setCellModifier(new TableCellModifier(((TreeViewer) viewer), this));
    TreeColumn[] 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++) {
        TreeViewerColumn tc = new TreeViewerColumn((TreeViewer) viewer, SWT.LEFT);
        id = getColumnID(i);
        ITableCellRenderer tr = RendererRegistry.getInstance().getRenderer(id);
        tc.getColumn().setText((tr != null ? tr.getHeader() : ""));
        tc.getColumn().setData(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);
                }
            }
        });
        tc.setLabelProvider(this.getTextCellLabelProvider(id));
        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 TreeColumn) {
                    TreeColumn tc = (TreeColumn) 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);
                    }
                }
            }
        });
    }
}
Also used : CheckboxCellEditor(org.eclipse.jface.viewers.CheckboxCellEditor) ControlAdapter(org.eclipse.swt.events.ControlAdapter) TreeViewer(org.eclipse.jface.viewers.TreeViewer) CellEditor(org.eclipse.jface.viewers.CellEditor) CheckboxCellEditor(org.eclipse.jface.viewers.CheckboxCellEditor) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) ComboBoxCellEditor(org.eclipse.jface.viewers.ComboBoxCellEditor) TreeColumn(org.eclipse.swt.widgets.TreeColumn) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Tree(org.eclipse.swt.widgets.Tree) ITableCellRenderer(de.janrufmonitor.ui.jface.application.rendering.ITableCellRenderer) IAction(de.janrufmonitor.ui.jface.application.action.IAction) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ITableCellEditorRenderer(de.janrufmonitor.ui.jface.application.rendering.ITableCellEditorRenderer) ComboBoxCellEditor(org.eclipse.jface.viewers.ComboBoxCellEditor) Point(org.eclipse.swt.graphics.Point) TreeViewerColumn(org.eclipse.jface.viewers.TreeViewerColumn) DropTargetEvent(org.eclipse.swt.dnd.DropTargetEvent) KeyEvent(org.eclipse.swt.events.KeyEvent) MouseEvent(org.eclipse.swt.events.MouseEvent) Event(org.eclipse.swt.widgets.Event) ControlEvent(org.eclipse.swt.events.ControlEvent) TreeEvent(org.eclipse.swt.events.TreeEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) ControlEvent(org.eclipse.swt.events.ControlEvent)

Example 15 with ITableCellRenderer

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

the class TableCellModifier method modify.

public void modify(Object element, String column, Object value) {
    if (element instanceof Item)
        element = ((Item) element).getData();
    ITableCellRenderer r = RendererRegistry.getInstance().getRenderer(column);
    if (r instanceof ITableAttributeCellEditorRenderer && ((ITableAttributeCellEditorRenderer) r).getAttribute() != null) {
        if (element instanceof ICall) {
            ICall c = ((ICall) element);
            IAttribute cAtt = c.getAttribute(((ITableAttributeCellEditorRenderer) r).getAttribute().getName());
            if (cAtt != null && value instanceof String) {
                if (cAtt.getValue().equalsIgnoreCase((String) value)) {
                    return;
                }
            }
            IAttribute att = ((ITableAttributeCellEditorRenderer) r).getAttribute();
            ((ITableAttributeCellEditorRenderer) r).applyAttributeChanges(c, att, value);
            if (this.m_ac.getController() instanceof IExtendedApplicationController) {
                ((IExtendedApplicationController) this.m_ac.getController()).updateElement(c, false);
            } else {
                this.m_ac.getController().updateElement(c);
            }
        }
        if (element instanceof ICaller) {
            ICaller c = ((ICaller) element);
            IAttribute cAtt = c.getAttribute(((ITableAttributeCellEditorRenderer) r).getAttribute().getName());
            if (cAtt != null && value instanceof String) {
                if (cAtt.getValue().equalsIgnoreCase((String) value)) {
                    return;
                }
            }
            IAttribute att = ((ITableAttributeCellEditorRenderer) r).getAttribute();
            ((ITableAttributeCellEditorRenderer) r).applyAttributeChanges(c, att, value);
            if (this.m_ac.getController() instanceof IExtendedApplicationController) {
                ((IExtendedApplicationController) this.m_ac.getController()).updateElement(c, false);
            } else {
                this.m_ac.getController().updateElement(c);
            }
        }
    }
    this.m_v.refresh();
}
Also used : Item(org.eclipse.swt.widgets.Item) ITableCellRenderer(de.janrufmonitor.ui.jface.application.rendering.ITableCellRenderer) ICaller(de.janrufmonitor.framework.ICaller) ICall(de.janrufmonitor.framework.ICall) IAttribute(de.janrufmonitor.framework.IAttribute) ITableAttributeCellEditorRenderer(de.janrufmonitor.ui.jface.application.rendering.ITableAttributeCellEditorRenderer)

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