/** * React to a change in an attribute. * * @param attribute The changed parameter. * @exception IllegalActionException If the parameter set is not valid. */ public void attributeChanged(Attribute attribute) throws IllegalActionException { String tmp = null; if (attribute == serverName) { // -------------- the user has changed serverName ----------- String strServerName = serverName.getExpression(); if (_serverNameString == null) { // the value is loaded from the moml file // don't cal the _createSubmission _serverNameString = strServerName; log.info("_serverNameString is set according to original value of moml file."); if (!strServerName.equals("")) { _appMetadata = AppMetadataParser.parseAppMetadata(strServerName); if (_appMetadata == null) { // something bad happen while getting the appMetadata log.error("Failed to parse metadata at " + strServerName); throw new IllegalActionException( this, "The selected URL does not point to a valid Opal service"); } } } else if (!strServerName.equals(_serverNameString)) { // the user changed the value, we have to update the actor log.info("Got a new server name: " + strServerName); _appMetadata = AppMetadataParser.parseAppMetadata(strServerName); if (_appMetadata != null) { if (_appMetadata.isArgMetadataEnable()) // complex submission form _createSubmission(_appMetadata); else // simple submission form _createSimpleSubmission(_appMetadata); _addDocumentation(_appMetadata); } else { // something bad happen while getting the appMetadata log.error("Failed to parse metadata at " + strServerName); throw new IllegalActionException( this, "The selected URL does not point to a valid Opal service"); } _serverNameString = strServerName; this.propagateValues(); } } else if (attribute == numberFiles) { // -------------- the user has changed the number of files ----------- int numFiles = 1; try { numFiles = Integer.parseInt(numberFiles.stringValue()); } catch (NumberFormatException e) { throw new IllegalActionException( this, "The numberFiles parameter is not a valid integer, please correct the value"); } if (numFiles != _numberFiles) { _updateUploadFileNumber(numFiles); _numberFiles = numFiles; } } else { log.debug("the user has changed: " + attribute.toString()); } super.attributeChanged(attribute); } // attributeChanged
private void populateDataBasedFunctions( final Map<String, Serializable> data, IFunction function) { if (function instanceof CompositeFunction) { CompositeFunction compositeFunction = (CompositeFunction) function; for (IFunction func : compositeFunction.getFunctions()) { populateDataBasedFunctions(data, func); } } if (function instanceof IDataBasedFunction) { IDataBasedFunction dbFunction = (IDataBasedFunction) function; String sdName = seedDataName.getExpression(); String sdAxis = seedAxisName.getExpression(); Dataset seedDataset = DatasetFactory.createFromObject(data.get(sdName)).clone(); Dataset seedAxisDataset = DatasetFactory.createFromObject(data.get(sdAxis)).clone(); dbFunction.setData(seedAxisDataset, seedDataset); } }
@Override protected DataMessageComponent getTransformedMessage(List<DataMessageComponent> cache) throws DataMessageException { // get the data out of the message, name of the item should be specified final Map<String, Serializable> data = MessageUtils.getList(cache); Map<String, AFunction> functions; try { functions = MessageUtils.getFunctions(cache); } catch (Exception e) { throw new DataMessageException( "Could not parse the Funcitons comming into the FunctionToDatsetActor", null, e); } // prepare the output message DataMessageComponent result = MessageUtils.copy(cache); // get the required datasets String dataset = datasetName.getExpression(); String xAxis = xAxisName.getExpression(); String functionString = functionName.getExpression(); // Get the actual objects Dataset xAxisDS = DatasetFactory.createFromObject(data.get(xAxis)).clone(); AFunction function = functions.get(functionString); populateDataBasedFunctions(data, function); // process the data // TODO Add Null Protection here. DoubleDataset createdDS = function.calculateValues(xAxisDS); createdDS.setName(dataset); // Add it to the result result.addList(createdDS.getName(), createdDS); return result; }
/** This function returns the number of CPU selected by the user */ private int _getCpuNumber() throws IllegalActionException { StringParameter cpuNumber = null; int value = 0; try { cpuNumber = (StringParameter) this.getAttribute("cpuNumber", StringParameter.class); } catch (IllegalActionException e) { throw new IllegalActionException( this, "Unable to find the command line parameter: " + e.getMessage()); } if (cpuNumber == null) { return 0; } if (cpuNumber.getExpression().length() == 0) { return 0; } try { value = Integer.valueOf(cpuNumber.getExpression()); } catch (Exception e) { throw new IllegalActionException(this, "The number of CPU must be an integer!"); } log.debug("Invoking Opal with " + cpuNumber.getExpression() + " CPUs"); return value; }
/** * Create a top-level viewer for the specified object with the specified parent window. * * @param object The object to configure, which is required to contain a parameter with name * matching <i>parameterName</i> and value that is an array of records. * @param parent The parent window, which is required to be an instance of TableauFrame. */ @Override public void createEditor(NamedObj object, Frame parent) { try { Parameter attributeToEdit = (Parameter) object.getAttribute(parameterName.getExpression(), Parameter.class); if (attributeToEdit == null) { MessageHandler.error("No such parameter: " + parameterName.getExpression()); return; } Token value = attributeToEdit.getToken(); if (!(value instanceof ArrayToken)) { MessageHandler.error( "Parameter does not contain an array token: " + attributeToEdit.toString()); return; } ArrayOfRecordsPane pane = new ArrayOfRecordsPane(); pane.display((ArrayToken) value, (ArrayToken) columns.getToken()); new ComponentDialog(parent, object.getFullName(), pane); } catch (KernelException ex) { MessageHandler.error("Cannot get specified string attribute to edit.", ex); return; } }
/** * Create a new background figure. This overrides the base class to draw a box around the value * display, where the width of the box depends on the value. * * @return A new figure. */ public Figure createBackgroundFigure() { NamedObj container = getContainer(); CompositeFigure result = new CompositeFigure(); if (container != null) { try { ArrayToken fieldsValue = (ArrayToken) fields.getToken(); Attribute associatedAttribute = container.getAttribute(variableName.getExpression()); if (associatedAttribute instanceof Variable) { Token value = ((Variable) associatedAttribute).getToken(); if (value instanceof ArrayToken) { // Find the number of rows and columns. int numRows = ((ArrayToken) value).length(); int numColumns = fieldsValue.length(); if (numColumns == 0) { // All columns should be included. // Make a pass to figure out how many that is. for (int i = 0; i < numRows; i++) { Token row = ((ArrayToken) value).getElement(i); if (row instanceof RecordToken) { int rowWidth = ((RecordToken) row).labelSet().size(); if (rowWidth > numColumns) { numColumns = rowWidth; } } } } // Find the width of each column and the height of each row. // All rows are the same height, but column widths can vary. double rowHeight = 0.0; double columnWidth[] = new double[numColumns]; for (int i = 1; i < numColumns; i++) { columnWidth[i] = 0.0; } LabelFigure tableElement[][] = new LabelFigure[numRows][numColumns]; // Iterate over rows. for (int i = 0; i < numRows; i++) { Token row = ((ArrayToken) value).getElement(i); if (row instanceof RecordToken) { if (fieldsValue.length() == 0) { // Display all fields. Iterator labelSet = ((RecordToken) row).labelSet().iterator(); int j = 0; while (labelSet.hasNext()) { String column = (String) labelSet.next(); tableElement[i][j] = _labelFigure((RecordToken) row, column); Rectangle2D bounds = tableElement[i][j].getBounds(); double width = bounds.getWidth(); if (width > columnWidth[j]) { columnWidth[j] = width; } double height = bounds.getHeight(); if (height > rowHeight) { rowHeight = height; } j++; } } else { // Display specified fields. for (int j = 0; j < fieldsValue.length(); j++) { if (j >= numColumns) { break; } String column = ((StringToken) fieldsValue.getElement(j)).stringValue(); tableElement[i][j] = _labelFigure((RecordToken) row, column); Rectangle2D bounds = tableElement[i][j].getBounds(); double width = bounds.getWidth(); if (width > columnWidth[j]) { columnWidth[j] = width; } double height = bounds.getHeight(); if (height > rowHeight) { rowHeight = height; } } } } } // Now make a pass to position and add all the figures. double rowPosition = _VERTICAL_PADDING; // Iterate over rows. for (int i = 0; i < numRows; i++) { Token row = ((ArrayToken) value).getElement(i); if (row instanceof RecordToken) { if (fieldsValue.length() == 0) { // Display all fields. Iterator labelSet = ((RecordToken) row).labelSet().iterator(); int j = 0; double columnPosition = _HORIZONTAL_PADDING; while (labelSet.hasNext()) { /*String column = (String) */ labelSet.next(); tableElement[i][j].translateTo(columnPosition, rowPosition); result.add(tableElement[i][j]); columnPosition += columnWidth[j] + _HORIZONTAL_PADDING; j++; } } else { // Display specified fields. double columnPosition = _HORIZONTAL_PADDING; for (int j = 0; j < fieldsValue.length(); j++) { // String column = ((StringToken)fieldsValue.getElement(j)).stringValue(); tableElement[i][j].translateTo(columnPosition, rowPosition); result.add(tableElement[i][j]); columnPosition += columnWidth[j] + _HORIZONTAL_PADDING; } } } rowPosition += rowHeight + _VERTICAL_PADDING; } } } } catch (IllegalActionException e) { // Stick the error message in the icon. result.add(new LabelFigure(e.getMessage())); } } // Now put a box around it all. Rectangle2D bounds = result.getBounds(); // Double the padding below to allow for both sides. double width = Math.floor(bounds.getWidth()) + _HORIZONTAL_PADDING * 2; double height = Math.floor(bounds.getHeight()) + _VERTICAL_PADDING * 2; Figure rectangle = new BasicRectangle(0, 0, width, height, boxColor.asColor(), 1); CompositeFigure finalResult = new CompositeFigure(rectangle); finalResult.add(result); return finalResult; }
/** this function build the command line reading the parameters selected by the user */ private String _makeCmd() throws IllegalActionException { String str = ""; if (_appMetadata.isArgMetadataEnable()) { // complex submission form if (_appMetadata.getArgFlags() != null) { // let's do the falgs ArgFlag[] flags = _appMetadata.getArgFlags(); for (int i = 0; i < flags.length; i++) { Parameter flagTemp = null; if ((flagTemp = (Parameter) this.getAttribute(flags[i].getId())) == null) throw new IllegalActionException( this, "Unable to find the command line parameter (flag): " + flags[i].getId()); if (((BooleanToken) flagTemp.getToken()).booleanValue()) str += " " + flags[i].getTag(); } // for } if (_appMetadata.getArgParams() != null) { // and then the params ArgParam[] params = _appMetadata.getArgParams(); String taggedParams = ""; String separator = _appMetadata.getSeparator(); if (separator == null) { separator = " "; } String[] untaggedParams = new String[_appMetadata.getNumUnttagedParams()]; // we make an array to contain // the untagged params for (int i = 0; i < untaggedParams.length; i++) // we initialized it to empty untaggedParams[i] = ""; log.info("We have " + _appMetadata.getNumUnttagedParams() + " untaggged parameters."); for (int i = 0; i < params.length; i++) { log.info("Analizing param: " + params[i].getId()); Attribute attr = this.getAttribute(params[i].getId()); if (attr == null) throw new IllegalActionException( this, "We could not find the attribute " + params[i].getId()); if (params[i].getTag() != null) { // tagged params if (attr instanceof FilePortParameter) { if (((FilePortParameter) attr).asFile() != null) // we have a file! taggedParams += " " + params[i].getTag() + separator + ((FilePortParameter) attr).asFile().getName(); } else if ((((StringParameter) attr).stringValue() != null) && (((StringParameter) attr).stringValue().length() > 0)) // basically the user // has entered some text taggedParams += " " + params[i].getTag() + separator + ((StringParameter) attr).stringValue(); } else { // untagged parameters if (attr instanceof FilePortParameter) { if (((FilePortParameter) attr).asFile() != null) // we have a file untaggedParams[params[i].getPosition()] = " " + ((FilePortParameter) attr).asFile().getName(); } else if ((((StringParameter) attr).stringValue() != null) && (((StringParameter) attr).stringValue().length() > 0)) { // basically the user // has entered some // text // untagged params this is a bit unreadable!! untaggedParams[params[i].getPosition()] = " " + ((StringParameter) attr).stringValue(); log.info( "Adding the " + i + " untagged paramters with: " + untaggedParams[params[i].getPosition()]); } // if } // else } // for if (taggedParams.length() > 0) str += taggedParams; for (int i = 0; i < _appMetadata.getNumUnttagedParams(); i++) str += untaggedParams[i]; } log.info("The command line is: " + str); return str; } else { // simple case StringParameter commandLine = null; try { commandLine = (StringParameter) this.getAttribute("commandLine", StringParameter.class); log.debug( "passing by here with commandLine = " + commandLine + " for server name: " + _serverNameString); } catch (IllegalActionException e) { throw new IllegalActionException( this, "Unable to find the command line parameter: " + e.getMessage()); } return commandLine.getExpression(); } } // _makeCmd