Search in sources :

Example 16 with ResourceData

use of gate.creole.ResourceData in project gate-core by GateNLP.

the class AnnotationSetsView method createAnnotationEditor.

/**
 * Create the annotation editor (responsible for creating the window
 * used to edit individual annotations).
 * @throws ResourceInstantiationException if an error occurs
 */
protected gate.gui.annedit.OwnedAnnotationEditor createAnnotationEditor(TextualDocumentView textView, AnnotationSetsView asView) throws ResourceInstantiationException {
    // find the last VR that implements the AnnotationEditor interface
    List<String> vrTypes = new ArrayList<String>(Gate.getCreoleRegister().getPublicVrTypes());
    Collections.reverse(vrTypes);
    for (String aVrType : vrTypes) {
        ResourceData rData = Gate.getCreoleRegister().get(aVrType);
        try {
            Class<? extends Resource> resClass = rData.getResourceClass();
            if (OwnedAnnotationEditor.class.isAssignableFrom(resClass)) {
                OwnedAnnotationEditor newEditor = (OwnedAnnotationEditor) resClass.newInstance();
                newEditor.setOwner(this);
                newEditor.init();
                if (currentOrientation != null) {
                    newEditor.changeOrientation(currentOrientation);
                }
                return newEditor;
            }
        } catch (ClassNotFoundException cnfe) {
            // ignore
            Err.prln("Invalid CREOLE data:");
            cnfe.printStackTrace(Err.getPrintWriter());
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
    }
    // if we got this far, we couldn't find an editor
    Err.prln("Could not find any annotation editors. Editing annotations disabled.");
    return null;
}
Also used : ResourceData(gate.creole.ResourceData) ArrayList(java.util.ArrayList) OwnedAnnotationEditor(gate.gui.annedit.OwnedAnnotationEditor) ResourceInstantiationException(gate.creole.ResourceInstantiationException)

Example 17 with ResourceData

use of gate.creole.ResourceData in project gate-core by GateNLP.

the class NameBearerHandle method buildViews.

protected void buildViews() {
    viewsBuilt = true;
    fireStatusChanged("Building views...");
    // build the large views
    List<String> largeViewNames = Gate.getCreoleRegister().getLargeVRsForResource(target.getClass().getName());
    if (largeViewNames != null && !largeViewNames.isEmpty()) {
        largeView = new JTabbedPane(JTabbedPane.BOTTOM);
        Iterator<String> classNameIter = largeViewNames.iterator();
        while (classNameIter.hasNext()) {
            try {
                String className = classNameIter.next();
                ResourceData rData = Gate.getCreoleRegister().get(className);
                FeatureMap params = Factory.newFeatureMap();
                FeatureMap features = Factory.newFeatureMap();
                Gate.setHiddenAttribute(features, true);
                VisualResource view = (VisualResource) Factory.createResource(className, params, features);
                try {
                    view.setTarget(target);
                } catch (IllegalArgumentException iae) {
                    // the view cannot display this particular target
                    Factory.deleteResource(view);
                    view = null;
                }
                if (view != null) {
                    view.setHandle(this);
                    ((JTabbedPane) largeView).add((Component) view, rData.getName());
                    // publishers
                    if (view instanceof ActionsPublisher)
                        actionPublishers.add((ActionsPublisher) view);
                }
            } catch (ResourceInstantiationException rie) {
                rie.printStackTrace(Err.getPrintWriter());
            }
        }
        // select the first view by default
        ((JTabbedPane) largeView).setSelectedIndex(0);
    }
    // build the small views
    List<String> smallViewNames = Gate.getCreoleRegister().getSmallVRsForResource(target.getClass().getName());
    if (smallViewNames != null && !smallViewNames.isEmpty()) {
        smallView = new JTabbedPane(JTabbedPane.BOTTOM);
        Iterator<String> classNameIter = smallViewNames.iterator();
        while (classNameIter.hasNext()) {
            try {
                String className = classNameIter.next();
                ResourceData rData = Gate.getCreoleRegister().get(className);
                FeatureMap params = Factory.newFeatureMap();
                FeatureMap features = Factory.newFeatureMap();
                Gate.setHiddenAttribute(features, true);
                VisualResource view = (VisualResource) Factory.createResource(className, params, features);
                try {
                    view.setTarget(target);
                } catch (IllegalArgumentException iae) {
                    // the view cannot display this particular target
                    Factory.deleteResource(view);
                    view = null;
                }
                if (view != null) {
                    view.setHandle(this);
                    ((JTabbedPane) smallView).add((Component) view, rData.getName());
                    if (view instanceof ActionsPublisher)
                        actionPublishers.add((ActionsPublisher) view);
                }
            } catch (ResourceInstantiationException rie) {
                rie.printStackTrace(Err.getPrintWriter());
            }
        }
        ((JTabbedPane) smallView).setSelectedIndex(0);
    }
    fireStatusChanged("Views built!");
    // Add the CTRL +F4 key & action combination to the resource
    JComponent largeView = this.getLargeView();
    if (largeView != null) {
        largeView.getActionMap().put("Close resource", new CloseAction());
        if (target instanceof Controller) {
            largeView.getActionMap().put("Close recursively", new CloseRecursivelyAction());
        }
    /*if(target instanceof gate.TextualDocument) {
        largeView.getActionMap().put("Save As XML", new SaveAsXmlAction());
      }// End if*/
    }
// End if
}
Also used : ResourceData(gate.creole.ResourceData) VisualResource(gate.VisualResource) JTabbedPane(javax.swing.JTabbedPane) JComponent(javax.swing.JComponent) SerialAnalyserController(gate.creole.SerialAnalyserController) Controller(gate.Controller) ConditionalSerialAnalyserController(gate.creole.ConditionalSerialAnalyserController) CorpusController(gate.CorpusController) ConditionalController(gate.creole.ConditionalController) ResourceInstantiationException(gate.creole.ResourceInstantiationException) FeatureMap(gate.FeatureMap)

Example 18 with ResourceData

use of gate.creole.ResourceData in project gate-core by GateNLP.

the class PRPersistence method extractDataFromSource.

/**
 * Populates this Persistence with the data that needs to be stored from the
 * original source object.
 */
@Override
public void extractDataFromSource(Object source) throws PersistenceException {
    if (!(source instanceof ProcessingResource)) {
        throw new UnsupportedOperationException(getClass().getName() + " can only be used for " + ProcessingResource.class.getName() + " objects!\n" + source.getClass().getName() + " is not a " + ProcessingResource.class.getName());
    }
    super.extractDataFromSource(source);
    Resource res = (Resource) source;
    ResourceData rData = Gate.getCreoleRegister().get(res.getClass().getName());
    if (rData == null)
        throw new PersistenceException("Could not find CREOLE data for " + res.getClass().getName());
    // now get the runtime params
    ParameterList params = rData.getParameterList();
    try {
        // get the values for the init time parameters
        runtimeParams = Factory.newFeatureMap();
        // this is a list of lists
        Iterator<List<Parameter>> parDisjIter = params.getRuntimeParameters().iterator();
        while (parDisjIter.hasNext()) {
            Iterator<Parameter> parIter = parDisjIter.next().iterator();
            while (parIter.hasNext()) {
                Parameter parameter = parIter.next();
                String parName = parameter.getName();
                Object parValue = res.getParameterValue(parName);
                if (storeParameterValue(parValue, parameter.getDefaultValue())) {
                    ((FeatureMap) runtimeParams).put(parName, parValue);
                }
            }
        }
        runtimeParams = PersistenceManager.getPersistentRepresentation(runtimeParams);
    } catch (ResourceInstantiationException | ParameterException rie) {
        throw new PersistenceException(rie);
    }
}
Also used : ResourceData(gate.creole.ResourceData) ProcessingResource(gate.ProcessingResource) Resource(gate.Resource) ProcessingResource(gate.ProcessingResource) ResourceInstantiationException(gate.creole.ResourceInstantiationException) FeatureMap(gate.FeatureMap) PersistenceException(gate.persist.PersistenceException) ParameterList(gate.creole.ParameterList) Parameter(gate.creole.Parameter) ParameterList(gate.creole.ParameterList) List(java.util.List) ParameterException(gate.creole.ParameterException)

Aggregations

ResourceData (gate.creole.ResourceData)18 ResourceInstantiationException (gate.creole.ResourceInstantiationException)9 Parameter (gate.creole.Parameter)6 List (java.util.List)6 ParameterException (gate.creole.ParameterException)5 FeatureMap (gate.FeatureMap)4 ProcessingResource (gate.ProcessingResource)4 PersistenceException (gate.persist.PersistenceException)4 Resource (gate.Resource)3 ParameterList (gate.creole.ParameterList)3 GateRuntimeException (gate.util.GateRuntimeException)3 ArrayList (java.util.ArrayList)3 Corpus (gate.Corpus)2 Document (gate.Document)2 AbstractProcessingResource (gate.creole.AbstractProcessingResource)2 AbstractResource (gate.creole.AbstractResource)2 ConditionalController (gate.creole.ConditionalController)2 Plugin (gate.creole.Plugin)2 CreoleEvent (gate.event.CreoleEvent)2 ActionEvent (java.awt.event.ActionEvent)2