Search in sources :

Example 16 with ResourceInstantiationException

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

the class FeaturesSchemaEditor method setParameterValue.

/**
 * Sets the value for a specified parameter.
 *
 * @param paramaterName the name for the parameteer
 * @param parameterValue the value the parameter will receive
 */
@Override
public void setParameterValue(String paramaterName, Object parameterValue) throws ResourceInstantiationException {
    // get the beaninfo for the resource bean, excluding data about Object
    BeanInfo resBeanInf = null;
    try {
        resBeanInf = Introspector.getBeanInfo(this.getClass(), Object.class);
    } catch (Exception e) {
        throw new ResourceInstantiationException("Couldn't get bean info for resource " + this.getClass().getName() + Strings.getNl() + "Introspector exception was: " + e);
    }
    AbstractResource.setParameterValue(this, resBeanInf, paramaterName, parameterValue);
}
Also used : BeanInfo(java.beans.BeanInfo) GateRuntimeException(gate.util.GateRuntimeException) ResourceInstantiationException(gate.creole.ResourceInstantiationException) ResourceInstantiationException(gate.creole.ResourceInstantiationException)

Example 17 with ResourceInstantiationException

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

the class AnnotationEditor method initGUI.

protected void initGUI() {
    popupWindow = new JWindow(SwingUtilities.getWindowAncestor(owner.getTextComponent())) {

        @Override
        public void pack() {
            // than the main frame
            if (isVisible()) {
                int maxHeight = MainFrame.getInstance().getHeight();
                int otherHeight = getHeight() - featuresScroller.getHeight();
                maxHeight -= otherHeight;
                if (featuresScroller.getPreferredSize().height > maxHeight) {
                    featuresScroller.setMaximumSize(new Dimension(featuresScroller.getMaximumSize().width, maxHeight));
                    featuresScroller.setPreferredSize(new Dimension(featuresScroller.getPreferredSize().width, maxHeight));
                }
            }
            super.pack();
        }

        @Override
        public void setVisible(boolean b) {
            super.setVisible(b);
            // when the editor is shown put the focus in the type combo box
            if (b) {
                typeCombo.requestFocus();
            }
        }
    };
    JPanel pane = new JPanel();
    pane.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1));
    pane.setLayout(new GridBagLayout());
    pane.setBackground(UIManager.getLookAndFeelDefaults().getColor("ToolTip.background"));
    popupWindow.setContentPane(pane);
    Insets insets0 = new Insets(0, 0, 0, 0);
    GridBagConstraints constraints = new GridBagConstraints();
    constraints.fill = GridBagConstraints.NONE;
    constraints.anchor = GridBagConstraints.CENTER;
    constraints.gridwidth = 1;
    constraints.gridy = 0;
    constraints.gridx = GridBagConstraints.RELATIVE;
    constraints.weightx = 0;
    constraints.weighty = 0;
    constraints.insets = insets0;
    solButton = new JButton();
    solButton.setContentAreaFilled(false);
    solButton.setBorderPainted(false);
    solButton.setMargin(insets0);
    pane.add(solButton, constraints);
    sorButton = new JButton();
    sorButton.setContentAreaFilled(false);
    sorButton.setBorderPainted(false);
    sorButton.setMargin(insets0);
    pane.add(sorButton, constraints);
    delButton = new JButton();
    delButton.setContentAreaFilled(false);
    delButton.setBorderPainted(false);
    delButton.setMargin(insets0);
    constraints.insets = new Insets(0, 20, 0, 20);
    pane.add(delButton, constraints);
    constraints.insets = insets0;
    eolButton = new JButton();
    eolButton.setContentAreaFilled(false);
    eolButton.setBorderPainted(false);
    eolButton.setMargin(insets0);
    pane.add(eolButton, constraints);
    eorButton = new JButton();
    eorButton.setContentAreaFilled(false);
    eorButton.setBorderPainted(false);
    eorButton.setMargin(insets0);
    pane.add(eorButton, constraints);
    pinnedButton = new JToggleButton(MainFrame.getIcon("pin"));
    pinnedButton.setSelectedIcon(MainFrame.getIcon("pin-in"));
    pinnedButton.setSelected(false);
    pinnedButton.setBorderPainted(false);
    pinnedButton.setContentAreaFilled(false);
    constraints.weightx = 1;
    constraints.insets = new Insets(0, 0, 0, 0);
    constraints.anchor = GridBagConstraints.EAST;
    pane.add(pinnedButton, constraints);
    dismissButton = new JButton();
    dismissButton.setBorder(null);
    constraints.anchor = GridBagConstraints.NORTHEAST;
    pane.add(dismissButton, constraints);
    constraints.anchor = GridBagConstraints.CENTER;
    constraints.insets = insets0;
    typeCombo = new JComboBox<String>();
    typeCombo.setEditable(true);
    typeCombo.setBackground(UIManager.getLookAndFeelDefaults().getColor("ToolTip.background"));
    constraints.fill = GridBagConstraints.HORIZONTAL;
    constraints.gridy = 1;
    constraints.gridwidth = 7;
    constraints.weightx = 1;
    constraints.insets = new Insets(3, 2, 2, 2);
    pane.add(typeCombo, constraints);
    featuresEditor = new FeaturesSchemaEditor();
    featuresEditor.setBackground(UIManager.getLookAndFeelDefaults().getColor("ToolTip.background"));
    try {
        featuresEditor.init();
    } catch (ResourceInstantiationException rie) {
        throw new GateRuntimeException(rie);
    }
    constraints.gridy = 2;
    constraints.weighty = 1;
    constraints.fill = GridBagConstraints.BOTH;
    featuresScroller = new JScrollPane(featuresEditor);
    pane.add(featuresScroller, constraints);
    // add the search and annotate GUI at the bottom of the annotator editor
    SearchAndAnnotatePanel searchPanel = new SearchAndAnnotatePanel(pane.getBackground(), this, popupWindow);
    constraints.insets = new Insets(0, 0, 0, 0);
    constraints.fill = GridBagConstraints.BOTH;
    constraints.anchor = GridBagConstraints.WEST;
    constraints.gridx = 0;
    constraints.gridy = GridBagConstraints.RELATIVE;
    constraints.gridwidth = GridBagConstraints.REMAINDER;
    constraints.gridheight = GridBagConstraints.REMAINDER;
    constraints.weightx = 0.0;
    constraints.weighty = 0.0;
    pane.add(searchPanel, constraints);
    popupWindow.pack();
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) GridBagLayout(java.awt.GridBagLayout) JWindow(javax.swing.JWindow) JButton(javax.swing.JButton) FeaturesSchemaEditor(gate.gui.FeaturesSchemaEditor) Dimension(java.awt.Dimension) ResourceInstantiationException(gate.creole.ResourceInstantiationException) JToggleButton(javax.swing.JToggleButton) GateRuntimeException(gate.util.GateRuntimeException) SearchAndAnnotatePanel(gate.gui.annedit.SearchAndAnnotatePanel)

