use of eu.esdihumboldt.hale.ui.service.project.ProjectService in project hale by halestudio.
the class ProjectVariablesPreferencePage method performOk.
@Override
public boolean performOk() {
ProjectService ps = PlatformUI.getWorkbench().getService(ProjectService.class);
if (changed) {
for (Entry<String, List<Control>> entry : varControls.entrySet()) {
String varName = entry.getKey();
Text textField = (Text) entry.getValue().get(1);
variables.put(varName, Value.of(textField.getText()));
}
ps.getConfigurationService().setProperty(ProjectVariables.PROJECT_PROPERTY_VARIABLES, Value.complex(variables));
changed = false;
}
return true;
}
use of eu.esdihumboldt.hale.ui.service.project.ProjectService in project hale by halestudio.
the class NewRelationPage method createViewer.
/**
* @see ViewerWizardSelectionPage#createViewer(Composite)
*/
@Override
protected Pair<StructuredViewer, Control> createViewer(Composite parent) {
PatternFilter filter = new PatternFilter();
filter.setIncludeLeadingWildcard(true);
FilteredTree tree = new FilteredTree(parent, SWT.SINGLE | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL, filter, true);
viewer = tree.getViewer();
viewer.setContentProvider(new FunctionWizardNodeContentProvider(getContainer(), initialSelection, selectionMatcher));
viewer.setLabelProvider(new FunctionWizardNodeLabelProvider());
// no input needed, but we have to set something
viewer.setInput(Boolean.TRUE);
// set focus on viewer control to prevent odd behavior
viewer.getControl().setFocus();
// expand selection
viewer.expandAll();
// selection context
contextProvider = new HALEContextProvider(viewer, null);
// help update on page shown
if (getContainer() instanceof IPageChangeProvider) {
((IPageChangeProvider) getContainer()).addPageChangedListener(changeListener = new IPageChangedListener() {
@Override
public void pageChanged(PageChangedEvent event) {
if (event.getSelectedPage() == NewRelationPage.this) {
// update the help button
if (getContainer() instanceof HaleWizardDialog) {
((HaleWizardDialog) getContainer()).setHelpButtonEnabled(getHelpContext() != null);
}
}
}
});
}
// help update on selection change
viewer.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
IContext context = getHelpContext();
// update the help button
if (getContainer() instanceof HaleWizardDialog) {
((HaleWizardDialog) getContainer()).setHelpButtonEnabled(context != null);
}
// update the help
if (context != null) {
TrayDialog trayDialog = (TrayDialog) getContainer();
if (trayDialog.getTray() != null) {
// if the tray is already open, update the help
performHelp();
}
}
}
});
// load page configuration
// XXX would be better if called from outside
ProjectService ps = PlatformUI.getWorkbench().getService(ProjectService.class);
restore(ps.getConfigurationService());
return new Pair<StructuredViewer, Control>(viewer, tree);
}
use of eu.esdihumboldt.hale.ui.service.project.ProjectService 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.ui.service.project.ProjectService in project hale by halestudio.
the class ArchiveProjectImportAdvisor method handleResults.
@Override
public void handleResults(ArchiveProjectImport provider) {
ProjectService projectService = getService(ProjectService.class);
projectService.load(provider.getProjectLocation());
}
use of eu.esdihumboldt.hale.ui.service.project.ProjectService in project hale by halestudio.
the class FileSource method createControls.
/**
* @see ImportSource#createControls(Composite)
*/
@Override
public void createControls(Composite parent) {
parent.setLayout(new GridLayout(4, false));
ProjectService ps = PlatformUI.getWorkbench().getService(ProjectService.class);
projectLocation = ps.getLoadLocation() == null ? null : ps.getLoadLocation();
boolean projectLocAvailable = projectLocation != null && "file".equals(projectLocation.getScheme());
// source file
sourceFile = new FileSourceFileFieldEditor("sourceFile", "Source file:", FileFieldEditor.VALIDATE_ON_KEY_STROKE, parent, projectLocation);
sourceFile.setEmptyStringAllowed(false);
sourceFile.setPage(getPage());
// set content types for file field
Collection<IOProviderDescriptor> factories = getConfiguration().getFactories();
supportedTypes = new HashSet<IContentType>();
for (IOProviderDescriptor factory : factories) {
supportedTypes.addAll(factory.getSupportedTypes());
}
sourceFile.setContentTypes(supportedTypes);
sourceFile.setPropertyChangeListener(new IPropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent event) {
if (event.getProperty().equals(FieldEditor.IS_VALID)) {
updateState(true);
} else if (event.getProperty().equals(FieldEditor.VALUE)) {
updateState(true);
}
}
});
// provider selection
// label
Label providerLabel = new Label(parent, SWT.NONE);
providerLabel.setText("Import as");
// create provider combo
ComboViewer providers = createProviders(parent);
providers.getControl().setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false, 3, 1));
final Button relativeCheck = new Button(parent, SWT.CHECK);
String text = "Use relative paths if possible.";
relativeCheck.setText("Use relative paths if possible.");
relativeCheck.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
sourceFile.setUseRelativeIfPossible(relativeCheck.getSelection());
}
});
if (!projectLocAvailable) {
relativeCheck.setEnabled(false);
text += " Only available once the project is saved to a file.";
}
relativeCheck.setText(text);
relativeCheck.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false, 4, 1));
// initial state update
updateState(true);
}
Aggregations