use of eu.esdihumboldt.hale.common.core.io.Value in project hale by halestudio.
the class InstanceViewPreferencePage method createContents.
@Override
protected Control createContents(Composite parent) {
ProjectService ps = PlatformUI.getWorkbench().getService(ProjectService.class);
Composite page = new Composite(parent, SWT.NONE);
GridLayoutFactory.swtDefaults().numColumns(1).applyTo(page);
GridDataFactory.fillDefaults().grab(true, true).applyTo(page);
// current sampler settings
samplerSettings.clear();
for (Entry<String, Sampler> entry : InstanceViewPreferences.SAMPLERS.entrySet()) {
Value settings = ps.getConfigurationService().getProperty(InstanceViewPreferences.KEY_SETTINGS_PREFIX + entry.getKey());
if (settings.isEmpty()) {
settings = entry.getValue().getDefaultSettings();
}
samplerSettings.put(entry.getKey(), settings);
}
// sampler group
samplerGroup = new Group(page, SWT.NONE);
samplerGroup.setText("Instance sampling");
GridDataFactory.fillDefaults().grab(true, false).applyTo(samplerGroup);
GridLayoutFactory.swtDefaults().applyTo(samplerGroup);
// enabled button
enabled = new Button(samplerGroup, SWT.CHECK);
enabled.setText("Use a sub-set of the imported source data as specified below:");
enabled.setSelection(ps.getConfigurationService().getBoolean(InstanceViewPreferences.KEY_ENABLED, InstanceViewPreferences.ENABLED_DEFAULT));
enabled.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
changed = true;
}
});
// sampler selector
samplers = new ComboViewer(samplerGroup);
samplers.setContentProvider(ArrayContentProvider.getInstance());
samplers.setLabelProvider(new LabelProvider() {
@Override
public String getText(Object element) {
if (element instanceof Sampler) {
return ((Sampler) element).getDisplayName(Value.NULL);
}
return super.getText(element);
}
});
GridDataFactory.swtDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false);
samplers.setInput(InstanceViewPreferences.SAMPLERS.values());
samplers.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
ISelection selection = event.getSelection();
if (selection.isEmpty()) {
updateEditor(null);
} else {
if (selection instanceof IStructuredSelection) {
updateEditor((Sampler) ((IStructuredSelection) selection).getFirstElement());
}
}
changed = true;
}
});
// restore the selected sampler
String samplerId = ps.getConfigurationService().get(InstanceViewPreferences.KEY_SAMPLER, InstanceViewPreferences.SAMPLER_FIRST);
Sampler selectedSampler = InstanceViewPreferences.SAMPLERS.get(samplerId);
if (selectedSampler != null) {
samplers.setSelection(new StructuredSelection(selectedSampler));
changed = false;
}
// occurring values group
Group ovGroup = new Group(page, SWT.NONE);
ovGroup.setText("Occurring values");
GridDataFactory.fillDefaults().grab(true, false).applyTo(ovGroup);
GridLayoutFactory.swtDefaults().applyTo(ovGroup);
// occurring values button
occurringValuesComplete = new Button(ovGroup, SWT.CHECK);
occurringValuesComplete.setText("Always use complete source data to determine occurring values (ignore sampling)");
occurringValuesComplete.setSelection(ps.getConfigurationService().getBoolean(InstanceViewPreferences.KEY_OCCURRING_VALUES_USE_EXTERNAL, InstanceViewPreferences.OCCURRING_VALUES_EXTERNAL_DEFAULT));
occurringValuesComplete.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
ov_changed = true;
}
});
return page;
}
use of eu.esdihumboldt.hale.common.core.io.Value in project hale by halestudio.
the class InstanceViewPreferencePage method updateEditor.
/**
* Update the sampler editor.
*
* @param newSampler the new selected sampler
*/
protected void updateEditor(Sampler newSampler) {
if (currentEditor != null) {
// store value for current sampler
Value setting = currentEditor.getValue();
samplerSettings.put(InstanceViewPreferences.SAMPLERS.inverse().get(currentSampler), setting);
// dispose current editor
currentEditor.setPropertyChangeListener(null);
currentEditor.getControl().dispose();
}
if (newSampler != null) {
// create the editor
currentEditor = newSampler.createEditor(samplerGroup);
if (currentEditor != null) {
// set the editor value
currentEditor.setValue(samplerSettings.get(InstanceViewPreferences.SAMPLERS.inverse().get(newSampler)));
currentEditor.setPropertyChangeListener(editorListener);
}
} else {
currentEditor = null;
}
currentSampler = newSampler;
// updated and re-layout controls
samplerGroup.layout(true);
}
use of eu.esdihumboldt.hale.common.core.io.Value in project hale by halestudio.
the class ProjectVariablesContentProposalProvider method reload.
/**
* Refresh the project variables from the {@link ProjectService}
*/
public void reload() {
ProjectService ps = PlatformUI.getWorkbench().getService(ProjectService.class);
Value value = ps.getConfigurationService().getProperty(ProjectVariables.PROJECT_PROPERTY_VARIABLES);
ValueProperties properties = value.as(ValueProperties.class);
variables.clear();
if (properties != null) {
variables.putAll(properties);
}
}
use of eu.esdihumboldt.hale.common.core.io.Value in project hale by halestudio.
the class IOWizard method performFinish.
/**
* @see Wizard#performFinish()
*
* @return <code>true</code> if executing the I/O provider was successful
*/
@Override
public boolean performFinish() {
if (getProvider() == null) {
return false;
}
if (!applyConfiguration()) {
return false;
}
// create default report
IOReporter defReport = provider.createReporter();
// validate and execute provider
try {
// validate configuration
provider.validate();
ProjectService ps = PlatformUI.getWorkbench().getService(ProjectService.class);
URI projectLoc = ps.getLoadLocation() == null ? null : ps.getLoadLocation();
boolean isProjectResource = false;
if (actionId != null) {
// XXX instead move project resource to action?
ActionUI factory = ActionUIExtension.getInstance().findActionUI(actionId);
isProjectResource = factory.isProjectResource();
}
// prevent loading of duplicate resources
if (isProjectResource && provider instanceof ImportProvider && !getProviderFactory().allowDuplicateResource()) {
String currentResource = ((ImportProvider) provider).getSource().getLocation().toString();
URI currentAbsolute = URI.create(currentResource);
if (projectLoc != null && !currentAbsolute.isAbsolute()) {
currentAbsolute = projectLoc.resolve(currentAbsolute);
}
for (IOConfiguration conf : ((Project) ps.getProjectInfo()).getResources()) {
Value otherResourceValue = conf.getProviderConfiguration().get(ImportProvider.PARAM_SOURCE);
if (otherResourceValue == null) {
continue;
}
String otherResource = otherResourceValue.as(String.class);
URI otherAbsolute = URI.create(otherResource);
if (projectLoc != null && !otherAbsolute.isAbsolute()) {
otherAbsolute = projectLoc.resolve(otherAbsolute);
}
String action = conf.getActionId();
// resource is already loaded into the project
if (currentAbsolute.equals(otherAbsolute) && Objects.equal(actionId, action)) {
// check if the resource is loaded with a provider that
// allows duplicates
boolean allowDuplicate = false;
IOProviderDescriptor providerFactory = IOProviderExtension.getInstance().getFactory(conf.getProviderId());
if (providerFactory != null) {
allowDuplicate = providerFactory.allowDuplicateResource();
}
if (!allowDuplicate) {
log.userError("Resource is already loaded. Loading duplicate resources is aborted!");
return false;
}
}
}
}
// enable provider internal caching
if (isProjectResource && provider instanceof CachingImportProvider) {
((CachingImportProvider) provider).setProvideCache();
}
IOReport report = execute(provider, defReport);
if (report != null) {
// add report to report server
ReportService repService = PlatformUI.getWorkbench().getService(ReportService.class);
repService.addReport(report);
// show message to user
if (report.isSuccess()) {
// let advisor handle results
try {
getContainer().run(true, false, new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
monitor.beginTask("Completing operation...", IProgressMonitor.UNKNOWN);
try {
advisor.handleResults(getProvider());
} finally {
monitor.done();
}
}
});
} catch (InvocationTargetException e) {
log.userError("Error processing results:\n" + e.getCause().getLocalizedMessage(), e.getCause());
return false;
} catch (Exception e) {
log.userError("Error processing results:\n" + e.getLocalizedMessage(), e);
return false;
}
// add to project service if necessary
if (isProjectResource)
ps.rememberIO(actionId, getProviderFactory().getIdentifier(), provider);
return true;
} else {
// error message
log.userError(report.getSummary() + "\nPlease see the report for details.");
return false;
}
} else
return true;
} catch (IOProviderConfigurationException e) {
// user feedback
log.userError("Validation of the provider configuration failed:\n" + e.getLocalizedMessage(), e);
return false;
}
}
use of eu.esdihumboldt.hale.common.core.io.Value in project hale by halestudio.
the class DefaultCustomPropertyFunctionTypeTest method testWriteRead.
/**
* Test if a simple lookup table containing only string values is the same
* when converted to DOM and back again.
*/
@Test
public void testWriteRead() {
DefaultCustomPropertyFunction f = new DefaultCustomPropertyFunction();
f.setIdentifier("ident");
f.setFunctionType("groovy");
f.setName("My function");
f.setFunctionDefinition(Value.of(new Text("a + b")));
List<DefaultCustomPropertyFunctionEntity> sources = new ArrayList<>();
sources.add(createEntity("a", 1, 1, false));
sources.add(createEntity("b", 0, 1, false));
f.setSources(sources);
f.setTarget(createEntity(null, 1, 1, false));
List<DefaultCustomPropertyFunctionParameter> parameters = new ArrayList<>();
DefaultCustomPropertyFunctionParameter param1 = new DefaultCustomPropertyFunctionParameter();
param1.setName("gender");
Set<String> enumeration = new TreeSet<>();
enumeration.add("male");
enumeration.add("female");
param1.setMinOccurrence(1);
param1.setMaxOccurrence(1);
param1.setEnumeration(enumeration);
parameters.add(param1);
DefaultCustomPropertyFunctionParameter param2 = new DefaultCustomPropertyFunctionParameter();
param2.setName("name");
param2.setBindingClass(String.class);
param2.setMinOccurrence(0);
param2.setMaxOccurrence(1);
parameters.add(param2);
DefaultCustomPropertyFunctionParameter param3 = new DefaultCustomPropertyFunctionParameter();
param3.setName("flag");
param3.setBindingClass(Boolean.class);
param3.setMinOccurrence(1);
param3.setMaxOccurrence(1);
param3.setDefaultValue(Value.of(false));
String p3display = "Awesome flag";
param3.setDisplayName(p3display);
String p3desc = "Awesome flag estimated in 2016.\nAll rights conserved.";
param3.setDescription(p3desc);
parameters.add(param3);
f.setParameters(parameters);
// explanation
Map<Locale, Value> templates = new HashMap<>();
templates.put(Locale.ROOT, Value.of(new Text("Hello")));
templates.put(Locale.GERMAN, Value.of(new Text("Hallo")));
templates.put(Locale.FRANCE, Value.of(new Text("Salut")));
DefaultCustomFunctionExplanation explanation = new DefaultCustomFunctionExplanation(templates, null);
f.setExplanation(explanation);
// convert to DOM
Element fragment = HaleIO.getComplexElement(f);
// DEBUG
System.out.println(XmlUtil.serialize(fragment));
// convert back
DefaultCustomPropertyFunction conv = HaleIO.getComplexValue(fragment, DefaultCustomPropertyFunction.class, null);
// checks
assertNotNull(conv);
assertEquals(f.getIdentifier(), conv.getIdentifier());
assertEquals(f.getName(), conv.getName());
assertEquals(f.getFunctionType(), conv.getFunctionType());
// function definition
Text text = conv.getFunctionDefinition().as(Text.class);
assertNotNull(text);
assertEquals("a + b", text.getText());
// sources
assertEquals(2, conv.getSources().size());
DefaultCustomPropertyFunctionEntity source1 = conv.getSources().get(0);
assertEquals("a", source1.getName());
assertEquals(1, source1.getMinOccurrence());
assertEquals(1, source1.getMaxOccurrence());
DefaultCustomPropertyFunctionEntity source2 = conv.getSources().get(1);
assertEquals("b", source2.getName());
assertEquals(0, source2.getMinOccurrence());
// target
assertNotNull(conv.getTarget());
assertEquals(null, conv.getTarget().getName());
// parameters
assertEquals(3, conv.getParameters().size());
DefaultCustomPropertyFunctionParameter cp1 = conv.getParameters().get(0);
assertEquals("gender", cp1.getName());
assertEquals(2, cp1.getEnumeration().size());
DefaultCustomPropertyFunctionParameter cp2 = conv.getParameters().get(1);
assertEquals("name", cp2.getName());
assertEquals(0, cp2.getMinOccurrence());
assertEquals(1, cp2.getMaxOccurrence());
assertEquals(String.class, cp2.getBindingClass());
DefaultCustomPropertyFunctionParameter cp3 = conv.getParameters().get(2);
assertEquals("flag", cp3.getName());
assertEquals(1, cp3.getMinOccurrence());
assertEquals(1, cp3.getMaxOccurrence());
assertEquals(Boolean.class, cp3.getBindingClass());
assertEquals(false, cp3.getDefaultValue().as(Boolean.class));
assertEquals(p3display, cp3.getDisplayName());
assertEquals(p3desc, cp3.getDescription());
// explanation
assertNotNull(conv.getExplanation());
Map<Locale, Value> tempConv = conv.getExplanation().getTemplates();
assertEquals(3, tempConv.size());
Value tempRoot = tempConv.get(Locale.ROOT);
assertNotNull(tempRoot);
assertEquals("Hello", tempRoot.as(Text.class).getText());
Value tempGerman = tempConv.get(Locale.GERMAN);
assertNotNull(tempGerman);
assertEquals("Hallo", tempGerman.as(Text.class).getText());
Value tempFrance = tempConv.get(Locale.FRANCE);
assertNotNull(tempFrance);
assertEquals("Salut", tempFrance.as(Text.class).getText());
}
Aggregations