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