use of eu.esdihumboldt.hale.common.schema.model.PropertyDefinition in project hale by halestudio.
the class CQLFilterDialogFactory method openDialog.
@Override
public Filter openDialog(Shell shell, EntityDefinition entityDef, String title, String message) {
TypeEntityDefinition parentType;
if (entityDef.getPropertyPath().isEmpty())
parentType = AlignmentUtil.getTypeEntity(entityDef);
else {
Definition<?> def = entityDef.getDefinition();
TypeDefinition propertyType = ((PropertyDefinition) def).getPropertyType();
// create a dummy type for the filter
TypeDefinition dummyType = new DefaultTypeDefinition(new QName("ValueFilterDummy"));
// create dummy type entity
Condition condition = AlignmentUtil.getContextCondition(entityDef);
Filter filter = condition == null ? null : condition.getFilter();
parentType = new TypeEntityDefinition(dummyType, entityDef.getSchemaSpace(), filter);
// with the property type being contained as value
// property
new DefaultPropertyDefinition(new QName("value"), dummyType, propertyType);
// and the parent type as parent property
new DefaultPropertyDefinition(new QName("parent"), dummyType, ((PropertyDefinition) def).getParentType());
}
CQLFilterDialog dialog = new CQLFilterDialog(shell, parentType, title, message);
if (dialog.open() == CQLFilterDialog.OK) {
return dialog.getFilter();
}
return null;
}
use of eu.esdihumboldt.hale.common.schema.model.PropertyDefinition in project hale by halestudio.
the class AssignParameterPage 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(2).create());
// is created)
if (getWizard().getUnfinishedCell().getTarget() != null) {
EntityDefinition entityDef = getWizard().getUnfinishedCell().getTarget().values().iterator().next().getDefinition();
PropertyDefinition propDef = (PropertyDefinition) entityDef.getDefinition();
title = new Composite(page, SWT.NONE);
title.setLayout(GridLayoutFactory.swtDefaults().numColumns(2).margins(0, 0).create());
// title.setLayoutData(GridDataFactory.swtDefaults().align(SWT.END, SWT.END).create());
DefinitionLabelFactory dlf = PlatformUI.getWorkbench().getService(DefinitionLabelFactory.class);
dlf.createLabel(title, propDef, false);
Label label = new Label(title, SWT.NONE);
label.setText(" = ");
editor = PlatformUI.getWorkbench().getService(AttributeEditorFactory.class).createEditor(page, propDef, entityDef, false);
editor.setVariableReplacer(new TransformationVariableReplacer());
editor.getControl().setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false));
editor.setPropertyChangeListener(new IPropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent event) {
if (event.getProperty().equals(AttributeEditor.IS_VALID))
setPageComplete((Boolean) event.getNewValue());
}
});
}
if (editor != null && initialValue != null) {
editor.setAsText(initialValue.as(String.class));
if (editor instanceof EditorChooserEditor)
((EditorChooserEditor<?>) editor).selectEditor(initialValue.getType());
}
if (editor != null)
setPageComplete(editor.isValid());
}
use of eu.esdihumboldt.hale.common.schema.model.PropertyDefinition 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));
}
}
use of eu.esdihumboldt.hale.common.schema.model.PropertyDefinition in project hale by halestudio.
the class XmlSchemaReaderTest method testRead_definitive_groups.
/**
* Test reading a simple XML schema containing groups and group references.
*
* @throws Exception if reading the schema fails
*/
@Test
public void testRead_definitive_groups() throws Exception {
URI location = getClass().getResource("/testdata/definitive/groups.xsd").toURI();
LocatableInputSupplier<? extends InputStream> input = new DefaultInputSupplier(location);
XmlIndex schema = (XmlIndex) readSchema(input);
// ShirtType
TypeDefinition shirtType = schema.getType(new QName("ShirtType"));
assertNotNull(shirtType);
assertEquals(5, shirtType.getChildren().size());
Iterator<? extends ChildDefinition<?>> it = shirtType.getChildren().iterator();
// ProductPropertyGroup
GroupPropertyDefinition prodGroup = it.next().asGroup();
// cardinality
Cardinality cc = prodGroup.getConstraint(Cardinality.class);
assertEquals(0, cc.getMinOccurs());
assertEquals(1, cc.getMaxOccurs());
// name
assertEquals("ProductPropertyGroup", prodGroup.getName().getLocalPart());
assertEquals(4, prodGroup.getDeclaredChildren().size());
Iterator<? extends ChildDefinition<?>> itProd = prodGroup.getDeclaredChildren().iterator();
// not there any more because it is flattened away
// // DescriptionGroup
// GroupPropertyDefinition descGroup = itProd.next().asGroup();
// assertNotNull(descGroup);
// // cardinality
// cc = descGroup.getConstraint(Cardinality.class);
// assertEquals(1, cc.getMinOccurs());
// assertEquals(1, cc.getMaxOccurs());
//
// assertEquals(2, descGroup.getDeclaredChildren().size());
// Iterator<? extends ChildDefinition<?>> itDesc = descGroup.getDeclaredChildren().iterator();
// description
PropertyDefinition description = itProd.next().asProperty();
assertNotNull(description);
assertEquals("description", description.getName().getLocalPart());
// comment
PropertyDefinition comment = itProd.next().asProperty();
assertNotNull(comment);
assertEquals("comment", comment.getName().getLocalPart());
// number
PropertyDefinition number = itProd.next().asProperty();
assertNotNull(number);
assertEquals("number", number.getName().getLocalPart());
// name
PropertyDefinition name = itProd.next().asProperty();
assertNotNull(name);
assertEquals("name", name.getName().getLocalPart());
// size
PropertyDefinition size = it.next().asProperty();
assertNotNull(size);
assertEquals("size", size.getName().getLocalPart());
}
use of eu.esdihumboldt.hale.common.schema.model.PropertyDefinition in project hale by halestudio.
the class XmlSchemaReaderTest method testRead_definitive_sequencegroup.
/**
* Test reading a simple XML schema with sequences that have to be grouped.
*
* @throws Exception if reading the schema fails
*/
@Test
public void testRead_definitive_sequencegroup() throws Exception {
URI location = getClass().getResource("/testdata/definitive/sequencegroup.xsd").toURI();
LocatableInputSupplier<? extends InputStream> input = new DefaultInputSupplier(location);
XmlIndex schema = (XmlIndex) readSchema(input);
// ItemsType
TypeDefinition itemsType = schema.getType(new QName("ItemsType"));
assertNotNull(itemsType);
assertEquals(1, itemsType.getChildren().size());
// sequence group
GroupPropertyDefinition sequence = itemsType.getChildren().iterator().next().asGroup();
assertNotNull(sequence);
// cardinality
Cardinality cc = sequence.getConstraint(Cardinality.class);
assertEquals(1, cc.getMinOccurs());
assertEquals(Cardinality.UNBOUNDED, cc.getMaxOccurs());
// choice flag (not a choice)
assertFalse(sequence.getConstraint(ChoiceFlag.class).isEnabled());
Iterator<? extends ChildDefinition<?>> it = sequence.getDeclaredChildren().iterator();
// name
PropertyDefinition name = it.next().asProperty();
assertNotNull(name);
assertEquals("name", name.getName().getLocalPart());
// id
PropertyDefinition id = it.next().asProperty();
assertNotNull(id);
assertEquals("id", id.getName().getLocalPart());
// choice
GroupPropertyDefinition choice = it.next().asGroup();
assertNotNull(choice);
// cardinality
cc = choice.getConstraint(Cardinality.class);
assertEquals(1, cc.getMinOccurs());
assertEquals(1, cc.getMaxOccurs());
// choice flag
assertTrue(choice.getConstraint(ChoiceFlag.class).isEnabled());
it = choice.getDeclaredChildren().iterator();
// choice sequence
GroupPropertyDefinition seqGroup = it.next().asGroup();
assertNotNull(seqGroup);
// choice flag (not a choice)
assertFalse(seqGroup.getConstraint(ChoiceFlag.class).isEnabled());
// sequence elements
// one
PropertyDefinition one = seqGroup.getChild(new QName("one")).asProperty();
assertNotNull(one);
// two
PropertyDefinition two = seqGroup.getChild(new QName("two")).asProperty();
assertNotNull(two);
// choice element
PropertyDefinition single = it.next().asProperty();
assertNotNull(single);
assertEquals("single", single.getName().getLocalPart());
}
Aggregations