Search in sources :

Example 1 with ExampleProject

use of eu.esdihumboldt.hale.doc.user.examples.internal.extension.ExampleProject in project hale by halestudio.

the class ExamplesContribution method getActions.

/**
 * @see DynamicActionsContribution#getActions()
 */
@Override
protected Iterable<IAction> getActions() {
    final AtomicReference<List<IAction>> actionsRef = new AtomicReference<List<IAction>>();
    final AtomicBoolean finished = new AtomicBoolean(false);
    BusyIndicator.showWhile(PlatformUI.getWorkbench().getDisplay(), new Runnable() {

        @Override
        public void run() {
            try {
                List<IAction> actions = new ArrayList<IAction>();
                for (ExampleProject project : ExampleProjectExtension.getInstance().getElements()) {
                    actions.add(new ShowProjectAction(project));
                }
                actionsRef.set(actions);
            } finally {
                finished.set(true);
            }
        }
    });
    while (!finished.get()) {
        if (Display.getCurrent() != null) {
            while (Display.getCurrent().readAndDispatch()) {
            // repeat
            }
        }
        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
        // ignore
        }
    }
    List<IAction> actions = actionsRef.get();
    if (actions == null) {
        // populating the list failed
        actions = new ArrayList<IAction>();
    }
    if (!actions.isEmpty()) {
        actions.add(0, null);
    }
    actions.add(0, new ExampleOverviewAction());
    return actions;
}
Also used : IAction(org.eclipse.jface.action.IAction) AtomicReference(java.util.concurrent.atomic.AtomicReference) ExampleProject(eu.esdihumboldt.hale.doc.user.examples.internal.extension.ExampleProject) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ArrayList(java.util.ArrayList) List(java.util.List)

Example 2 with ExampleProject

use of eu.esdihumboldt.hale.doc.user.examples.internal.extension.ExampleProject in project hale by halestudio.

the class ExamplesContent method getInputStream.

/**
 * @see IHelpContentProducer#getInputStream(String, String, Locale)
 */
@Override
public InputStream getInputStream(String pluginID, String href, Locale locale) {
    ATransaction trans = log.begin("Generating examples help content");
    try {
        if (href.startsWith(PATH_PREFIX_PROJECT)) {
            // references a project
            // determine the project id
            String projectId = href.substring(PATH_PREFIX_PROJECT.length());
            // strip everything after a ?
            int ind = projectId.indexOf('?');
            if (ind >= 0) {
                projectId = projectId.substring(0, ind);
            }
            // strip the .*htm? ending
            if (projectId.endsWith("html") || projectId.endsWith("htm")) {
                projectId = projectId.substring(0, projectId.lastIndexOf('.'));
            }
            if (projectId.endsWith(PATH_SUFFIX_MAPPINGDOC)) {
                projectId = projectId.substring(0, projectId.length() - PATH_SUFFIX_MAPPINGDOC.length());
                return getMappingContent(projectId);
            }
            ExampleProject project = ExampleProjectExtension.getInstance().get(projectId);
            if (project != null) {
                return getProjectContent(project);
            }
            // Auxiliary mapping documentation files
            // XXX no / may be contained in
            ind = projectId.indexOf('/');
            // project id
            String path = projectId.substring(ind + 1);
            projectId = projectId.substring(0, ind);
            return getMappingFileContent(projectId, path);
        } else if (href.startsWith(PATH_OVERVIEW)) {
            return getOverviewContent();
        }
    } finally {
        trans.end();
    }
    return null;
}
Also used : ATransaction(de.fhg.igd.slf4jplus.ATransaction) ExampleProject(eu.esdihumboldt.hale.doc.user.examples.internal.extension.ExampleProject)

Example 3 with ExampleProject

use of eu.esdihumboldt.hale.doc.user.examples.internal.extension.ExampleProject in project hale by halestudio.

the class ExampleReferenceTopic method getSubtopics.

/**
 * @see ITopic#getSubtopics()
 */
