Search in sources :

Example 1 with JavaSnippetTemplate

use of org.knime.base.node.jsnippet.template.JavaSnippetTemplate in project knime-core by knime.

the class JavaSnippetNodeDialog method createTemplateInfoPanel.

/**
 * The panel at the to with the "Create Template..." Button.
 */
private JPanel createTemplateInfoPanel(final boolean isPreview) {
    final JButton addTemplateButton = new JButton("Create Template...");
    addTemplateButton.addActionListener(e -> {
        final Frame parent = (Frame) SwingUtilities.getAncestorOfClass(Frame.class, addTemplateButton);
        final JavaSnippetTemplate newTemplate = AddTemplateDialog.openUserDialog(parent, m_snippet, m_templateMetaCategory, JavaSnippetTemplateProvider.getDefault());
        if (null != newTemplate) {
            JavaSnippetTemplateProvider.getDefault().addTemplate(newTemplate);
            // update the template UUID of the current snippet
            m_settings.setTemplateUUID(newTemplate.getUUID());
            final String loc = JavaSnippetTemplateProvider.getDefault().getDisplayLocation(newTemplate);
            m_templateLocation.setText(loc);
            JavaSnippetNodeDialog.this.getPanel().validate();
        }
    });
    final JPanel templateInfoPanel = new JPanel(new BorderLayout());
    m_templateLocation = new JLabel(getTemplateLocation());
    if (isPreview) {
        templateInfoPanel.add(m_templateLocation, BorderLayout.CENTER);
    } else {
        templateInfoPanel.add(addTemplateButton, BorderLayout.LINE_END);
    }
    templateInfoPanel.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
    return templateInfoPanel;
}
Also used : JPanel(javax.swing.JPanel) Frame(java.awt.Frame) BorderLayout(java.awt.BorderLayout) JButton(javax.swing.JButton) JavaSnippetTemplate(org.knime.base.node.jsnippet.template.JavaSnippetTemplate) JLabel(javax.swing.JLabel)

Example 2 with JavaSnippetTemplate

use of org.knime.base.node.jsnippet.template.JavaSnippetTemplate in project knime-core by knime.

the class JavaSnippetNodeDialog method getTemplateLocation.

/* Get the location of the template set in the settings. (empty string if none set) */
private String getTemplateLocation() {
    final TemplateProvider<JavaSnippetTemplate> provider = JavaSnippetTemplateProvider.getDefault();
    final String uuid = m_settings.getTemplateUUID();
    final JavaSnippetTemplate template = null != uuid ? provider.getTemplate(UUID.fromString(uuid)) : null;
    final String loc = null != template ? createTemplateLocationText(template) : "";
    return loc;
}
Also used : JavaSnippetTemplate(org.knime.base.node.jsnippet.template.JavaSnippetTemplate)

Aggregations

JavaSnippetTemplate (org.knime.base.node.jsnippet.template.JavaSnippetTemplate)2 BorderLayout (java.awt.BorderLayout)1 Frame (java.awt.Frame)1 JButton (javax.swing.JButton)1 JLabel (javax.swing.JLabel)1 JPanel (javax.swing.JPanel)1