use of eu.esdihumboldt.hale.common.align.model.Entity in project hale by halestudio.
the class CellInfo method getName.
private String getName(CellType cellType, boolean fullName) {
Iterator<? extends Entity> iterator;
ListMultimap<String, ? extends Entity> entities;
PropertyDefinition child = null;
switch(cellType) {
case SOURCE:
if ((entities = getCell().getSource()) == null)
return null;
iterator = entities.values().iterator();
break;
case TARGET:
if ((entities = getCell().getTarget()) == null)
return null;
iterator = entities.values().iterator();
break;
default:
return null;
}
StringBuffer sb = new StringBuffer();
while (iterator.hasNext()) {
Entity entity = iterator.next();
if (fullName) {
for (ChildContext childContext : entity.getDefinition().getPropertyPath()) {
child = childContext.getChild().asProperty();
if (child != null) {
sb.append(child.getDisplayName());
sb.append(".");
}
}
sb.append(entity.getDefinition().getDefinition().getDisplayName());
sb.append(",\n");
} else {
sb.append(entity.getDefinition().getDefinition().getDisplayName());
sb.append(", ");
}
}
String result = sb.toString();
if (fullName)
return result.substring(0, result.lastIndexOf(",\n"));
else
return result.substring(0, result.lastIndexOf(","));
}
use of eu.esdihumboldt.hale.common.align.model.Entity in project hale by halestudio.
the class GeographicalNamePage method createSpellingGroup.
private void createSpellingGroup(Composite parent, PropertyFunctionDefinition function) {
// define Spelling Group composite
Group configurationGroup = new Group(parent, SWT.NONE);
configurationGroup.setText(SPELLING_GROUP_TEXT);
configurationGroup.setLayout(GridLayoutFactory.fillDefaults().create());
GridData configurationAreaGD = new GridData(GridData.VERTICAL_ALIGN_FILL | GridData.HORIZONTAL_ALIGN_FILL);
configurationAreaGD.grabExcessHorizontalSpace = true;
configurationAreaGD.grabExcessVerticalSpace = true;
configurationGroup.setLayoutData(configurationAreaGD);
configurationGroup.setSize(configurationGroup.computeSize(SWT.DEFAULT, SWT.DEFAULT));
configurationGroup.setFont(parent.getFont());
final Composite configurationComposite = new Composite(configurationGroup, SWT.NONE);
GridData configurationLayoutData = new GridData(GridData.GRAB_HORIZONTAL | GridData.FILL_HORIZONTAL);
configurationLayoutData.grabExcessHorizontalSpace = true;
configurationComposite.setLayoutData(configurationLayoutData);
GridLayout spellingLayout = new GridLayout();
spellingLayout.numColumns = 2;
spellingLayout.makeColumnsEqualWidth = false;
spellingLayout.marginWidth = 0;
spellingLayout.marginHeight = 0;
spellingLayout.horizontalSpacing = 8;
configurationComposite.setLayout(spellingLayout);
// or get the known information about the cell to be edited
if (getSpellings() == null || getSpellings().size() == 0) {
spellings = new ArrayList<SpellingType>();
ListMultimap<String, ? extends Entity> source = getWizard().getUnfinishedCell().getSource();
if (source != null) {
for (Entity item : source.values()) {
int i = 0;
Definition<?> entity = item.getDefinition().getDefinition();
if (entity instanceof PropertyDefinition) {
SpellingType sp = new SpellingType((PropertyDefinition) entity);
// set the same script value if you had a value before
if (scripts != null && i < scripts.size()) {
sp.setScript(scripts.get(i));
} else {
// else set the default value
sp.setScript(ISO_CODE_ENG);
}
// before
if (trans != null && i < trans.size()) {
sp.setTransliteration(trans.get(i));
} else {
// else set the default value
sp.setTransliteration("");
}
spellings.add(sp);
}
i++;
}
}
} else {
// after initialization of the spellings
ArrayList<PropertyDefinition> temp = new ArrayList<PropertyDefinition>();
ArrayList<SpellingType> templist = getSpellings();
// we have to create a new spellings list because a live
// modification of the combo box input would occur an error
spellings = new ArrayList<SpellingType>();
for (int i = 0; i < templist.size(); i++) {
temp.add(templist.get(i).getProperty());
if (scripts != null && trans != null && i < scripts.size() && scripts.get(i) != null && i < trans.size() && trans.get(i) != null) {
templist.get(i).setScript(scripts.get(i));
templist.get(i).setTransliteration(trans.get(i));
}
}
for (Entity item : getWizard().getUnfinishedCell().getSource().values()) {
Definition<?> entity = item.getDefinition().getDefinition();
if (entity instanceof PropertyDefinition) {
PropertyDefinition propDef = (PropertyDefinition) entity;
for (SpellingType st : templist) {
// transliteration) to the new spellings list
if (propDef.equals(st.getProperty())) {
spellings.add(st);
}
}
// with default values
if (!temp.contains(propDef)) {
SpellingType sp = new SpellingType(propDef);
sp.setScript(ISO_CODE_ENG);
sp.setTransliteration("");
spellings.add(sp);
}
}
}
}
// Text
final Label nameSpellingTextLabel = new Label(configurationComposite, SWT.NONE);
nameSpellingTextLabel.setText(SPELLING_TEXT_LABEL_TEXT);
this.nameSpellingText = new ComboViewer(configurationComposite, SWT.DROP_DOWN | SWT.READ_ONLY);
this.nameSpellingText.getControl().setLayoutData(configurationLayoutData);
this.nameSpellingText.setContentProvider(ArrayContentProvider.getInstance());
this.nameSpellingText.setLabelProvider(new LabelProvider() {
@Override
public String getText(Object element) {
if (element instanceof SpellingType) {
return ((SpellingType) element).getProperty().getName().getLocalPart();
}
return super.getText(element);
}
});
this.nameSpellingText.setInput(spellings);
// default set selection to the first element on the list
if (!spellings.isEmpty()) {
this.activeSpelling = spellings.iterator().next();
this.nameSpellingText.setSelection(new StructuredSelection(activeSpelling));
}
// set active spelling
nameSpellingText.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
if (!event.getSelection().isEmpty() && event.getSelection() instanceof IStructuredSelection) {
SpellingType selected = (SpellingType) ((IStructuredSelection) event.getSelection()).getFirstElement();
String script = ISO_CODE_ENG;
// $NON-NLS-1$
String transliteration = "";
activeSpelling = selected;
if (activeSpelling.getScript() != null && // $NON-NLS-1$
!activeSpelling.getScript().equals(""))
script = activeSpelling.getScript();
if (activeSpelling.getTransliteration() != null && // $NON-NLS-1$
!activeSpelling.getTransliteration().equals(""))
transliteration = activeSpelling.getTransliteration();
nameSpellingScript.setText(script);
nameSpellingTransliteration.setText(transliteration);
}
}
});
// Script
final Label nameSpellingScriptLabel = new Label(configurationComposite, SWT.NONE);
nameSpellingScriptLabel.setText(SCRIPT_LABEL_TEXT);
configureParameterLabel(nameSpellingScriptLabel, PROPERTY_SCRIPT, function);
this.nameSpellingScript = new Text(configurationComposite, SWT.BORDER | SWT.SINGLE);
this.nameSpellingScript.setLayoutData(configurationLayoutData);
this.nameSpellingScript.setEnabled(true);
this.nameSpellingScript.setTabs(0);
// $NON-NLS-1$
String script = "eng";
// read script from the active spelling
if (activeSpelling != null && activeSpelling.getScript() != null)
script = activeSpelling.getScript();
// set default value for script
this.nameSpellingScript.setText(script);
this.nameSpellingScript.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
activeSpelling.setScript(nameSpellingScript.getText());
}
});
// Transliteration
final Label nameSpellingTransliterationLabel = new Label(configurationComposite, SWT.NONE);
nameSpellingTransliterationLabel.setText(TRANSLITERATION_LABEL_TEXT);
configureParameterLabel(nameSpellingTransliterationLabel, PROPERTY_TRANSLITERATION, function);
this.nameSpellingTransliteration = new Text(configurationComposite, SWT.BORDER | SWT.SINGLE);
this.nameSpellingTransliteration.setLayoutData(configurationLayoutData);
this.nameSpellingTransliteration.setEnabled(true);
this.nameSpellingTransliteration.setTabs(0);
// read script from the active spelling
// $NON-NLS-1$
String transliteration = "";
if (activeSpelling != null && activeSpelling.getTransliteration() != null)
transliteration = activeSpelling.getTransliteration();
// set default value for transliteration
this.nameSpellingTransliteration.setText(transliteration);
this.nameSpellingTransliteration.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
activeSpelling.setTransliteration(nameSpellingTransliteration.getText());
}
});
}
use of eu.esdihumboldt.hale.common.align.model.Entity in project hale by halestudio.
the class SequentialIDParameterPage method validateValue.
/**
* Validates if the given value is valid for the target property.
*
* @param value the value to validate
* @return if the value is valid
*/
protected boolean validateValue(String value) {
Cell cell = getWizard().getUnfinishedCell();
List<? extends Entity> targets = cell.getTarget().get(null);
if (!targets.isEmpty()) {
Entity entity = targets.get(0);
Definition<?> def = entity.getDefinition().getDefinition();
if (def instanceof PropertyDefinition) {
TypeDefinition propertyType = ((PropertyDefinition) def).getPropertyType();
Validator validator = propertyType.getConstraint(ValidationConstraint.class).getValidator();
// TODO conversion to binding needed?
String error = validator.validate(value);
// update the example decoration
if (error == null) {
exampleDecoration.hide();
} else {
exampleDecoration.setDescriptionText(error);
exampleDecoration.show();
}
return error == null;
}
}
// no validation possible
return true;
}
use of eu.esdihumboldt.hale.common.align.model.Entity in project hale by halestudio.
the class AlignmentViewContentProvider method getElements.
/**
* @see eu.esdihumboldt.hale.ui.common.graph.content.CellGraphContentProvider#getElements(java.lang.Object)
*/
@Override
public Object[] getElements(Object input) {
// check if the input is a (incomplete) type cell
if (input instanceof Cell) {
Cell cell = (Cell) input;
Entity source = CellUtil.getFirstEntity(cell.getSource());
Entity target = CellUtil.getFirstEntity(cell.getTarget());
if ((source == null || source instanceof Type) && (target == null || target instanceof Type))
return getEdges((Cell) input);
}
return super.getElements(input);
}
use of eu.esdihumboldt.hale.common.align.model.Entity in project hale by halestudio.
the class GenericParameterPage method onShowPage.
/**
* @see HaleWizardPage#onShowPage(boolean)
*/
@Override
protected void onShowPage(boolean firstShow) {
Cell cell = getWizard().getUnfinishedCell();
// update variables as they could have changed
if (!AlignmentUtil.isTypeCell(cell)) {
Set<PropertyEntityDefinition> variables = new HashSet<PropertyEntityDefinition>();
for (Entity e : cell.getSource().values()) {
// Cell is no type cell, so entities are Properties.
variables.add(((Property) e).getDefinition());
}
for (Pair<AttributeEditor<?>, Button> pair : inputFields.values()) pair.getFirst().setVariables(variables);
}
updateState();
}
Aggregations