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 });
}
}
}
}
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;
}
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;
}
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);
}
}
}
});
}
}
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();
}
Aggregations