Search in sources :

Example 1 with LanguageResource

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);
// 
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) VisualResource(gate.VisualResource) 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 2 with LanguageResource

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);
}
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 3 with LanguageResource

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);
}
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 4 with LanguageResource

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));
    }
}
Also used : LanguageResource(gate.LanguageResource) ProcessingResource(gate.ProcessingResource) Document(gate.Document) IndexedCorpus(gate.creole.ir.IndexedCorpus) Corpus(gate.Corpus) AnnotationSchema(gate.creole.AnnotationSchema) SerialAnalyserController(gate.creole.SerialAnalyserController) ConditionalSerialAnalyserController(gate.creole.ConditionalSerialAnalyserController) JComponent(javax.swing.JComponent) SerialAnalyserController(gate.creole.SerialAnalyserController) Controller(gate.Controller) ConditionalSerialAnalyserController(gate.creole.ConditionalSerialAnalyserController) CorpusController(gate.CorpusController) ConditionalController(gate.creole.ConditionalController) XJMenuItem(gate.swing.XJMenuItem)

Example 5 with LanguageResource

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");
    }
}
Also used : FeatureMap(gate.FeatureMap) LanguageResource(gate.LanguageResource) DataStore(gate.DataStore) GateRuntimeException(gate.util.GateRuntimeException) DatastoreEvent(gate.event.DatastoreEvent) Corpus(gate.Corpus)

Aggregations

LanguageResource (gate.LanguageResource)13 Document (gate.Document)5 Corpus (gate.Corpus)4 FeatureMap (gate.FeatureMap)4 ProcessingResource (gate.ProcessingResource)4 Resource (gate.Resource)4 Controller (gate.Controller)3 ConditionalSerialAnalyserController (gate.creole.ConditionalSerialAnalyserController)3 File (java.io.File)3 CorpusController (gate.CorpusController)2 VisualResource (gate.VisualResource)2 AnnotationSchema (gate.creole.AnnotationSchema)2 PackagedController (gate.creole.PackagedController)2 GateRuntimeException (gate.util.GateRuntimeException)2 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)2 DataStore (gate.DataStore)1 TestDocument (gate.corpora.TestDocument)1 AbstractVisualResource (gate.creole.AbstractVisualResource)1 ConditionalController (gate.creole.ConditionalController)1 ResourceInstantiationException (gate.creole.ResourceInstantiationException)1