Search in sources :

Example 1 with MetaGUIElement

use of org.knime.workbench.ui.metainfo.model.MetaGUIElement in project knime-core by knime.

the class WorkflowSetMetaInfoEditor method createPartControl.

/**
 * {@inheritDoc}
 */
@Override
public void createPartControl(final Composite parent) {
    m_toolkit = new FormToolkit(parent.getDisplay());
    m_form = m_toolkit.createScrolledForm(parent);
    m_form.setText(getPartName());
    GridLayout layout = new GridLayout();
    layout.numColumns = 2;
    layout.makeColumnsEqualWidth = true;
    m_form.getBody().setLayout(layout);
    // content composite
    Composite content = m_toolkit.createComposite(m_form.getBody());
    layout = new GridLayout();
    layout.numColumns = 2;
    layout.horizontalSpacing = 20;
    layout.makeColumnsEqualWidth = false;
    content.setLayout(layout);
    // placeholder composite
    m_toolkit.createComposite(m_form.getBody());
    GridData layoutData = new GridData();
    layoutData.minimumWidth = 100;
    layoutData.widthHint = 100;
    layoutData.verticalAlignment = SWT.TOP;
    for (MetaGUIElement element : m_elements) {
        LOGGER.debug("element " + element.getLabel());
        Label label = m_toolkit.createLabel(content, element.getLabel() + ": ");
        label.setLayoutData(layoutData);
        element.createGUIElement(m_toolkit, content);
        element.addListener(new ModifyListener() {

            @Override
            public void modifyText(final ModifyEvent e) {
                setDirty(true);
            }
        });
    }
    m_form.reflow(true);
}
Also used : MetaGUIElement(org.knime.workbench.ui.metainfo.model.MetaGUIElement) GridLayout(org.eclipse.swt.layout.GridLayout) ModifyEvent(org.eclipse.swt.events.ModifyEvent) FormToolkit(org.eclipse.ui.forms.widgets.FormToolkit) Composite(org.eclipse.swt.widgets.Composite) ModifyListener(org.eclipse.swt.events.ModifyListener) GridData(org.eclipse.swt.layout.GridData) Label(org.eclipse.swt.widgets.Label)

Example 2 with MetaGUIElement

use of org.knime.workbench.ui.metainfo.model.MetaGUIElement in project knime-core by knime.

the class WorkflowSetMetaInfoEditor method doSave.

/**
 * {@inheritDoc}
 */
@Override
public void doSave(final IProgressMonitor monitor) {
    try {
        URI path = ((IURIEditorInput) getEditorInput()).getURI();
        File inputFile = new File(path);
        SAXTransformerFactory fac = (SAXTransformerFactory) TransformerFactory.newInstance();
        TransformerHandler handler = fac.newTransformerHandler();
        Transformer t = handler.getTransformer();
        t.setOutputProperty(OutputKeys.METHOD, "xml");
        t.setOutputProperty(OutputKeys.INDENT, "yes");
        OutputStream out = new FileOutputStream(inputFile);
        handler.setResult(new StreamResult(out));
        handler.startDocument();
        AttributesImpl atts = new AttributesImpl();
        atts.addAttribute(null, null, "nrOfElements", "CDATA", "" + m_elements.size());
        handler.startElement(null, null, "KNIMEMetaInfo", atts);
        monitor.beginTask("Saving meta information...", m_elements.size());
        for (MetaGUIElement element : m_elements) {
            element.saveTo(handler);
            monitor.worked(1);
        }
        handler.endElement(null, null, "KNIMEMetaInfo");
        handler.endDocument();
        out.close();
        setDirty(false);
    } catch (Exception e) {
        LOGGER.error("An error ocurred while saving " + getEditorInput().toString(), e);
    } finally {
        monitor.done();
    }
}
Also used : MetaGUIElement(org.knime.workbench.ui.metainfo.model.MetaGUIElement) IURIEditorInput(org.eclipse.ui.IURIEditorInput) TransformerHandler(javax.xml.transform.sax.TransformerHandler) Transformer(javax.xml.transform.Transformer) AttributesImpl(org.xml.sax.helpers.AttributesImpl) StreamResult(javax.xml.transform.stream.StreamResult) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) SAXTransformerFactory(javax.xml.transform.sax.SAXTransformerFactory) URI(java.net.URI) File(java.io.File) PartInitException(org.eclipse.ui.PartInitException)

Aggregations

MetaGUIElement (org.knime.workbench.ui.metainfo.model.MetaGUIElement)2 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 OutputStream (java.io.OutputStream)1 URI (java.net.URI)1 Transformer (javax.xml.transform.Transformer)1 SAXTransformerFactory (javax.xml.transform.sax.SAXTransformerFactory)1 TransformerHandler (javax.xml.transform.sax.TransformerHandler)1 StreamResult (javax.xml.transform.stream.StreamResult)1 ModifyEvent (org.eclipse.swt.events.ModifyEvent)1 ModifyListener (org.eclipse.swt.events.ModifyListener)1 GridData (org.eclipse.swt.layout.GridData)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 Composite (org.eclipse.swt.widgets.Composite)1 Label (org.eclipse.swt.widgets.Label)1 IURIEditorInput (org.eclipse.ui.IURIEditorInput)1 PartInitException (org.eclipse.ui.PartInitException)1 FormToolkit (org.eclipse.ui.forms.widgets.FormToolkit)1 AttributesImpl (org.xml.sax.helpers.AttributesImpl)1