use of eu.esdihumboldt.hale.common.align.extension.function.custom.CustomPropertyFunction in project hale by halestudio.
the class EditCustomFunctionContribution method fill.
@Override
public void fill(Menu menu, int index) {
AlignmentService alignmentService = PlatformUI.getWorkbench().getService(AlignmentService.class);
Collection<CustomPropertyFunction> functions = alignmentService.getAlignment().getCustomPropertyFunctions().values();
for (CustomPropertyFunction function : functions) {
if (function instanceof DefaultCustomPropertyFunction) {
// XXX currently only these functions editable
DefaultCustomPropertyFunction cf = (DefaultCustomPropertyFunction) function;
EditWizardAction action = new EditWizardAction(cf, alignmentService);
IContributionItem item = new ActionContributionItem(action);
item.fill(menu, index++);
}
}
// TODO add base alignment functions (disabled, with separator)?
}
use of eu.esdihumboldt.hale.common.align.extension.function.custom.CustomPropertyFunction in project hale by halestudio.
the class RemoveCustomFunctionContribution method fill.
@Override
public void fill(Menu menu, int index) {
AlignmentService alignmentService = PlatformUI.getWorkbench().getService(AlignmentService.class);
Collection<CustomPropertyFunction> functions = alignmentService.getAlignment().getCustomPropertyFunctions().values();
for (CustomPropertyFunction function : functions) {
if (function instanceof DefaultCustomPropertyFunction) {
// XXX currently only these functions editable
DefaultCustomPropertyFunction cf = (DefaultCustomPropertyFunction) function;
RemoveCustomFunctionAction action = new RemoveCustomFunctionAction(cf, alignmentService);
IContributionItem item = new ActionContributionItem(action);
item.fill(menu, index++);
}
}
// TODO add base alignment functions (disabled, with separator)?
}
use of eu.esdihumboldt.hale.common.align.extension.function.custom.CustomPropertyFunction in project hale by halestudio.
the class AlignmentServiceImpl method addOrUpdateAlignment.
/**
* @see AlignmentService#addOrUpdateAlignment(MutableAlignment)
*/
@Override
public void addOrUpdateAlignment(MutableAlignment alignment) {
Collection<Cell> added = new ArrayList<Cell>();
/*
* XXX Updates for disables not supported
*
* One problem is, that base alignments shouldn't be added twice, so if
* the given alignment contains a base alignment that is also contained
* in the current alignment it won't be added.
*
* Now what about cells in the given alignment, that reference those
* base alignments (-> disabled for)? They need to be changed to the
* base alignment cells of the current alignment.
*
* Those cells can be obtained by replacing the prefix part of the cell
* and using getCell(String).
*
* XXX Addition of base alignments not supported
*
* Here the problem is, that it is not enough to gather the base
* alignment cells and change their prefix to a new one, since the base
* cell could be another base alignment cell, which would need to
* change, too. They would have to be added in order. An option would be
* to load them with the base alignment loading mechanism, which would
* result in a loss of additional disables.
*
* XXX Changes of conflicting base alignment cells not handled
*/
// if (!alignment.getBaseAlignments().isEmpty()) {
// _log.warn("Adding alignments currently does not support merging of base alignments. Import base alignments independently.");
// }
boolean addedBaseCells = false;
// add cells
synchronized (this) {
for (Cell cell : alignment.getCells()) {
if (cell instanceof MutableCell) {
this.alignment.addCell((MutableCell) cell);
added.add(cell);
} else if (!(cell instanceof BaseAlignmentCell)) {
throw new IllegalStateException("The given alignment contained a cell which is neither mutable nor from a base alignment.");
} else {
addedBaseCells = true;
}
}
}
synchronized (this) {
// XXX this needs merging, see above
boolean first = true;
for (Entry<String, URI> baseAlignment : alignment.getBaseAlignments().entrySet()) {
Collection<CustomPropertyFunction> baseFunctions;
if (first) {
// XXX hack - insert all base functions with the first base
// alignment
baseFunctions = alignment.getBasePropertyFunctions().values();
} else {
// base functions should only be added once
baseFunctions = Collections.<CustomPropertyFunction>emptyList();
}
this.alignment.addBaseAlignment(baseAlignment.getKey(), baseAlignment.getValue(), //
alignment.getBaseAlignmentCells(baseAlignment.getValue()), baseFunctions);
}
}
// add custom functions
boolean addedFunctions = false;
synchronized (this) {
for (CustomPropertyFunction cf : alignment.getCustomPropertyFunctions().values()) {
this.alignment.addCustomPropertyFunction(cf);
addedFunctions = true;
}
}
if (addedBaseCells || (!added.isEmpty() && addedFunctions)) {
// only emit one combined event (not to trigger multiple
// transformations)
notifyAlignmentChanged();
} else {
if (!added.isEmpty()) {
notifyCellsAdded(added);
}
if (addedFunctions) {
notifyCustomFunctionsChanged();
}
}
}
use of eu.esdihumboldt.hale.common.align.extension.function.custom.CustomPropertyFunction in project hale by halestudio.
the class PreferencesGroovyService method getScriptHash.
/**
* Calculates the current alignments script hash.
*
* @return the current alignments script hash
*/
private synchronized String getScriptHash() {
if (scriptHash == null) {
List<String> scripts = new ArrayList<>();
// get all Groovy scripts
for (Cell cell : alignmentService.getAlignment().getCells()) {
ListMultimap<String, ParameterValue> parameters = cell.getTransformationParameters();
if (parameters == null)
continue;
// Groovy transformations
if (cell.getTransformationIdentifier().contains("groovy")) {
List<ParameterValue> val = parameters.get(GroovyConstants.PARAMETER_SCRIPT);
if (!val.isEmpty()) {
String script = getScriptString(val.get(0));
if (script != null) {
scripts.add(script);
}
}
}
// GroovyScript function parameters
for (ParameterValue value : parameters.values()) {
if (GroovyScript.GROOVY_SCRIPT_ID.equals(value.getType())) {
String script = getScriptString(value);
if (script != null) {
scripts.add(script);
}
}
}
}
// Groovy scripts of custom property functions
for (CustomPropertyFunction customFunction : alignmentService.getAlignment().getAllCustomPropertyFunctions().values()) {
if (customFunction instanceof DefaultCustomPropertyFunction) {
DefaultCustomPropertyFunction cf = (DefaultCustomPropertyFunction) customFunction;
if (CustomPropertyFunctionType.GROOVY.equals(cf.getFunctionType())) {
Value functionDef = cf.getFunctionDefinition();
if (functionDef != null && !functionDef.isEmpty()) {
String script = getScriptString(functionDef);
if (script != null) {
scripts.add(script);
}
}
}
}
}
// order scripts (for consistent hash)
Collections.sort(scripts);
// modify the script in a undetectable way
try {
MessageDigest md = MessageDigest.getInstance("MD5");
for (String script : scripts) md.update(script.getBytes("UTF-8"));
byte[] hash = md.digest();
StringBuilder sb = new StringBuilder(2 * hash.length);
for (byte b : hash) {
sb.append(String.format("%02x", b & 0xff));
}
scriptHash = sb.toString();
// Both exceptions cannot happen in a valid Java platform.
// Anyways, if they happen, execution should stop here!
} catch (NoSuchAlgorithmException e) {
throw new IllegalStateException("No MD5 MessageDigest!");
} catch (UnsupportedEncodingException e) {
throw new IllegalStateException("No UTF-8 Charset!");
}
}
return scriptHash;
}
use of eu.esdihumboldt.hale.common.align.extension.function.custom.CustomPropertyFunction in project hale by halestudio.
the class AbstractDefaultFunctionService method getPropertyFunctions.
@Override
public Collection<? extends PropertyFunctionDefinition> getPropertyFunctions() {
Collection<? extends PropertyFunctionDefinition> functions = super.getPropertyFunctions();
Alignment al = getCurrentAlignment();
if (al != null) {
List<PropertyFunctionDefinition> cfs = new ArrayList<>();
for (CustomPropertyFunction cf : al.getAllCustomPropertyFunctions().values()) {
cfs.add(new AlignmentFunctionDescriptor(cf.getDescriptor()));
}
cfs.addAll(functions);
functions = cfs;
}
return functions;
}
Aggregations