public TableType generateDefaultTable(String gid) { final TableType table = new TableType(); table.setId(gid); table.setTitle(ILMLCoreConstants.TITLE_PREFIX + gid); final ContentType ct = ContentType.fromValue(ILguiItem.CONTENT_JOBS); table.setContenttype(ct); for (final ColumnlayoutType columnLayout : lguiItem.getLayoutAccess().getTableLayout(gid).getColumn()) { if (columnLayout.isActive()) { final ColumnType column = new ColumnType(); column.setId(columnLayout.getCid()); column.setName(columnLayout.getKey()); generateDefaultSorting(column); if (columnLayout.getKey().equals(ILguiItem.JOB_STATUS)) { column.setType(ITableColumnLayout.COLUMN_TYPE_MANDATORY); if (gid.equals(ILMLCoreConstants.ID_ACTIVE_JOBS_VIEW)) { generateDefaultPattern(JobStatusData.RUNNING, ILMLCoreConstants.EQ, columnLayout); } else { generateDefaultPattern(JobStatusData.RUNNING, ILMLCoreConstants.NEQ, columnLayout); } } table.getColumn().add(column); } } jaxbUtil.addTable(lgui, table); return table; }
/** @return */ private RowType[] getTableData(TableType table, BigInteger[] cids) { final RowType[] tableData = new RowType[table.getRow().size()]; for (int i = 0; i < tableData.length; i++) { final RowType row = table.getRow().get(i); tableData[i] = new RowType(); if (row.getOid() != null) { tableData[i].setOid(row.getOid()); } for (final BigInteger cid : cids) { boolean exists = false; for (final CellType cell : row.getCell()) { if (cell.getCid().equals(cid)) { tableData[i].getCell().add(cell); exists = true; break; } } if (!exists) { final CellType newCell = new CellType(); newCell.setCid(cid); newCell.setValue(ILMLCoreConstants.QM); tableData[i].getCell().add(newCell); } } } return tableData; }
/** Not currently used */ public String getTableTitle(String gid) { final TableType table = getTable(gid); if (table == null) { return ILMLCoreConstants.EMPTY; } return table.getTitle(); }
/** * Forwards new information for the jobs to the jobstatus instances, which are afterwards saved * via Memento within the monitor.core plug-in. This function stores all additional information * provided by lml_da in each jobStatusData instance. */ public void forwardRowToJobData() { final JobStatusData[] userJobs = lguiItem.getUserJobs(); final Set<String> userNames = new HashSet<String>(); for (final JobStatusData jobStatus : userJobs) { userNames.add(jobStatus.getString(JobStatusData.OWNER_ATTR)); } // Traverse all tables for (final TableType table : getTables()) { // Get extended rows with attached jobStatusData final Row[] rows = getTableDataWithColor( table.getId(), false); // Contains extended rows with additional data for (int i = 0; i < rows.length; i++) { if (rows[i].status == null) { // If there is no jobstatusdata, do not add additional data continue; } if (!userNames.contains(rows[i].status.getString(JobStatusData.OWNER_ATTR))) { continue; } final RowType rawRow = table.getRow().get(i); // The actual row from LML data // Iterate over all columns and save their key value pairs // into the jobstatus instances for (final ColumnType column : table.getColumn()) { final String columnName = column.getName(); final String value = getCellValue(table, rawRow, columnName); if (value != null) { rows[i].status.putString(columnName, value); } } } } }
/** * Getting an element(Table Type) which has an equal title to the argument tableType. * * @param gid ID of the desired table * @return Corresponding table to the desired table title */ public TableType getTable(String gid) { for (final TableType tag : getTables()) { if (tag.getId().equals(gid)) { return tag; } } return null; }
/** * Get the table with color information added * * @param gid ID of the table layout * @return rows with color information added */ public Row[] getTableDataWithColor(String gid, boolean addColor) { final BigInteger[] cids = getCids(gid); final TableType table = getTable(gid); if (table == null) { return new Row[0]; } final List<Row> tableData = new ArrayList<Row>(); for (int i = 0; i < table.getRow().size(); i++) { final RowType rowType = table.getRow().get(i); final Row row = new Row(); row.setOid(rowType.getOid()); if (addColor) { row.setColor(lguiItem.getOIDToObject().getColorById(rowType.getOid())); } final BigInteger jobIdIndex = getColumnIndex(table, ILguiItem.JOB_ID); final Cell[] tableDataRow = new Cell[cids.length]; String jobId = null; for (int j = 0; j < cids.length; j++) { for (final CellType cell : rowType.getCell()) { if (cell.getCid() != null && cell.getCid().equals(cids[j])) { tableDataRow[j] = new Cell(cell.getValue(), row); break; } } if (tableDataRow[j] == null) { tableDataRow[j] = new Cell(ILMLCoreConstants.QM, row); } if (cids[j].equals(jobIdIndex)) { jobId = tableDataRow[j].value; } } row.setCells(tableDataRow); if (jobId != null) { JobStatusData status = lguiItem.getUserJob(jobId); if (status == null) { final String queueName = getCellValue(table, rowType, ILguiItem.JOB_QUEUE_NAME); final String owner = getCellValue(table, rowType, ILguiItem.JOB_OWNER); final String state = getCellValue(table, rowType, ILguiItem.JOB_STATUS); final String[][] attrs = { {JobStatusData.MONITOR_ID_ATTR, lguiItem.getName()}, {JobStatusData.QUEUE_NAME_ATTR, queueName}, {JobStatusData.OWNER_ATTR, owner}, {JobStatusData.STATE_ATTR, state} }; status = new JobStatusData(jobId, attrs); } else if (status.isRemoved()) { /* * Skip rows that have been marked as "removed" */ continue; } row.setJobStatusData(status); } tableData.add(row); } return tableData.toArray(new Row[tableData.size()]); }
/** * Get the column sort property for the given column index * * @param table table containing columns * @param cids column indexes * @param index index of column * @return sort property */ private String getColumnSortProperty(TableType table, BigInteger[] cids, int index) { for (final ColumnType column : table.getColumn()) { if (column != null) { if (column.getId().equals(cids[index])) { return column.getSort().value(); } } } return ILMLCoreConstants.TABLECOLUMN_ALPHA; }
private BigInteger getColumnIndex(TableType table, String colName) { if (table != null) { for (final ColumnType column : table.getColumn()) { if (colName.equals(column.getName())) { return column.getId(); } } } return null; }
/** * Sorting of the data which should be displayed in a table. * * @param gid ID of the table * @param sortDirectionComparator Should always be the int value of ascending sorting. * @param sortIndex * @param sortDirection */ public void sort(String gid, int sortDirectionComparator, int sortIndex, int sortDirection) { final TableType table = getTable(gid); if (table != null && sortIndex != -1) { final BigInteger[] cids = getCids(gid); if (cids.length > sortIndex) { final RowType[] jobTableData = getTableData(table, cids); Arrays.sort( jobTableData, new TableSorter( getColumnSortProperty(table, cids, sortIndex), sortDirectionComparator, sortIndex, sortDirection)); table.getRow().clear(); for (final RowType element : jobTableData) { table.getRow().add(element); } } } }
public Row[] getTableDataWithColor( String gid, boolean addColor, List<IPattern> filterTitlesValues) { final Row[] rows = getTableDataWithColor(gid, addColor); if (rows.length == 0) { return rows; } final BigInteger[] cids = getCids(gid); final TableType table = getTable(gid); // Convert Map filterTitlesValues into Map filterPosValues final Map<Integer, IPattern> filterPosValues = new HashMap<Integer, IPattern>(); for (final IPattern pattern : filterTitlesValues) { BigInteger cid = BigInteger.valueOf(-1); for (final ColumnType column : table.getColumn()) { if (column.getName().equals(pattern.getColumnTitle())) { cid = column.getId(); break; } } if (cid.equals(BigInteger.valueOf(-1))) { continue; } int position = -1; for (int i = 0; i < cids.length; i++) { if (cids[i].equals(cid)) { position = i; break; } } if (position == -1) { continue; } filterPosValues.put(position, pattern); } // Filter the rows final List<Row> filterRows = new ArrayList<Row>(); for (final Row row : rows) { boolean allIncluded = true; for (final int position : filterPosValues.keySet()) { if (row.cells[position] == null) { continue; } final IPattern pattern = filterPosValues.get(position); final String rowValue = row.cells[position].value; if (rowValue.equals(ILMLCoreConstants.QM)) { allIncluded = false; continue; } final String type = pattern.getType(); if (pattern.isRange()) { // Range final String minValue = pattern.getMinValueRange(); final String maxValue = pattern.getMaxValueRange(); if (type.equals(ILMLCoreConstants.TABLECOLUMN_NUMERIC)) { if ((Integer.valueOf(rowValue) < Integer.valueOf(minValue)) || (Integer.valueOf(maxValue) < Integer.valueOf(rowValue))) { allIncluded = false; break; } } else { if (rowValue.compareTo(minValue) < 0 || maxValue.compareTo(rowValue) < 0) { allIncluded = false; break; } } } else if (pattern.isRelation()) { // Relation final String compareValue = pattern.getRelationValue(); final String compareOperator = pattern.getRelationOperator(); if (type.equals(ILMLCoreConstants.TABLECOLUMN_NUMERIC)) { final int rowValueInt = Integer.valueOf(rowValue); final int compareValueInt = Integer.valueOf(compareValue); if (compareOperator.equals(ILMLCoreConstants.EQ) && rowValueInt != compareValueInt) { allIncluded = false; break; } else if (compareOperator.equals(ILMLCoreConstants.NEQ) && rowValueInt == compareValueInt) { allIncluded = false; break; } else if (compareOperator.equals(ILMLCoreConstants.LT) && rowValueInt >= compareValueInt) { allIncluded = false; break; } else if (compareOperator.equals(ILMLCoreConstants.LE) && rowValueInt > compareValueInt) { allIncluded = false; break; } else if (compareOperator.equals(ILMLCoreConstants.GT) && rowValueInt <= compareValueInt) { allIncluded = false; break; } else if (compareOperator.equals(ILMLCoreConstants.GE) && rowValueInt < compareValueInt) { allIncluded = false; break; } } else { if ((compareOperator.equals(ILMLCoreConstants.EQ) && !compareValue.equals(rowValue)) || (compareOperator.equals(ILMLCoreConstants.NEQ) && compareValue.equals(rowValue))) { allIncluded = false; break; } else if (type.equals(ILMLCoreConstants.TABLECOLUMN_ALPHA)) { if ((compareOperator.equals(ILMLCoreConstants.SI) && !rowValue.contains(compareValue)) || (compareOperator.equals(ILMLCoreConstants.NSI) && rowValue.contains(compareValue))) { allIncluded = false; break; } } else if (type.equals(ILMLCoreConstants.TABLECOLUMN_DATE)) { if (compareOperator.equals(ILMLCoreConstants.LT) && rowValue.compareTo(compareValue) >= 0) { allIncluded = false; break; } else if (compareOperator.equals(ILMLCoreConstants.LE) && rowValue.compareTo(compareValue) > 0) { allIncluded = false; break; } else if (compareOperator.equals(ILMLCoreConstants.GT) && rowValue.compareTo(compareValue) <= 0) { allIncluded = false; break; } else if (compareOperator.equals(ILMLCoreConstants.GE) && rowValue.compareTo(compareValue) < 0) { allIncluded = false; break; } } } } } if (allIncluded) { filterRows.add(row); } } return filterRows.toArray(new Row[filterRows.size()]); }
/** * Reading out the select patterns from the JAXB objects. * * <p>Also taking care of the switch between the operators on the client side and in the LML file. * * @param gid Id of the table from which we want to get the list of patterns. * @return List of select patterns */ public List<IPattern> getPattern(String gid) { // Expects both elements to be available table and tablelayout // Requires sort datatype from table and pattern from tablelayout final TablelayoutType tablelayout = lguiItem.getLayoutAccess().getTableLayout(gid); final TableType table = getTable(gid); final LinkedList<IPattern> patternList = new LinkedList<IPattern>(); // Avoid null values if (tablelayout == null || table == null) { return patternList; } final HashMap<ColumnlayoutType, ColumnType> columnLayoutToColumn = new HashMap<ColumnlayoutType, ColumnType>(); // Search column for each columnlayout for (final ColumnlayoutType columnLayout : tablelayout.getColumn()) { for (final ColumnType aColumn : table.getColumn()) { // Search for columnlayout referencing to the column's ID if (aColumn.getId().intValue() == columnLayout.getCid().intValue()) { columnLayoutToColumn.put(columnLayout, aColumn); break; } } } for (final ColumnlayoutType columnLayout : tablelayout.getColumn()) { final ColumnType column = columnLayoutToColumn.get(columnLayout); if (column != null && columnLayout != null && columnLayout.getPattern() != null) { final List<SelectType> selects = jaxbUtil.getSelects(columnLayout.getPattern().getIncludeAndExcludeAndSelect()); if (selects.size() == 1) { String rel = null; if (selects.get(0).getRel().equals(ILMLCoreConstants.xLT_LC)) { rel = ILMLCoreConstants.LT; } else if (selects.get(0).getRel().equals(ILMLCoreConstants.xLE_LC)) { rel = ILMLCoreConstants.LE; } else if (selects.get(0).getRel().equals(ILMLCoreConstants.xGT_LC)) { rel = ILMLCoreConstants.GT; } else if (selects.get(0).getRel().equals(ILMLCoreConstants.xGE_LC)) { rel = ILMLCoreConstants.GE; } else { rel = selects.get(0).getRel(); } if (rel != null) { patternList.add( (new Pattern(columnLayout.getKey(), column.getSort().value())) .setRelation(rel, selects.get(0).getValue())); } } else if (selects.size() == 2) { String minValue = null; String maxValue = null; for (final SelectType select : selects) { if (select.getRel().equals(ILMLCoreConstants.xLE_LC)) { maxValue = select.getValue(); } else if (select.getRel().equals(ILMLCoreConstants.xGE_LC)) { minValue = select.getValue(); } } if (minValue != null && maxValue != null) { patternList.add( (new Pattern(columnLayout.getKey(), column.getSort().value())) .setRange(minValue, maxValue)); } } } } return patternList; }