Search in sources :

Example 21 with ProjectService

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

the class TransformDataWizardSourcePage method createControl.

/**
 * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
 */
@Override
public void createControl(Composite parent) {
    Composite content = new Composite(parent, SWT.NONE);
    content.setLayout(GridLayoutFactory.swtDefaults().create());
    final ListViewer listViewer = new ListViewer(content);
    listViewer.getControl().setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());
    if (!useProjectData) {
        Button addButton = new Button(content, SWT.PUSH);
        addButton.setText("Add source file");
        addButton.setLayoutData(GridDataFactory.swtDefaults().align(SWT.END, SWT.CENTER).create());
        addButton.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                InstanceImportWizard importWizard = new InstanceImportWizard();
                TransformDataImportAdvisor advisor = new TransformDataImportAdvisor();
                // specifying null as actionId results in no call to
                // ProjectService.rememberIO
                importWizard.setAdvisor(advisor, null);
                if (new HaleWizardDialog(getShell(), importWizard).open() == Dialog.OK) {
                    if (advisor.getInstances() != null) {
                        sourceCollections.add(advisor.getInstances());
                        listViewer.add(advisor.getLocation());
                        getContainer().updateButtons();
                    }
                }
            }
        });
    } else {
        // initialize project source data
        IRunnableWithProgress op = new IRunnableWithProgress() {

            @Override
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                monitor.beginTask("Prepare data sources", IProgressMonitor.UNKNOWN);
                ProjectService ps = PlatformUI.getWorkbench().getService(ProjectService.class);
                final List<URI> locations = new ArrayList<>();
                for (Resource resource : ps.getResources()) {
                    if (InstanceIO.ACTION_LOAD_SOURCE_DATA.equals(resource.getActionId())) {
                        // resource is source data
                        IOConfiguration conf = resource.copyConfiguration(true);
                        TransformDataImportAdvisor advisor = new TransformDataImportAdvisor();
                        ProjectResourcesUtil.executeConfiguration(conf, advisor, false, null);
                        if (advisor.getInstances() != null) {
                            sourceCollections.add(advisor.getInstances());
                            locations.add(advisor.getLocation());
                        }
                    }
                }
                PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {

                    @Override
                    public void run() {
                        for (URI location : locations) {
                            listViewer.add(location);
                        }
                    }
                });
                monitor.done();
            }
        };
        try {
            ThreadProgressMonitor.runWithProgressDialog(op, false);
        } catch (Exception e) {
            throw new IllegalStateException(e);
        }
    }
    setControl(content);
}
Also used : InstanceImportWizard(eu.esdihumboldt.hale.ui.io.instance.InstanceImportWizard) ListViewer(org.eclipse.jface.viewers.ListViewer) Composite(org.eclipse.swt.widgets.Composite) IOConfiguration(eu.esdihumboldt.hale.common.core.io.project.model.IOConfiguration) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ArrayList(java.util.ArrayList) Resource(eu.esdihumboldt.hale.common.core.io.project.model.Resource) ProjectService(eu.esdihumboldt.hale.ui.service.project.ProjectService) URI(java.net.URI) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) HaleWizardDialog(eu.esdihumboldt.hale.ui.util.wizard.HaleWizardDialog)

Example 22 with ProjectService

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

the class ResourcesLabelProvider method getText.

@Override
public String getText(Object element) {
    if (element instanceof ProjectToken) {
        ProjectService ps = PlatformUI.getWorkbench().getService(ProjectService.class);
        String name = ps.getProjectInfo().getName();
        if (name == null) {
            return "<Unnamed project>";
        }
        return name;
    }
    if (element instanceof IOAction) {
        IOAction action = (IOAction) element;
        // resource category name
        if (action.getResourceCategoryName() != null) {
            return action.getResourceCategoryName();
        }
        // action name
        if (action.getName() != null) {
            return action.getName();
        }
        // action ID
        return action.getId();
    }
    if (element instanceof Resource) {
        Resource resource = (Resource) element;
        if (resource.getSource() != null) {
            String location = resource.getSource().toString();
            int index = location.lastIndexOf('/');
            if (index > 0 && index < location.length()) {
                return location.substring(index + 1);
            } else {
                return location;
            }
        }
        return resource.getResourceId();
    }
    if (element instanceof IContentType) {
        IContentType ct = (IContentType) element;
        return ct.getName();
    }
    return element.toString();
}
Also used : Resource(eu.esdihumboldt.hale.common.core.io.project.model.Resource) ProjectService(eu.esdihumboldt.hale.ui.service.project.ProjectService) IOAction(eu.esdihumboldt.hale.common.core.io.IOAction) IContentType(org.eclipse.core.runtime.content.IContentType) StyledString(org.eclipse.jface.viewers.StyledString)