Example 18 with ResourceInstantiationException

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

the class SerialDatastoreViewer method setParameterValue.

/**
 * Sets the value for a specified parameter.
 *
 * @param paramaterName the name for the parameteer
 * @param parameterValue the value the parameter will receive
 */
@Override
public void setParameterValue(String paramaterName, Object parameterValue) throws ResourceInstantiationException {
    // get the beaninfo for the resource bean, excluding data about
    // Object
    BeanInfo resBeanInf = null;
    try {
        resBeanInf = Introspector.getBeanInfo(this.getClass(), Object.class);
    } catch (Exception e) {
        throw new ResourceInstantiationException("Couldn't get bean info for resource " + this.getClass().getName() + Strings.getNl() + "Introspector exception was: " + e);
    }
    AbstractResource.setParameterValue(this, resBeanInf, paramaterName, parameterValue);
}
Also used : BeanInfo(java.beans.BeanInfo) GateRuntimeException(gate.util.GateRuntimeException) ResourceInstantiationException(gate.creole.ResourceInstantiationException) PersistenceException(gate.persist.PersistenceException) ResourceInstantiationException(gate.creole.ResourceInstantiationException)

Example 19 with ResourceInstantiationException

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

the class SerialControllerEditor method selectPR.

/**
 * Called when a PR has been selected in the member PRs table;
 * @param index row index in {@link #memberPRsTable} (or -1 if no PR is
 * currently selected)
 */