@Override
public ITopic[] getSubtopics() {
    if (projectTopics == null) {
        ATransaction trans = log.begin("Initializing example project topics");
        try {
            Collection<ITopic> topics = new ArrayList<ITopic>();
            // initialize function topics
            for (ExampleProject project : ExampleProjectExtension.getInstance().getElements()) {
                ITopic projectTopic = new ProjectTopic(project);
                topics.add(projectTopic);
            }
            if (topics.isEmpty()) {
                projectTopics = NO_TOPICS;
            } else {
                projectTopics = topics.toArray(new ITopic[topics.size()]);
            }
        } finally {
            trans.end();
        }
    }
    return projectTopics;
}
Also used : ITopic(org.eclipse.help.ITopic) ATransaction(de.fhg.igd.slf4jplus.ATransaction) ArrayList(java.util.ArrayList) ExampleProject(eu.esdihumboldt.hale.doc.user.examples.internal.extension.ExampleProject)

Example 4 with ExampleProject

use of eu.esdihumboldt.hale.doc.user.examples.internal.extension.ExampleProject in project hale by halestudio.

the class ExamplesContent method getMappingContent.

/**
 * Get the mapping documentation content for an example project.
 *
 * @param projectId the project ID
 * @return the mapping documentation content stream or <code>null</code>
 */
private InputStream getMappingContent(String projectId) {
    if (!mappingDocExportInitialized) {
        mappingDocExport = HaleIO.createIOProvider(AlignmentWriter.class, null, ID_MAPPING_EXPORT);
        if (mappingDocExport == null) {
            log.error("Could not create mapping documentation exporter.");
        }
        mappingDocExportInitialized = true;
    }
    if (mappingDocExport == null) {
        // no mapping documentation export possible
        return null;
    }
    if (tempMappingDir == null) {
        tempMappingDir = Files.createTempDir();
        tempMappingDir.deleteOnExit();
    }
    // the file of the mapping documentation
    File mappingDoc = new File(tempMappingDir, projectId + ".html");
    if (!mappingDoc.exists()) {
        ATransaction trans = log.begin("Generate example mapping documentation");
        try {
            // create the mapping documentation
            ExampleProject exampleProject = ExampleProjectExtension.getInstance().get(projectId);
            final Project project = (Project) exampleProject.getInfo();
            // determine alignment location - contained in project file, not
            // a resource
            URI alignmentLoc = exampleProject.getAlignmentLocation();
            if (alignmentLoc == null) {
                // no alignment present
                return null;
            }
            // store configurations per action ID
            Multimap<String, IOConfiguration> confs = HashMultimap.create();
            for (IOConfiguration conf : project.getResources()) {
                confs.put(conf.getActionId(), conf);
            }
            // load schemas
            // source schemas
            LoadSchemaAdvisor source = new LoadSchemaAdvisor(SchemaSpaceID.SOURCE);
            for (IOConfiguration conf : confs.get(SchemaIO.ACTION_LOAD_SOURCE_SCHEMA)) {
                source.setConfiguration(conf);
                executeProvider(source, conf.getProviderId(), null);
            }
            // target schemas
            LoadSchemaAdvisor target = new LoadSchemaAdvisor(SchemaSpaceID.TARGET);
            for (IOConfiguration conf : confs.get(SchemaIO.ACTION_LOAD_TARGET_SCHEMA)) {
                target.setConfiguration(conf);
                executeProvider(target, conf.getProviderId(), null);
            }
            // load alignment
            // manual loading needed, as we can't rely on the environment
            // alignment advisor
            DefaultInputSupplier alignmentIn = new DefaultInputSupplier(alignmentLoc);
            AlignmentReader reader = HaleIO.findIOProvider(AlignmentReader.class, alignmentIn, alignmentLoc.getPath());
            LoadAlignmentAdvisor alignmentAdvisor = new LoadAlignmentAdvisor(null, source.getSchemaSpace(), target.getSchemaSpace(), exampleProject.getUpdater());
            reader.setSource(alignmentIn);
            executeProvider(alignmentAdvisor, null, reader);
            Alignment alignment = alignmentAdvisor.getAlignment();
            if (alignment != null) {
                // save alignment docu
                synchronized (mappingDocExport) {
                    // only a single instance
                    mappingDocExport.setAlignment(alignment);
                    mappingDocExport.setTarget(new FileIOSupplier(mappingDoc));
                    if (mappingDocExport instanceof ProjectInfoAware) {
                        ProjectInfo smallInfo = new ProjectInfo() {

                            @Override
                            public String getName() {
                                return project.getName();
                            }

                            @Override
                            public Date getModified() {
                                return null;
                            }

                            @Override
                            public Version getHaleVersion() {
                                return null;
                            }

                            @Override
                            public String getDescription() {
                                return project.getDescription();
                            }

                            @Override
                            public Date getCreated() {
                                return null;
                            }

                            @Override
                            public String getAuthor() {
                                return project.getAuthor();
                            }
                        };
                        // project);
                        ((ProjectInfoAware) mappingDocExport).setProjectInfo(smallInfo);
                    }
                    mappingDocExport.execute(null);
                }
                mappingDoc.deleteOnExit();
            }
        } catch (Throwable e) {
            log.error("Error generating mapping documentation for example project", e);
            return null;
        } finally {
            trans.end();
        }
    }
    if (mappingDoc.exists()) {
        try {
            return new FileInputStream(mappingDoc);
        } catch (FileNotFoundException e) {
            return null;
        }
    } else
        return null;
}
Also used : AlignmentReader(eu.esdihumboldt.hale.common.align.io.AlignmentReader) DefaultInputSupplier(eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier) IOConfiguration(eu.esdihumboldt.hale.common.core.io.project.model.IOConfiguration) FileNotFoundException(java.io.FileNotFoundException) ExampleProject(eu.esdihumboldt.hale.doc.user.examples.internal.extension.ExampleProject) URI(java.net.URI) ProjectInfoAware(eu.esdihumboldt.hale.common.core.io.project.ProjectInfoAware) FileInputStream(java.io.FileInputStream) ExampleProject(eu.esdihumboldt.hale.doc.user.examples.internal.extension.ExampleProject) Project(eu.esdihumboldt.hale.common.core.io.project.model.Project) Alignment(eu.esdihumboldt.hale.common.align.model.Alignment) ATransaction(de.fhg.igd.slf4jplus.ATransaction) ProjectInfo(eu.esdihumboldt.hale.common.core.io.project.ProjectInfo) FileIOSupplier(eu.esdihumboldt.hale.common.core.io.supplier.FileIOSupplier) LoadSchemaAdvisor(eu.esdihumboldt.hale.common.schema.io.impl.LoadSchemaAdvisor) LoadAlignmentAdvisor(eu.esdihumboldt.hale.common.align.io.impl.LoadAlignmentAdvisor) File(java.io.File) AlignmentWriter(eu.esdihumboldt.hale.common.align.io.AlignmentWriter)

