Search in sources :

Example 1 with DisplayTextDialog

use of name.abuchen.portfolio.ui.dialogs.DisplayTextDialog in project portfolio by buchen.

the class ErrorLogPart method createComposite.

@PostConstruct
public void createComposite(Composite parent, LogEntryCache cache) {
    this.entries = cache.getEntries();
    Composite container = new Composite(parent, SWT.NONE);
    TreeColumnLayout layout = new TreeColumnLayout();
    container.setLayout(layout);
    logViewer = new TreeViewer(container, SWT.FULL_SELECTION);
    TreeViewerColumn column = new TreeViewerColumn(logViewer, SWT.NONE);
    column.getColumn().setText(Messages.ColumnDate);
    layout.setColumnData(column.getColumn(), new ColumnPixelData(140));
    column.setLabelProvider(new ColumnLabelProvider() {

        private DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);

        @Override
        public String getText(Object element) {
            return dateFormat.format(((LogEntry) element).getDate());
        }
    });
    column = new TreeViewerColumn(logViewer, SWT.NONE);
    column.getColumn().setText(Messages.ColumnMessage);
    layout.setColumnData(column.getColumn(), new ColumnPixelData(500));
    column.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            return ((LogEntry) element).getMessage();
        }

        @Override
        public Image getImage(Object element) {
            LogEntry entry = (LogEntry) element;
            switch(entry.getSeverity()) {
                case IStatus.ERROR:
                    return Images.ERROR.image();
                case IStatus.WARNING:
                    return Images.WARNING.image();
                default:
                    return Images.INFO.image();
            }
        }
    });
    logViewer.getTree().setHeaderVisible(true);
    logViewer.getTree().setLinesVisible(true);
    logViewer.setContentProvider(new LogEntryContentProvider());
    logViewer.setInput(entries);
    logViewer.addDoubleClickListener(new IDoubleClickListener() {

        @Override
        public void doubleClick(DoubleClickEvent event) {
            LogEntry entry = (LogEntry) ((IStructuredSelection) event.getSelection()).getFirstElement();
            DisplayTextDialog dialog = new DisplayTextDialog(Display.getCurrent().getActiveShell(), entry.getText());
            dialog.open();
        }
    });
}
Also used : Composite(org.eclipse.swt.widgets.Composite) TreeColumnLayout(org.eclipse.jface.layout.TreeColumnLayout) DisplayTextDialog(name.abuchen.portfolio.ui.dialogs.DisplayTextDialog) TreeViewer(org.eclipse.jface.viewers.TreeViewer) ColumnPixelData(org.eclipse.jface.viewers.ColumnPixelData) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Image(org.eclipse.swt.graphics.Image) TreeViewerColumn(org.eclipse.jface.viewers.TreeViewerColumn) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) DateFormat(java.text.DateFormat) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) PostConstruct(javax.annotation.PostConstruct)

Example 2 with DisplayTextDialog

use of name.abuchen.portfolio.ui.dialogs.DisplayTextDialog in project portfolio by buchen.

the class CreateTextFromPDFHandler method execute.

@Execute
public void execute(@Named(IServiceConstants.ACTIVE_PART) MPart part, @Named(IServiceConstants.ACTIVE_SHELL) Shell shell) throws IOException {
    FileDialog fileDialog = new FileDialog(shell, SWT.OPEN | SWT.SINGLE);
    fileDialog.setText(Messages.PDFImportDebugTextExtraction);
    fileDialog.setFilterNames(new String[] { Messages.PDFImportFilterName });
    // $NON-NLS-1$
    fileDialog.setFilterExtensions(new String[] { "*.pdf" });
    fileDialog.open();
    String fileName = fileDialog.getFileName();
    if (fileName == null || fileName.isEmpty())
        return;
    try {
        PDFInputFile inputFile = new PDFInputFile(new File(fileDialog.getFilterPath(), fileName));
        inputFile.parse();
        String text = MessageFormat.format(Messages.PDFImportDebugAuthor, inputFile.getAuthor());
        // $NON-NLS-1$
        text += "\nPDFBox Version: " + inputFile.getPDFBoxVersion().toString();
        // $NON-NLS-1$
        text += "\n-----------------------------------------\n";
        // CRLF to spac; //$NON-NLS-1$ //$NON-NLS-2$
        text += inputFile.getText().replace("\r", "");
        new DisplayTextDialog(shell, text).open();
    } catch (IOException e) {
        PortfolioPlugin.log(e);
        MessageDialog.openError(shell, Messages.LabelError, e.getMessage());
    }
}
Also used : DisplayTextDialog(name.abuchen.portfolio.ui.dialogs.DisplayTextDialog) PDFInputFile(name.abuchen.portfolio.datatransfer.pdf.PDFInputFile) IOException(java.io.IOException) FileDialog(org.eclipse.swt.widgets.FileDialog) PDFInputFile(name.abuchen.portfolio.datatransfer.pdf.PDFInputFile) File(java.io.File) Execute(org.eclipse.e4.core.di.annotations.Execute)

Aggregations

DisplayTextDialog (name.abuchen.portfolio.ui.dialogs.DisplayTextDialog)2 File (java.io.File)1 IOException (java.io.IOException)1 DateFormat (java.text.DateFormat)1 PostConstruct (javax.annotation.PostConstruct)1 PDFInputFile (name.abuchen.portfolio.datatransfer.pdf.PDFInputFile)1 Execute (org.eclipse.e4.core.di.annotations.Execute)1 TreeColumnLayout (org.eclipse.jface.layout.TreeColumnLayout)1 ColumnLabelProvider (org.eclipse.jface.viewers.ColumnLabelProvider)1 ColumnPixelData (org.eclipse.jface.viewers.ColumnPixelData)1 DoubleClickEvent (org.eclipse.jface.viewers.DoubleClickEvent)1 IDoubleClickListener (org.eclipse.jface.viewers.IDoubleClickListener)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 TreeViewer (org.eclipse.jface.viewers.TreeViewer)1 TreeViewerColumn (org.eclipse.jface.viewers.TreeViewerColumn)1 Image (org.eclipse.swt.graphics.Image)1 Composite (org.eclipse.swt.widgets.Composite)1 FileDialog (org.eclipse.swt.widgets.FileDialog)1