Search in sources :

Example 36 with ProjectService

use of eu.esdihumboldt.hale.ui.service.project.ProjectService in project hale by halestudio.

the class SaveConfigurationInstanceExportWizard method performFinish.

@Override
public boolean performFinish() {
    if (!applyConfiguration()) {
        return false;
    }
    IOConfiguration configuration = new IOConfiguration();
    // store the (export) configuration of the provider in the new IO
    // configuration
    configuration.setActionId(getActionId());
    configuration.setProviderId(getProviderFactory().getIdentifier());
    getProvider().storeConfiguration(configuration.getProviderConfiguration());
    ProjectService ps = PlatformUI.getWorkbench().getService(ProjectService.class);
    // target is not set here and also not needed for the configuration
    configuration.getProviderConfiguration().remove(ExportProvider.PARAM_TARGET);
    // add the new configuration to the export configurations of the project
    ps.addExportConfiguration(configurationName, configuration);
    log.userInfo(MessageFormat.format("Created export configuration ''{0}''", configurationName));
    return true;
}
Also used : IOConfiguration(eu.esdihumboldt.hale.common.core.io.project.model.IOConfiguration) ProjectService(eu.esdihumboldt.hale.ui.service.project.ProjectService)

Example 37 with ProjectService

use of eu.esdihumboldt.hale.ui.service.project.ProjectService in project hale by halestudio.

the class ArchiveProjectExportAdvisor method prepareProvider.

@Override
public void prepareProvider(ArchiveProjectWriter provider) {
    super.prepareProvider(provider);
    ProjectService projectService = getService(ProjectService.class);
    Project project = (Project) projectService.getProjectInfo();
    // set a copy of the project
    provider.setProject(project.clone());
}
Also used : Project(eu.esdihumboldt.hale.common.core.io.project.model.Project) ProjectService(eu.esdihumboldt.hale.ui.service.project.ProjectService)

Example 38 with ProjectService

use of eu.esdihumboldt.hale.ui.service.project.ProjectService in project hale by halestudio.

the class URLTargetURIFieldEditor method getTextControl.

@Override
public Text getTextControl(Composite parent) {
    // ensure resource control is added before the text control
    historyButton = new Button(parent, SWT.PUSH | SWT.FLAT);
    historyButton.setToolTipText("Choose from recent URLs");
    historyButton.setImage(CommonSharedImages.getImageRegistry().get(CommonSharedImages.IMG_HISTORY));
    historyButton.setEnabled(false);
    historyButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            ProjectService ps = PlatformUI.getWorkbench().getService(ProjectService.class);
            final List<String> locations = ps.getConfigurationService().getList(SETTING_URL_HISTORY);
            if (locations != null && !locations.isEmpty()) {
                Menu filesMenu = new Menu(historyButton);
                for (String locationString : locations) {
                    try {
                        final URI location = URI.create(locationString);
                        MenuItem item = new MenuItem(filesMenu, SWT.PUSH);
                        item.setText(RecentProjectsMenu.shorten(location.toString(), 80, 20));
                        item.addSelectionListener(new SelectionAdapter() {

                            @Override
                            public void widgetSelected(SelectionEvent e) {
                                getTextControl().setText(location.toString());
                                getTextControl().setFocus();
                                valueChanged();
                                onHistorySelected(location);
                            }
                        });
                    } catch (Exception e1) {
                    // ignore
                    }
                }
                Point histLoc = historyButton.getParent().toDisplay(historyButton.getLocation());
                filesMenu.setLocation(histLoc.x, histLoc.y + historyButton.getSize().y);
                filesMenu.setVisible(true);
            }
        }
    });
    return super.getTextControl(parent);
}
Also used : Button(org.eclipse.swt.widgets.Button) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ProjectService(eu.esdihumboldt.hale.ui.service.project.ProjectService) ArrayList(java.util.ArrayList) List(java.util.List) MenuItem(org.eclipse.swt.widgets.MenuItem) RecentProjectsMenu(eu.esdihumboldt.hale.ui.service.project.RecentProjectsMenu) Menu(org.eclipse.swt.widgets.Menu) Point(org.eclipse.swt.graphics.Point) URI(java.net.URI)

Example 39 with ProjectService

use of eu.esdihumboldt.hale.ui.service.project.ProjectService in project hale by halestudio.

the class URLTargetURIFieldEditor method getURI.

/**
 * Get the entered URI.
 *
 * @param store if the URI should be stored in the history
 * @return the URI or <code>null</code>
 */
@Nullable
public URI getURI(boolean store) {
    URI uri = super.getURI();
    if (uri != null && store) {
        String value = uri.toString();
        // store the URI in the history list
        ProjectService ps = PlatformUI.getWorkbench().getService(ProjectService.class);
        List<String> history = ps.getConfigurationService().getList(SETTING_URL_HISTORY);
        if (history != null) {
            List<String> newHistory = new ArrayList<>(history);
            boolean unchanged = history.size() >= 1 && history.get(0).equals(value);
            if (!unchanged) {
                // remove any occurrences
                while (newHistory.remove(value)) {
                // nothing to do
                }
                // insert at beginning
                newHistory.add(0, value);
                while (newHistory.size() > HISTORY_MAX_SIZE) {
                    newHistory.remove(newHistory.size() - 1);
                }
                ps.getConfigurationService().setList(SETTING_URL_HISTORY, newHistory);
            }
        } else {
            // just store the new value
            ps.getConfigurationService().setList(SETTING_URL_HISTORY, Collections.singletonList(value));
        }
        updateHistory();
    }
    return uri;
}
Also used : ArrayList(java.util.ArrayList) ProjectService(eu.esdihumboldt.hale.ui.service.project.ProjectService) URI(java.net.URI) Nullable(javax.annotation.Nullable)

