use of net.sourceforge.processdash.data.SaveableData in project processdash by dtuma.
the class ResultSet method get.
/** Perform a query and return a result set, using the old-style
mechanism. */
public static ResultSet get(DataRepository data, String[] conditions, String orderBy, String[] dataNames, String basePrefix, Comparator nodeComparator) {
// Construct a regular expression for searching the repository.
StringBuffer re = new StringBuffer("~(.*/)?");
if (conditions != null)
for (int c = 0; c < conditions.length; c++) re.append("{").append(conditions[c]).append("}");
if (orderBy == null)
orderBy = dataNames[0];
re.append(orderBy);
// Find data elements that match the regular expression.
if (basePrefix == null)
basePrefix = "";
SortedList list = SortedList.getInstance(data, re.toString(), basePrefix, FAKE_DATA_NAME, nodeComparator);
String[] prefixes = list.getNames();
// Create a result set to return
ResultSet result = new ResultSet(prefixes.length, dataNames.length);
// write the column headers into the result set.
result.setColName(0, null);
for (int i = 0; i < dataNames.length; i++) result.setColName(i + 1, dataNames[i]);
// get the data and fill the result set.
String prefix, dataName;
int baseLen = basePrefix.length(), tailLen = orderBy.length() + 1;
// remove / as well
if (baseLen > 0)
baseLen++;
String[] fixedUpNames = new String[dataNames.length];
for (int i = dataNames.length; i > 0; ) if (dataNames[--i].charAt(0) == '!')
fixedUpNames[i] = fixupName(dataNames[i]);
SaveableData value;
for (int p = 0; p < prefixes.length; p++) {
// get the next prefix
prefix = prefixes[p];
// remove the name of the orderBy data element, & the preceeding /
prefix = prefix.substring(0, prefix.length() - tailLen);
if (baseLen > prefix.length())
result.setRowName(p + 1, "");
else
result.setRowName(p + 1, prefix.substring(baseLen));
// look up the data for this row.
for (int d = 0; d < dataNames.length; d++) if (dataNames[d].startsWith("![(")) {
dataName = DataRepository.anonymousPrefix + "/" + prefix + "/" + fixedUpNames[d];
value = data.getSimpleValue(dataName);
if (value == null)
try {
value = ValueFactory.create(dataName, dataNames[d], data, prefix);
data.putValue(dataName, value);
} catch (MalformedValueException mve) {
}
result.setData(p + 1, d + 1, value == null ? null : value.getSimpleValue());
} else if (dataNames[d].startsWith("\"")) {
try {
result.setData(p + 1, d + 1, new StringData(dataNames[d]));
} catch (MalformedValueException mve) {
result.setData(p + 1, d + 1, null);
}
} else {
dataName = DataRepository.createDataName(prefix, dataNames[d]);
result.setData(p + 1, d + 1, data.getSimpleValue(dataName));
}
}
return result;
}
use of net.sourceforge.processdash.data.SaveableData in project processdash by dtuma.
the class InheritedValue method get.
/**
* Look for a hierarchically inherited value in the given DataContext.
*
* This method first constructs a data name by appending the given prefix
* and name. Then it checks to see if the data context has a non-null value
* for that name. If so, an InheritableValue object is returned containing
* the value found. Otherwise, this method chops the final name segment off
* of the prefix and tries again. It walks up the path hierarchy in this
* manner and returns the first match found. Even if no match can be found,
* an InheritableValue object is still returned; its getValue method will
* return null.
*
* Note that the search algorithm above is looking for non-null
* {@link SaveableValue} objects. If the value found is a calculation, that
* calculation might still evaluate to null.
*
* @param data
* the data context
* @param prefix
* the prefix to start the search
* @param name
* the name of a data element to look up
* @return return an {@link InheritedValue} object capturing the inherited
* value that was or was not found
*/
public static InheritedValue get(DataContext data, String prefix, String name) {
String dataName = prefix + "/" + name;
SaveableData result = data.getValue(dataName);
int pos;
while (result == null && prefix.length() > 0) {
pos = prefix.lastIndexOf('/');
if (pos == -1)
prefix = "";
else
prefix = prefix.substring(0, pos);
dataName = prefix + "/" + name;
result = data.getValue(dataName);
}
return new InheritedValue(prefix, name, result);
}
use of net.sourceforge.processdash.data.SaveableData in project processdash by dtuma.
the class AddTaskDialog method identifyTargetLocationAndHandler.
private String identifyTargetLocationAndHandler() {
activeTask = previousSibling = dash.getCurrentPhase();
targetParent = activeTask.getParent();
StringBuffer path = new StringBuffer(activeTask.path());
while (true) {
SaveableData sd = dash.getData().getInheritableValue(path, EXT_DATA_NAME);
String handler = (sd == null ? null : sd.getSimpleValue().format());
if (!"none".equals(handler))
return handler;
previousSibling = dash.getHierarchy().findExistingKey(path.toString());
targetParent = previousSibling.getParent();
path.setLength(targetParent.path().length());
}
}
use of net.sourceforge.processdash.data.SaveableData in project processdash by dtuma.
the class DependencyIndicator method shouldBeVisible.
private boolean shouldBeVisible(String path) {
if (path == null)
return false;
SaveableData enabledVal = context.getData().getInheritableValue(path, ENABLED_DATA_NAME);
if (enabledVal == null)
return Settings.getBool(ENABLED_SETTING_NAME, true);
SimpleData enabled = enabledVal.getSimpleValue();
return (enabled != null && enabled.test());
}
use of net.sourceforge.processdash.data.SaveableData in project processdash by dtuma.
the class EVReportSettings method lookupGroupFilter.
private void lookupGroupFilter() {
SaveableData sval = data.getInheritableValue(prefix, UserGroupManagerDash.FILTER_DATANAME);
SimpleData val = (sval == null ? null : sval.getSimpleValue());
parameters.put(GROUP_FILTER_PARAM, val == null ? "" : val.format());
}
Aggregations