Search in sources :

Example 6 with Resource

use of gate.Resource in project gate-core by GateNLP.

the class MainFrame method resourceUnloaded.

// resourceLoaded();
@Override
public void resourceUnloaded(CreoleEvent e) {
    final Resource res = e.getResource();
    if (Gate.getHiddenAttribute(res.getFeatures()))
        return;
    Runnable runner = new Runnable() {

        @Override
        public void run() {
            DefaultMutableTreeNode node;
            DefaultMutableTreeNode parent = null;
            if (res instanceof Controller) {
                parent = applicationsRoot;
            } else if (res instanceof ProcessingResource) {
                parent = processingResourcesRoot;
            } else if (res instanceof LanguageResource) {
                parent = languageResourcesRoot;
            }
            if (parent != null) {
                Enumeration<?> children = parent.children();
                while (children.hasMoreElements()) {
                    node = (DefaultMutableTreeNode) children.nextElement();
                    if (((NameBearerHandle) node.getUserObject()).getTarget() == res) {
                        resourcesTreeModel.removeNodeFromParent(node);
                        Handle handle = (Handle) node.getUserObject();
                        if (handle.viewsBuilt()) {
                            if (mainTabbedPane.indexOfComponent(handle.getLargeView()) != -1)
                                mainTabbedPane.remove(handle.getLargeView());
                            if (lowerScroll.getViewport().getView() == handle.getSmallView())
                                lowerScroll.getViewport().setView(null);
                        }
                        handle.cleanup();
                        return;
                    }
                }
            }
        }
    };
    SwingUtilities.invokeLater(runner);
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) LanguageResource(gate.LanguageResource) ProcessingResource(gate.ProcessingResource) VisualResource(gate.VisualResource) Resource(gate.Resource) LanguageResource(gate.LanguageResource) ProcessingResource(gate.ProcessingResource) Controller(gate.Controller) ConditionalSerialAnalyserController(gate.creole.ConditionalSerialAnalyserController) PackagedController(gate.creole.PackagedController)

Example 7 with Resource

use of gate.Resource in project gate-core by GateNLP.

the class AnnotationEditor method initData.

protected void initData() {
    schemasByType = new HashMap<String, AnnotationSchema>();
    java.util.List<LanguageResource> schemas = Gate.getCreoleRegister().getLrInstances("gate.creole.AnnotationSchema");
    for (Iterator<LanguageResource> schIter = schemas.iterator(); schIter.hasNext(); ) {
        AnnotationSchema aSchema = (AnnotationSchema) schIter.next();
        schemasByType.put(aSchema.getAnnotationName(), aSchema);
    }
    CreoleListener creoleListener = new CreoleListener() {

        @Override
        public void resourceLoaded(CreoleEvent e) {
            Resource newResource = e.getResource();
            if (newResource instanceof AnnotationSchema) {
                AnnotationSchema aSchema = (AnnotationSchema) newResource;
                schemasByType.put(aSchema.getAnnotationName(), aSchema);
            }
        }

        @Override
        public void resourceUnloaded(CreoleEvent e) {
            Resource newResource = e.getResource();
            if (newResource instanceof AnnotationSchema) {
                AnnotationSchema aSchema = (AnnotationSchema) newResource;
                if (schemasByType.containsValue(aSchema)) {
                    schemasByType.remove(aSchema.getAnnotationName());
                }
            }
        }

        @Override
        public void datastoreOpened(CreoleEvent e) {
        }

        @Override
        public void datastoreCreated(CreoleEvent e) {
        }

        @Override
        public void datastoreClosed(CreoleEvent e) {
        }

        @Override
        public void resourceRenamed(Resource resource, String oldName, String newName) {
        }
    };
    Gate.getCreoleRegister().addCreoleListener(creoleListener);
}
Also used : CreoleListener(gate.event.CreoleListener) AnnotationSchema(gate.creole.AnnotationSchema) LanguageResource(gate.LanguageResource) CreoleEvent(gate.event.CreoleEvent) Resource(gate.Resource) LanguageResource(gate.LanguageResource) AbstractVisualResource(gate.creole.AbstractVisualResource)

Example 8 with Resource

use of gate.Resource in project gate-core by GateNLP.

the class SerialDatastoreViewer method resourceWritten.

