Search in sources :

Example 1 with UnboundedFifoBuffer

use of org.apache.commons.collections.buffer.UnboundedFifoBuffer in project tdi-studio-se by Talend.

the class RuntimeGraphcsComposite method createReportField.

/*  private void createInfoField(Composite parent) {

        infoComposite = createFlatFormComposite(parent, new FormToolkit(Display.getDefault()));
        FormLayout reportLayout = new FormLayout();
        reportLayout.marginWidth = 0;
        reportLayout.marginHeight = 0;
        infoComposite.setLayout(reportLayout);
        FormData reportData = new FormData();
        reportData.left = new FormAttachment(65, 5);
        reportData.right = new FormAttachment(100, -5);
        reportData.top = new FormAttachment(50, 0);
        reportData.bottom = new FormAttachment(100, -5);
        infoComposite.setLayoutData(reportData);

        Group group = new Group(infoComposite, SWT.NULL);
        FormLayout groupLayout = new FormLayout();
        groupLayout.marginWidth = 0;
        groupLayout.marginHeight = 0;
        group.setLayout(groupLayout);
        FormData groupData = new FormData();
        groupData.left = new FormAttachment(0, 0);
        groupData.right = new FormAttachment(100, 0);
        groupData.top = new FormAttachment(0, 0);
        groupData.bottom = new FormAttachment(100, 0);
        group.setLayoutData(groupData);
        group.setText("Run job Informations");

        infoField = new Text(group, SWT.BORDER | SWT.WRAP | SWT.V_SCROLL | SWT.READ_ONLY);
        infoField.setEditable(false);
        infoField.setBackground(group.getBackground());

        FormData data;
        data = new FormData();
        data.left = new FormAttachment(0, 0);
        data.right = new FormAttachment(100, 0);
        data.top = new FormAttachment(0, 0);
        data.bottom = new FormAttachment(100, 0);
        infoField.setLayoutData(data);
    }*/
private void createReportField(Composite parent) {
    reportComposite = createFlatFormComposite(parent, new FormToolkit(Display.getDefault()));
    FormLayout reportLayout = new FormLayout();
    reportComposite.setLayout(reportLayout);
    FormData reportData = new FormData();
    reportData.left = new FormAttachment(65, 5);
    reportData.right = new FormAttachment(100, -5);
    reportData.top = new FormAttachment(0, 0);
    reportData.bottom = new FormAttachment(100, -5);
    reportComposite.setLayoutData(reportData);
    Group group = new Group(reportComposite, SWT.NULL);
    FormLayout groupLayout = new FormLayout();
    group.setLayout(groupLayout);
    FormData groupData = new FormData();
    groupData.left = new FormAttachment(0, 0);
    groupData.right = new FormAttachment(100, 0);
    groupData.top = new FormAttachment(0, 0);
    groupData.bottom = new FormAttachment(100, 0);
    group.setLayoutData(groupData);
    //$NON-NLS-1$
    group.setText("Job execution information");
    reportField = new StyledText(group, SWT.WRAP | SWT.V_SCROLL | SWT.READ_ONLY);
    //may be CoreUIPlugin.setCSSClass can do this globally ,check later
    reportField.setBackground(getDisplay().getSystemColor(SWT.COLOR_WHITE));
    FormData data;
    data = new FormData();
    data.left = new FormAttachment(0, 0);
    data.right = new FormAttachment(100, 0);
    data.top = new FormAttachment(0, 0);
    data.bottom = new FormAttachment(93, 0);
    reportField.setLayoutData(data);
    displayReportField();
    //export button
    Button exportButton = new Button(group, SWT.PUSH);
    //$NON-NLS-1$
    exportButton.setText("Export");
    FormData exportData = new FormData();
    exportData.left = new FormAttachment(100, -70);
    exportData.right = new FormAttachment(100, 0);
    exportData.bottom = new FormAttachment(100, -1);
    exportButton.setLayoutData(exportData);
    exportButton.setEnabled(true);
    exportButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            if (messageManager == null || messageManager.getMessages().size() < 1) {
                //$NON-NLS-1$ //$NON-NLS-2$
                MessageDialog.openWarning(getShell(), "Warning", "No log to export.");
                return;
            }
            UnboundedFifoBuffer messages = messageManager.getMessages();
            Iterator iterator = messages.iterator();
            StringBuilder content = new StringBuilder();
            while (iterator.hasNext()) {
                ReportMessage message = (ReportMessage) iterator.next();
                content.append(message.getContent());
            }
            if (isMonitoring) {
                //$NON-NLS-1$ //$NON-NLS-2$
                MessageDialog.openWarning(getShell(), "Warning", "Waiting for job done.");
                return;
            }
            FileDialog dialog = new FileDialog(getShell(), SWT.SAVE);
            //$NON-NLS-1$
            dialog.setFilterPath(".");
            String fileName = dialog.open();
            if (fileName != null) {
                FileWriter writer = null;
                try {
                    writer = new FileWriter(fileName);
                    writer.write(content.toString());
                } catch (IOException e1) {
                    e1.printStackTrace();
                } finally {
                    try {
                        if (writer != null) {
                            writer.close();
                        }
                    } catch (IOException e1) {
                        e1.printStackTrace();
                    }
                }
            }
        }
    });
}
Also used : FormLayout(org.eclipse.swt.layout.FormLayout) FormData(org.eclipse.swt.layout.FormData) IMonitoredMXBeanGroup(org.talend.designer.runtime.visualization.MBean.IMonitoredMXBeanGroup) Group(org.eclipse.swt.widgets.Group) StyledText(org.eclipse.swt.custom.StyledText) FormToolkit(org.eclipse.ui.forms.widgets.FormToolkit) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) FileWriter(java.io.FileWriter) ReportMessage(org.talend.designer.runtime.visualization.ReportMessage) IOException(java.io.IOException) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Iterator(java.util.Iterator) UnboundedFifoBuffer(org.apache.commons.collections.buffer.UnboundedFifoBuffer) FileDialog(org.eclipse.swt.widgets.FileDialog) FormAttachment(org.eclipse.swt.layout.FormAttachment)