Example 40 with ProjectService

use of eu.esdihumboldt.hale.ui.service.project.ProjectService in project hale by halestudio.

the class UserFallbackEntityResolver method resolveType.

/**
 * Ask the user to select a replacement for a type.
 *
 * @param original the original entity
 * @param candidate a candidate for the replacement
 * @param schemaSpace the schema space
 * @return the resolved type (may be the original)
 */
public static Type resolveType(TypeEntityDefinition original, @Nullable EntityDefinition candidate, SchemaSpaceID schemaSpace) {
    ResolveCache cache = getCache();
    TypeEntityDefinition replacement = cache.getReplacement(original);
    if (replacement != null) {
        // use cached replacement
        return new DefaultType(replacement);
    }
    ProjectService ps = HaleUI.getServiceProvider().getService(ProjectService.class);
    final AtomicBoolean canceled;
    final AtomicBoolean skipped = new AtomicBoolean(false);
    if (ps.getTemporaryProperty(RESOLVE_SKIP_PROPERTY, Value.of(false)).as(Boolean.class)) {
        canceled = new AtomicBoolean(true);
    } else {
        canceled = new AtomicBoolean(false);
    }
    final AtomicReference<EntityDefinition> result = new AtomicReference<>();
    if (!canceled.get()) {
        PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {

            @Override
            public void run() {
                TypeEntityResolverDialog dlg = new TypeEntityResolverDialog(Display.getCurrent().getActiveShell(), schemaSpace, "Cell entity could not be resolved", candidate, false) {

                    @Override
                    public void create() {
                        super.create();
                        openTray(new ViewerEntityTray(original));
                    }
                };
                switch(dlg.open()) {
                    case Window.OK:
                        result.set(dlg.getObject());
                        break;
                    case Window.CANCEL:
                        // Don't try to resolve further entities
                        ps.setTemporaryProperty(RESOLVE_SKIP_PROPERTY, Value.of(true));
                        canceled.set(true);
                        break;
                    case TypeEntityResolverDialog.SKIP:
                        // skip this entity
                        skipped.set(true);
                        break;
                    default:
                        canceled.set(true);
                }
            }
        });
    }
    EntityDefinition def = result.get();
    if (canceled.get() || skipped.get()) {
        // return the original so the cell is not lost
        return new DefaultType(original);
    } else if (def == null) {
        // caller must take care about this
        return null;
    } else {
        TypeEntityDefinition ted = (TypeEntityDefinition) def;
        // make sure that the type is classified as mapping relevant
        if (!ted.getType().getConstraint(MappingRelevantFlag.class).isEnabled()) {
            SchemaService ss = PlatformUI.getWorkbench().getService(SchemaService.class);
            ss.toggleMappable(schemaSpace, Collections.singleton(ted.getType()));
        }
        cache.put(original, ted);
        return new DefaultType(ted);
    }
}
Also used : DefaultType(eu.esdihumboldt.hale.common.align.model.impl.DefaultType) TypeEntityResolverDialog(eu.esdihumboldt.hale.ui.service.align.resolver.internal.TypeEntityResolverDialog) ProjectService(eu.esdihumboldt.hale.ui.service.project.ProjectService) ViewerEntityTray(eu.esdihumboldt.hale.ui.service.align.resolver.internal.ViewerEntityTray) AtomicReference(java.util.concurrent.atomic.AtomicReference) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) PropertyEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition) TypeEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition) EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) TypeEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition) SchemaService(eu.esdihumboldt.hale.ui.service.schema.SchemaService) ResolveCache(eu.esdihumboldt.hale.ui.service.align.resolver.internal.ResolveCache) MappingRelevantFlag(eu.esdihumboldt.hale.common.schema.model.constraint.type.MappingRelevantFlag)

Aggregations

ProjectService (eu.esdihumboldt.hale.ui.service.project.ProjectService)49 IOConfiguration (eu.esdihumboldt.hale.common.core.io.project.model.IOConfiguration)5 Resource (eu.esdihumboldt.hale.common.core.io.project.model.Resource)5 URI (java.net.URI)5 ArrayList (java.util.ArrayList)5 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)5 SelectionEvent (org.eclipse.swt.events.SelectionEvent)5 Button (org.eclipse.swt.widgets.Button)5 Value (eu.esdihumboldt.hale.common.core.io.Value)4 ResolveCache (eu.esdihumboldt.hale.ui.service.align.resolver.internal.ResolveCache)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)4 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)4 Project (eu.esdihumboldt.hale.common.core.io.project.model.Project)3 SchemaService (eu.esdihumboldt.hale.ui.service.schema.SchemaService)3 List (java.util.List)3 Composite (org.eclipse.swt.widgets.Composite)3 EntityDefinition (eu.esdihumboldt.hale.common.align.model.EntityDefinition)2 PropertyEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition)2 TypeEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition)2