@Override
public void resourceWritten(DatastoreEvent e) {
    Resource res = e.getResource();
    String resID = (String) e.getResourceID();
    String resType = Gate.getCreoleRegister().get(res.getClass().getName()).getName();
    DefaultMutableTreeNode parent = treeRoot;
    DefaultMutableTreeNode node = null;
    // first look for the type node
    Enumeration<?> childrenEnum = parent.children();
    boolean found = false;
    while (childrenEnum.hasMoreElements() && !found) {
        node = (DefaultMutableTreeNode) childrenEnum.nextElement();
        if (node.getUserObject() instanceof DSType) {
            found = ((DSType) node.getUserObject()).name.equals(resType);
        }
    }
    if (!found) {
        // exhausted the children without finding the node -> new type
        node = new DefaultMutableTreeNode(new DSType(resType, res.getClass().getName()));
        treeModel.insertNodeInto(node, parent, parent.getChildCount());
    }
    if (node.getUserObject() instanceof DSType) {
        if (!((DSType) node.getUserObject()).expanded)
            return;
    }
    // now look for the resource node
    parent = node;
    childrenEnum = parent.children();
    found = false;
    while (childrenEnum.hasMoreElements() && !found) {
        node = (DefaultMutableTreeNode) childrenEnum.nextElement();
        found = ((DSEntry) node.getUserObject()).id.equals(resID);
    }
    if (!found) {
        // exhausted the children without finding the node -> new resource
        try {
            DSEntry entry = new DSEntry(datastore.getLrName(resID), resID, res.getClass().getName());
            node = new DefaultMutableTreeNode(entry, false);
            treeModel.insertNodeInto(node, parent, parent.getChildCount());
        } catch (PersistenceException pe) {
            pe.printStackTrace(Err.getPrintWriter());
        }
    }
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) VisualResource(gate.VisualResource) Resource(gate.Resource) CreoleResource(gate.creole.metadata.CreoleResource) AbstractResource(gate.creole.AbstractResource) PersistenceException(gate.persist.PersistenceException)

Example 9 with Resource

use of gate.Resource in project gate-core by GateNLP.

the class PRViewer method setTarget.

@Override
public void setTarget(Object target) {
    if (target == null)
        return;
    if (!(target instanceof Resource)) {
        throw new GateRuntimeException(this.getClass().getName() + " can only be used to display " + Resource.class.getName() + "\n" + target.getClass().getName() + " is not a " + Resource.class.getName() + "!");
    }
    Resource pr = (Resource) target;
    ResourceData rData = Gate.getCreoleRegister().get(pr.getClass().getName());
    if (rData != null) {
        editor.init(pr, rData.getParameterList().getInitimeParameters());
    } else {
        editor.init(pr, null);
    }
    editor.removeCreoleListenerLink();
}
Also used : ResourceData(gate.creole.ResourceData) GateRuntimeException(gate.util.GateRuntimeException) CreoleResource(gate.creole.metadata.CreoleResource) Resource(gate.Resource) AbstractVisualResource(gate.creole.AbstractVisualResource)

Example 10 with Resource

use of gate.Resource in project gate-core by GateNLP.

the class GateClassLoader method forgetClassLoader.

public void forgetClassLoader(String id, Plugin dInfo) {
    if (dInfo == null) {
        forgetClassLoader(id);
        return;
    }
    GateClassLoader classloader = null;
    synchronized (childClassLoaders) {
        classloader = childClassLoaders.remove(id);
    }
    if (classloader != null && !classloader.isIsolated()) {
        // classloader was responsible for
        for (ResourceInfo rInfo : dInfo.getResourceInfoList()) {
            try {
                @SuppressWarnings("unchecked") Class<? extends Resource> c = (Class<? extends Resource>) classloader.loadClass(rInfo.getResourceClassName());
                if (c != null) {
                    // in theory this shouldn't be needed as the Introspector
                    // uses soft references if we move to requiring Java 8 it
                    // should be safe to drop this call
                    Introspector.flushFromCaches(c);
                    AbstractResource.forgetBeanInfo(c);
                }
            } catch (ClassNotFoundException e) {
                // hmm not sure what to do now
                e.printStackTrace();
            }
        }
    }
}
Also used : ResourceInfo(gate.Gate.ResourceInfo) Resource(gate.Resource) AbstractResource(gate.creole.AbstractResource)

Aggregations

Resource (gate.Resource)26 LanguageResource (gate.LanguageResource)9 CreoleResource (gate.creole.metadata.CreoleResource)9 FeatureMap (gate.FeatureMap)8 ProcessingResource (gate.ProcessingResource)8 VisualResource (gate.VisualResource)6 GateException (gate.util.GateException)5 GateRuntimeException (gate.util.GateRuntimeException)5 URL (java.net.URL)5 AbstractVisualResource (gate.creole.AbstractVisualResource)4 Corpus (gate.Corpus)3 AbstractResource (gate.creole.AbstractResource)3 ResourceData (gate.creole.ResourceData)3 ResourceInstantiationException (gate.creole.ResourceInstantiationException)3 PersistenceException (gate.persist.PersistenceException)3 ArrayList (java.util.ArrayList)3 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)3 Controller (gate.Controller)2 Document (gate.Document)2 ResourceInfo (gate.Gate.ResourceInfo)2