protected void selectPR(int index) {
    // stop current editing of parameters
    if (parametersEditor.getResource() != null) {
        try {
            parametersEditor.setParameters();
        } catch (ResourceInstantiationException rie) {
            JOptionPane.showMessageDialog(SerialControllerEditor.this, "Failed to set parameters for \"" + parametersEditor.getResource().getName() + "\"!\n", "GATE", JOptionPane.ERROR_MESSAGE);
            rie.printStackTrace(Err.getPrintWriter());
        }
        if (conditionalMode) {
            if (selectedPRRunStrategy != null && selectedPRRunStrategy instanceof AnalyserRunningStrategy) {
                AnalyserRunningStrategy strategy = (AnalyserRunningStrategy) selectedPRRunStrategy;
                strategy.setFeatureName(featureNameTextField.getText());
                strategy.setFeatureValue(featureValueTextField.getText());
            }
            selectedPRRunStrategy = null;
        }
    }
    // find the new PR
    ProcessingResource pr = null;
    if (index >= 0 && index < controller.getPRs().size()) {
        pr = controller.getPRs().get(index);
    }
    if (pr != null) {
        // update the GUI for the new PR
        ResourceData rData = Gate.getCreoleRegister().get(pr.getClass().getName());
        // update the border name
        parametersBorder.setTitle(" Runtime Parameters for the \"" + pr.getName() + "\" " + rData.getName() + ": ");
        // update the params editor
        // this is a list of lists
        List<List<Parameter>> parameters = rData.getParameterList().getRuntimeParameters();
        if (corpusControllerMode) {
            // remove corpus and document
            // create a new list so we don't change the one from CreoleReg.
            List<List<Parameter>> oldParameters = parameters;
            parameters = new ArrayList<List<Parameter>>();
            for (List<Parameter> aDisjunction : oldParameters) {
                List<Parameter> newDisjunction = new ArrayList<Parameter>();
                for (Parameter parameter : aDisjunction) {
                    if (!parameter.getName().equals("corpus") && !parameter.getName().equals("document")) {
                        newDisjunction.add(parameter);
                    }
                }
                if (!newDisjunction.isEmpty())
                    parameters.add(newDisjunction);
            }
        }
        parametersEditor.init(pr, parameters);
        if (conditionalMode) {
            strategyBorder.setTitle(" Run \"" + pr.getName() + "\"? ");
            // update the state of the run strategy buttons
            yes_RunRBtn.setEnabled(true);
            no_RunRBtn.setEnabled(true);
            conditional_RunRBtn.setEnabled(true);
            // editing the strategy panel causes the edits to be sent to the current
            // strategy object, which can lead to a race condition.
            // So we used a cached value instead.
            selectedPRRunStrategy = null;
            RunningStrategy newStrategy = ((ConditionalController) controller).getRunningStrategies().get(index);
            if (newStrategy instanceof AnalyserRunningStrategy) {
                featureNameTextField.setEnabled(true);
                featureValueTextField.setEnabled(true);
                conditional_RunRBtn.setEnabled(true);
                featureNameTextField.setText(((AnalyserRunningStrategy) newStrategy).getFeatureName());
                featureValueTextField.setText(((AnalyserRunningStrategy) newStrategy).getFeatureValue());
            } else {
                featureNameTextField.setEnabled(false);
                featureValueTextField.setEnabled(false);
                conditional_RunRBtn.setEnabled(false);
            }
            switch(newStrategy.getRunMode()) {
                case RunningStrategy.RUN_ALWAYS:
                    {
                        yes_RunRBtn.setSelected(true);
                        break;
                    }
                case RunningStrategy.RUN_NEVER:
                    {
                        no_RunRBtn.setSelected(true);
                        break;
                    }
                case RunningStrategy.RUN_CONDITIONAL:
                    {
                        conditional_RunRBtn.setSelected(true);
                        break;
                    }
            }
            // switch
            // now that the UI is updated, we can safely link to the new strategy
            selectedPRRunStrategy = newStrategy;
        }
    } else {
        // selected PR == null -> clean all mentions of the old PR from the GUI
        parametersBorder.setTitle(" No processing resource selected... ");
        parametersEditor.init(null, null);
        if (conditionalMode) {
            strategyBorder.setTitle(" No processing resource selected... ");
            yes_RunRBtn.setEnabled(false);
            no_RunRBtn.setEnabled(false);
            conditional_RunRBtn.setEnabled(false);
            featureNameTextField.setText("");
            featureNameTextField.setEnabled(false);
            featureValueTextField.setText("");
            featureValueTextField.setEnabled(false);
        }
    }
    // this seems to be needed to show the changes
    SerialControllerEditor.this.repaint(100);
}
Also used : ResourceData(gate.creole.ResourceData) RunningStrategy(gate.creole.RunningStrategy) AnalyserRunningStrategy(gate.creole.AnalyserRunningStrategy) UnconditionalRunningStrategy(gate.creole.RunningStrategy.UnconditionalRunningStrategy) ProcessingResource(gate.ProcessingResource) ArrayList(java.util.ArrayList) Parameter(gate.creole.Parameter) AnalyserRunningStrategy(gate.creole.AnalyserRunningStrategy) List(java.util.List) ArrayList(java.util.ArrayList) ResourceInstantiationException(gate.creole.ResourceInstantiationException)

Example 20 with ResourceInstantiationException

use of gate.creole.ResourceInstantiationException 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)

Aggregations

ResourceInstantiationException (gate.creole.ResourceInstantiationException)29 FeatureMap (gate.FeatureMap)10 PersistenceException (gate.persist.PersistenceException)10 ResourceData (gate.creole.ResourceData)9 GateRuntimeException (gate.util.GateRuntimeException)6 Document (gate.Document)5 File (java.io.File)5 ParameterException (gate.creole.ParameterException)4 SerialDataStore (gate.persist.SerialDataStore)4 IOException (java.io.IOException)4 List (java.util.List)4 ProcessingResource (gate.ProcessingResource)3 Resource (gate.Resource)3 ExecutionException (gate.creole.ExecutionException)3 Parameter (gate.creole.Parameter)3 ParameterList (gate.creole.ParameterList)3 Plugin (gate.creole.Plugin)3 Dimension (java.awt.Dimension)3 BeanInfo (java.beans.BeanInfo)3 URL (java.net.URL)3