Example 2 with UnboundedFifoBuffer

use of org.apache.commons.collections.buffer.UnboundedFifoBuffer in project tdi-studio-se by Talend.

the class RuntimeGraphcsComposite method displayReportField.

public void displayReportField() {
    if (reportField != null && !reportField.isDisposed()) {
        if (messageManager == null) {
            return;
        }
        UnboundedFifoBuffer messages = messageManager.getMessages();
        Iterator iterator = messages.iterator();
        StringBuilder content = new StringBuilder();
        StyleRange[] styleRanges = new StyleRange[messages.size()];
        int i = 0;
        while (iterator.hasNext()) {
            ReportMessage message = (ReportMessage) iterator.next();
            content.append(message.getContent());
            styleRanges[i++] = message.getType();
        }
        reportField.setText(content.toString());
        reportField.setStyleRanges(styleRanges);
        //            reportField.setForeground(new Color(Display.getDefault(), 255, 0, 0));
        reportField.setTopIndex(Integer.MAX_VALUE);
    }
}
Also used : StyleRange(org.eclipse.swt.custom.StyleRange) Iterator(java.util.Iterator) UnboundedFifoBuffer(org.apache.commons.collections.buffer.UnboundedFifoBuffer) ReportMessage(org.talend.designer.runtime.visualization.ReportMessage)

Aggregations

Iterator (java.util.Iterator)2 UnboundedFifoBuffer (org.apache.commons.collections.buffer.UnboundedFifoBuffer)2 ReportMessage (org.talend.designer.runtime.visualization.ReportMessage)2 FileWriter (java.io.FileWriter)1 IOException (java.io.IOException)1 StyleRange (org.eclipse.swt.custom.StyleRange)1 StyledText (org.eclipse.swt.custom.StyledText)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 FormAttachment (org.eclipse.swt.layout.FormAttachment)1 FormData (org.eclipse.swt.layout.FormData)1 FormLayout (org.eclipse.swt.layout.FormLayout)1 Button (org.eclipse.swt.widgets.Button)1 FileDialog (org.eclipse.swt.widgets.FileDialog)1 Group (org.eclipse.swt.widgets.Group)1 FormToolkit (org.eclipse.ui.forms.widgets.FormToolkit)1 IMonitoredMXBeanGroup (org.talend.designer.runtime.visualization.MBean.IMonitoredMXBeanGroup)1