Example 23 with ProjectService

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

the class ProjectProperties method refresh.

@Override
public void refresh() {
    super.refresh();
    ProjectService ps = PlatformUI.getWorkbench().getService(ProjectService.class);
    ProjectInfo info = ps.getProjectInfo();
    updateProject = false;
    nameText.setText((info.getName() == null) ? ("") : (info.getName()));
    authorText.setText((info.getAuthor() == null) ? ("") : (info.getAuthor()));
    descriptionText.setText((info.getDescription() == null) ? ("") : (info.getDescription()));
    updateProject = true;
}
Also used : ProjectInfo(eu.esdihumboldt.hale.common.core.io.project.ProjectInfo) ProjectService(eu.esdihumboldt.hale.ui.service.project.ProjectService)

Example 24 with ProjectService

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

the class ApplicationWorkbenchAdvisor method preShutdown.

/**
 * @see WorkbenchAdvisor#preShutdown()
 */
@Override
public boolean preShutdown() {
    // call workbench hooks
    boolean shutdownCanceled = false;
    for (WorkbenchHook hook : hooks) {
        try {
            if (!hook.preShutdown(getWorkbenchConfigurer().getWorkbench())) {
                shutdownCanceled = true;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    if (shutdownCanceled) {
        return false;
    }
    // ask for save if there are changes
    // TODO use a workbench hook for this
    ProjectService ps = PlatformUI.getWorkbench().getService(ProjectService.class);
    if (ps.isChanged()) {
        Shell shell = PlatformUI.getWorkbench().getWorkbenchWindows()[0].getShell();
        MessageBox mb = new MessageBox(shell, SWT.YES | SWT.NO | SWT.CANCEL | SWT.ICON_QUESTION);
        // $NON-NLS-1$
        mb.setMessage(Messages.ApplicationWorkbenchAdvisor_1);
        // $NON-NLS-1$
        mb.setText(Messages.ApplicationWorkbenchAdvisor_2);
        int result = mb.open();
        if (result == SWT.CANCEL) {
            return false;
        } else if (result == SWT.YES) {
            // try saving project
            ps.save();
            if (ps.isChanged()) {
                return false;
            }
            return true;
        } else {
            return true;
        }
    } else {
        return true;
    }
}
Also used : Shell(org.eclipse.swt.widgets.Shell) WorkbenchHook(eu.esdihumboldt.hale.ui.application.workbench.WorkbenchHook) ProjectService(eu.esdihumboldt.hale.ui.service.project.ProjectService) MessageBox(org.eclipse.swt.widgets.MessageBox)

Example 25 with ProjectService

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

the class LoadProjectAction method run.

/**
 * @see org.eclipse.jface.action.Action#run()
 */
@Override
public void run() {
    if (Display.getCurrent() == null) {
        // execute in display thread
        PlatformUI.getWorkbench().getDisplay().asyncExec(this);
        return;
    }
    PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell().forceActive();
    // close intro if specified and visible
    if (closeIntro) {
        IIntroPart introPart = PlatformUI.getWorkbench().getIntroManager().getIntro();
        if (introPart != null)
            PlatformUI.getWorkbench().getIntroManager().closeIntro(introPart);
    }
    // executes event with last configuration
    ProjectService ps = PlatformUI.getWorkbench().getService(ProjectService.class);
    // load a given file or show open project dialog
    if (path != null) {
        if (TYPE_FILE.equalsIgnoreCase(type) || type == null)
            ps.load(new File(path).toURI());
        else if (TYPE_URI.equalsIgnoreCase(type))
            ps.load(URI.create(path));
        else if (TYPE_BUNDLE.equalsIgnoreCase(type))
            try {
                // ps.load(Platform.getBundle(bundle).getEntry(path).toURI());
                StringBuilder b = new StringBuilder();
                b.append("platform:/plugin/");
                b.append(bundle);
                if (path.length() > 0 && path.charAt(0) != '/') {
                    b.append("/");
                }
                b.append(path);
                ps.load(new URI(b.toString()));
            } catch (URISyntaxException e) {
                throw new IllegalArgumentException(e);
            }
    } else
        ps.open();
}
Also used : IIntroPart(org.eclipse.ui.intro.IIntroPart) ProjectService(eu.esdihumboldt.hale.ui.service.project.ProjectService) URISyntaxException(java.net.URISyntaxException) File(java.io.File) URI(java.net.URI)

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