Search in sources :

Example 6 with TransformationVariableReplacer

use of eu.esdihumboldt.hale.ui.transformation.TransformationVariableReplacer in project hale by halestudio.

the class RegexAnalysisParameterPage method createContent.

/**
 * @see eu.esdihumboldt.hale.ui.HaleWizardPage#createContent(org.eclipse.swt.widgets.Composite)
 */
@Override
protected void createContent(Composite page) {
    this.page = page;
    page.setLayout(GridLayoutFactory.swtDefaults().numColumns(1).create());
    if (getWizard().getUnfinishedCell().getTarget() != null) {
        PropertyDefinition propDef = (PropertyDefinition) getWizard().getUnfinishedCell().getTarget().values().iterator().next().getDefinition().getDefinition();
        if (!propDef.equals(target)) {
            String regexTooltip = "A regular expression containing groups (see http://www.javamex.com/tutorials/regular_expressions/capturing_groups.shtml). Press Ctrl+Space for project variable content assistance.";
            Group regexGroup = new Group(page, SWT.NONE);
            regexGroup.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
            regexGroup.setLayout(new GridLayout(1, false));
            regexGroup.setText("Regular Expression");
            regexGroup.setToolTipText(regexTooltip);
            _regexText = new Text(regexGroup, SWT.SINGLE | SWT.LEAD | SWT.BORDER);
            _regexText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
            _regexText.setText("");
            _regexText.addModifyListener(this);
            final ControlDecoration regexInfoDeco = new ControlDecoration(_regexText, SWT.TOP | SWT.LEFT);
            regexInfoDeco.setDescriptionText(regexTooltip);
            regexInfoDeco.setImage(FieldDecorationRegistry.getDefault().getFieldDecoration(FieldDecorationRegistry.DEC_INFORMATION).getImage());
            regexInfoDeco.setMarginWidth(2);
            ContentProposalAdapter regexTextAdapter = new ContentProposalAdapter(_regexText, new TextContentAdapter(), new ProjectVariablesContentProposalProvider(true), ProjectVariablesContentProposalProvider.CTRL_SPACE, new char[] { '{' });
            regexTextAdapter.setAutoActivationDelay(0);
            String formatTooltip = "The output format to apply, containing curly brackets delimited group definitions. Ex. {1} represents the result of group 1 from the regex analysis. Press Ctrl+Space for project variable content assistance.";
            Group outformatGroup = new Group(page, SWT.NONE);
            outformatGroup.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
            outformatGroup.setLayout(new GridLayout(1, false));
            outformatGroup.setText("Output format");
            outformatGroup.setToolTipText(formatTooltip);
            _outformatText = new Text(outformatGroup, SWT.SINGLE | SWT.LEAD | SWT.BORDER);
            _outformatText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
            _outformatText.setText("");
            _outformatText.addModifyListener(this);
            final ControlDecoration formatInfoDeco = new ControlDecoration(_outformatText, SWT.TOP | SWT.LEFT);
            formatInfoDeco.setDescriptionText(formatTooltip);
            formatInfoDeco.setImage(FieldDecorationRegistry.getDefault().getFieldDecoration(FieldDecorationRegistry.DEC_INFORMATION).getImage());
            formatInfoDeco.setMarginWidth(2);
            ContentProposalAdapter outformatAdapter = new ContentProposalAdapter(_outformatText, new TextContentAdapter(), new ProjectVariablesContentProposalProvider(true), ProjectVariablesContentProposalProvider.CTRL_SPACE, new char[] { '{' });
            outformatAdapter.setAutoActivationDelay(0);
            Group exampleGroup = new Group(page, SWT.NONE);
            exampleGroup.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
            exampleGroup.setLayout(new GridLayout(3, false));
            exampleGroup.setText("Example");
            Label inputLabel = new Label(exampleGroup, SWT.NONE);
            inputLabel.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
            inputLabel.setText("Sample text");
            _inputText = new Text(exampleGroup, SWT.SINGLE | SWT.LEAD | SWT.BORDER);
            _inputText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
            _inputText.setText("");
            Button testButton = new Button(exampleGroup, SWT.PUSH);
            GridData testButtonGD = new GridData(SWT.FILL, SWT.FILL, false, false);
            testButtonGD.verticalSpan = 2;
            testButton.setLayoutData(testButtonGD);
            testButton.setText("Test");
            Label outputLabel = new Label(exampleGroup, SWT.NONE);
            outputLabel.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
            outputLabel.setText("Sample result");
            final Text outputText = new Text(exampleGroup, SWT.SINGLE | SWT.LEAD | SWT.BORDER);
            outputText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
            outputText.setText("");
            testButton.addSelectionListener(new SelectionAdapter() {

                @Override
                public void widgetSelected(SelectionEvent e) {
                    String convertedString = "No match found.";
                    try {
                        String regex = new TransformationVariableReplacer().replaceVariables(_regexText.getText());
                        String outformat = new TransformationVariableReplacer().replaceVariables(_outformatText.getText());
                        convertedString = RegexAnalysis.analize(regex, outformat, _inputText.getText());
                        outputText.setText(convertedString);
                    } catch (Exception e1) {
                        outputText.setText(e1.getCause().getLocalizedMessage());
                    }
                }
            });
        }
    }
    if (_regexText != null && initialRegexValue != null) {
        _regexText.setText(initialRegexValue.as(String.class));
    }
    if (_outformatText != null && initialOutformatValue != null) {
        _outformatText.setText(initialOutformatValue.as(String.class));
    }
}
Also used : Group(org.eclipse.swt.widgets.Group) ProjectVariablesContentProposalProvider(eu.esdihumboldt.hale.ui.service.project.ProjectVariablesContentProposalProvider) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) Text(org.eclipse.swt.widgets.Text) TextContentAdapter(org.eclipse.jface.fieldassist.TextContentAdapter) PropertyDefinition(eu.esdihumboldt.hale.common.schema.model.PropertyDefinition) ContentProposalAdapter(org.eclipse.jface.fieldassist.ContentProposalAdapter) TransformationVariableReplacer(eu.esdihumboldt.hale.ui.transformation.TransformationVariableReplacer) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) ControlDecoration(org.eclipse.jface.fieldassist.ControlDecoration) SelectionEvent(org.eclipse.swt.events.SelectionEvent)