Aggregations

ExampleProject (eu.esdihumboldt.hale.doc.user.examples.internal.extension.ExampleProject)4 ATransaction (de.fhg.igd.slf4jplus.ATransaction)3 ArrayList (java.util.ArrayList)2 AlignmentReader (eu.esdihumboldt.hale.common.align.io.AlignmentReader)1 AlignmentWriter (eu.esdihumboldt.hale.common.align.io.AlignmentWriter)1 LoadAlignmentAdvisor (eu.esdihumboldt.hale.common.align.io.impl.LoadAlignmentAdvisor)1 Alignment (eu.esdihumboldt.hale.common.align.model.Alignment)1 ProjectInfo (eu.esdihumboldt.hale.common.core.io.project.ProjectInfo)1 ProjectInfoAware (eu.esdihumboldt.hale.common.core.io.project.ProjectInfoAware)1 IOConfiguration (eu.esdihumboldt.hale.common.core.io.project.model.IOConfiguration)1 Project (eu.esdihumboldt.hale.common.core.io.project.model.Project)1 DefaultInputSupplier (eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier)1 FileIOSupplier (eu.esdihumboldt.hale.common.core.io.supplier.FileIOSupplier)1 LoadSchemaAdvisor (eu.esdihumboldt.hale.common.schema.io.impl.LoadSchemaAdvisor)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 URI (java.net.URI)1 List (java.util.List)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1