use of gate.LanguageResource in project gate-core by GateNLP.
the class MainFrame method resourceLoaded.
@Override
public void resourceLoaded(CreoleEvent e) {
final Resource res = e.getResource();
if (Gate.getHiddenAttribute(res.getFeatures()) || res instanceof VisualResource)
return;
// SwingUtilities.invokeLater(new Runnable() {
// @Override
// public void run() {
NameBearerHandle handle = null;
if (res instanceof Controller) {
handle = new NameBearerHandle(res, MainFrame.this);
DefaultMutableTreeNode node = new DefaultMutableTreeNode(handle, false);
resourcesTreeModel.insertNodeInto(node, applicationsRoot, 0);
} else if (res instanceof ProcessingResource) {
handle = new NameBearerHandle(res, MainFrame.this);
DefaultMutableTreeNode node = new DefaultMutableTreeNode(handle, false);
resourcesTreeModel.insertNodeInto(node, processingResourcesRoot, 0);
} else if (res instanceof LanguageResource) {
handle = new NameBearerHandle(res, MainFrame.this);
DefaultMutableTreeNode node = new DefaultMutableTreeNode(handle, false);
resourcesTreeModel.insertNodeInto(node, languageResourcesRoot, 0);
}
if (handle != null)
handle.addProgressListener(MainFrame.this);
if (handle != null)
handle.addStatusListener(MainFrame.this);
// }
// });
// JPopupMenu popup = handle.getPopup();
//
// // Create a CloseViewAction and a menu item based on it
// CloseViewAction cva = new CloseViewAction(handle);
// XJMenuItem menuItem = new XJMenuItem(cva, this);
// // Add an accelerator ATL+F4 for this action
// menuItem.setAccelerator(KeyStroke.getKeyStroke(
// KeyEvent.VK_H, ActionEvent.CTRL_MASK));
// popup.insert(menuItem, 1);
// popup.insert(new JPopupMenu.Separator(), 2);
//
// popup.insert(new XJMenuItem(
// new RenameResourceAction(
// new TreePath(resourcesTreeModel.getPathToRoot(node))),
// MainFrame.this) , 3);
//
// // Put the action command in the component's action map
// if (handle.getLargeView() != null)
// handle.getLargeView().getActionMap().put("Hide current
// view",cva);
//
}
use of gate.LanguageResource 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.LanguageResource 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.LanguageResource in project gate-core by GateNLP.
the class NameBearerHandle method buildStaticPopupItems.
protected void buildStaticPopupItems() {
// build the static part of the popup
staticPopupItems = new ArrayList<JComponent>();
if (target instanceof ProcessingResource && !(target instanceof Controller)) {
// actions for PRs (but not Controllers)
staticPopupItems.add(null);
staticPopupItems.add(new XJMenuItem(new ReloadAction(), sListenerProxy));
staticPopupItems.add(new XJMenuItem(new ApplicationWithPRAction(), sListenerProxy));
} else if (target instanceof LanguageResource) {
// Language Resources
staticPopupItems.add(null);
if (target instanceof Document) {
staticPopupItems.add(new XJMenuItem(new CreateCorpusForDocAction(), sListenerProxy));
}
if (target instanceof gate.TextualDocument) {
staticPopupItems.add(null);
staticPopupItems.add(new DocumentExportMenu(this));
} else if (target instanceof Corpus) {
corpusFiller = new CorpusFillerComponent();
scfInputDialog = new SingleConcatenatedFileInputDialog();
staticPopupItems.add(new XJMenuItem(new PopulateCorpusAction(), sListenerProxy));
staticPopupItems.add(new XJMenuItem(new PopulateCorpusFromSingleConcatenatedFileAction(), sListenerProxy));
staticPopupItems.add(null);
staticPopupItems.add(new DocumentExportMenu(this));
}
if (((LanguageResource) target).getDataStore() != null) {
// this item can be used only if the resource belongs to a
// datastore
staticPopupItems.add(new XJMenuItem(new SaveAction(), sListenerProxy));
}
if (!(target instanceof AnnotationSchema)) {
staticPopupItems.add(new XJMenuItem(new SaveToAction(), sListenerProxy));
}
}
if (target instanceof Controller) {
// Applications
staticPopupItems.add(null);
if (target instanceof SerialAnalyserController) {
staticPopupItems.add(new XJMenuItem(new MakeConditionalAction(), sListenerProxy));
}
staticPopupItems.add(new XJMenuItem(new DumpToFileAction(), sListenerProxy));
staticPopupItems.add(new XJMenuItem(new ExportApplicationAction(), sListenerProxy));
}
}
use of gate.LanguageResource in project gate-core by GateNLP.
the class SerialDataStore method adopt.
// delete(lr)
/**
* Adopt a resource for persistence.
*/
@Override
public LanguageResource adopt(LanguageResource lr) throws PersistenceException {
// ignore security info
// check the LR's current DS
DataStore currentDS = lr.getDataStore();
if (currentDS == null) {
// an orphan - do the adoption
LanguageResource res = lr;
if (lr instanceof Corpus) {
FeatureMap features1 = Factory.newFeatureMap();
features1.put("transientSource", lr);
try {
// here we create the persistent LR via Factory, so it's registered
// in GATE
res = (LanguageResource) Factory.createResource("gate.corpora.SerialCorpusImpl", features1);
// Here the transient corpus is not deleted from the CRI, because
// this might not always be the desired behaviour
// since we chose that it is for the GUI, this functionality is
// now move to the 'Save to' action code in NameBearerHandle
} catch (gate.creole.ResourceInstantiationException ex) {
throw new GateRuntimeException(ex.getMessage());
}
}
res.setDataStore(this);
// let the world know
fireResourceAdopted(new DatastoreEvent(this, DatastoreEvent.RESOURCE_ADOPTED, lr, null));
return res;
} else if (// adopted already here
currentDS.equals(this))
return lr;
else {
// someone else's child
throw new PersistenceException("Can't adopt a resource which is already in a different datastore");
}
}
Aggregations