Aggregations

TransformationVariableReplacer (eu.esdihumboldt.hale.ui.transformation.TransformationVariableReplacer)6 GridData (org.eclipse.swt.layout.GridData)3 PropertyDefinition (eu.esdihumboldt.hale.common.schema.model.PropertyDefinition)2 AttributeInputDialog (eu.esdihumboldt.hale.ui.common.definition.AttributeInputDialog)2 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)2 SelectionEvent (org.eclipse.swt.events.SelectionEvent)2 Button (org.eclipse.swt.widgets.Button)2 Label (org.eclipse.swt.widgets.Label)2 Text (org.eclipse.swt.widgets.Text)2 Expression (com.iabcinc.jmep.Expression)1 EntityDefinition (eu.esdihumboldt.hale.common.align.model.EntityDefinition)1 AttributeEditor (eu.esdihumboldt.hale.ui.common.AttributeEditor)1 EditorFactory (eu.esdihumboldt.hale.ui.common.EditorFactory)1 AttributeEditorFactory (eu.esdihumboldt.hale.ui.common.definition.AttributeEditorFactory)1 DefinitionLabelFactory (eu.esdihumboldt.hale.ui.common.definition.DefinitionLabelFactory)1 EditorChooserEditor (eu.esdihumboldt.hale.ui.common.definition.editors.EditorChooserEditor)1 ProjectVariablesContentProposalProvider (eu.esdihumboldt.hale.ui.service.project.ProjectVariablesContentProposalProvider)1 ContentProposalAdapter (org.eclipse.jface.fieldassist.ContentProposalAdapter)1 ControlDecoration (org.eclipse.jface.fieldassist.ControlDecoration)1 TextContentAdapter (org.eclipse.jface.fieldassist.TextContentAdapter)1