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);
}
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);
}
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());
}
}
}
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();
}
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();
}
}
}
}
Aggregations