use of eu.esdihumboldt.hale.ui.service.project.ProjectVariablesContentProposalProvider 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));
}
}
Aggregations