private ListGridField createAuthorizedField( String name, String title, final String nameField, final ListGrid grid, boolean readOnlyColumn) { final ListGridField authorizedField = new ListGridField(name, title, 65); // Show images rather than true/false. authorizedField.setType(ListGridFieldType.IMAGE); authorizedField.setImageSize(11); LinkedHashMap<String, String> valueMap = new LinkedHashMap<String, String>(2); // set the proper images different for read-only column if (readOnlyColumn) { valueMap.put(Boolean.TRUE.toString(), "global/permission_checked_disabled_11.png"); valueMap.put(Boolean.FALSE.toString(), "global/permission_disabled_11.png"); } else { valueMap.put(Boolean.TRUE.toString(), "global/permission_enabled_11.png"); valueMap.put(Boolean.FALSE.toString(), "global/permission_disabled_11.png"); } authorizedField.setValueMap(valueMap); authorizedField.setCanEdit(true); CheckboxItem editor = new CheckboxItem(); authorizedField.setEditorType(editor); if (!this.isReadOnly) { grid.setEditEvent(ListGridEditEvent.CLICK); final Record[] recordBeingEdited = {null}; authorizedField.addRecordClickHandler( new RecordClickHandler() { public void onRecordClick(RecordClickEvent event) { recordBeingEdited[0] = event.getRecord(); } }); authorizedField.addChangedHandler( new ChangedHandler() { public void onChanged(ChangedEvent event) { Boolean authorized = (Boolean) event.getValue(); int recordNum = event.getRowNum(); ListGridRecord record = grid.getRecord(recordNum); String permissionName = record.getAttribute(nameField); Permission permission = Permission.valueOf(permissionName); String permissionDisplayName = record.getAttribute("displayName"); if (permission == Permission.VIEW_RESOURCE) { String messageString = MSG.view_adminRoles_permissions_readAccessImplied(permissionDisplayName); handleIllegalPermissionSelection(event, messageString); } else if (!authorized && selectedPermissions.contains(Permission.MANAGE_SECURITY) && permission != Permission.MANAGE_SECURITY) { String messageString = MSG.view_adminRoles_permissions_illegalDeselectionDueToManageSecuritySelection( permissionDisplayName); handleIllegalPermissionSelection(event, messageString); } else if (!authorized && selectedPermissions.contains(Permission.MANAGE_INVENTORY) && permission.getTarget() == Permission.Target.RESOURCE) { String messageString = MSG.view_adminRoles_permissions_illegalDeselectionDueToManageInventorySelection( permissionDisplayName); handleIllegalPermissionSelection(event, messageString); } else if (!authorized && selectedPermissions.contains(Permission.CONFIGURE_WRITE) && permission == Permission.CONFIGURE_READ) { String messageString = MSG .view_adminRoles_permissions_illegalDeselectionDueToCorrespondingWritePermSelection( permissionDisplayName); handleIllegalPermissionSelection(event, messageString); } else { updatePermissions(authorized, permission); // Let our parent role editor know the permissions have been changed, so it can // update the // enablement of its Save and Reset buttons. PermissionsEditor.this.roleEditView.onItemChanged(); } } }); } return authorizedField; }
@Override public ArrayList<ListGridField> getListGridFields() { ArrayList<ListGridField> fields = super.getListGridFields(); // hide the created/modified fields, we don't need to show them by default // add cell formatter on the name field so we can make it a link for (ListGridField field : fields) { String fieldName = field.getName(); if (fieldName.equals(FIELD_CTIME) || fieldName.equals(FIELD_MTIME)) { field.setHidden(true); } else if (fieldName.equals(FIELD_NAME)) { field.setCellFormatter( new CellFormatter() { @Override public String format(Object value, ListGridRecord record, int rowNum, int colNum) { AlertDefinition alertDef = copyValues(record); int resourceId = alertDef.getResource().getId(); int alertDefId = alertDef.getId(); String link = LinkManager.getSubsystemAlertDefinitionLink(resourceId, alertDefId); return "<a href=\"" + link + "\">" + StringUtility.escapeHtml(alertDef.getName()) + "</a>"; } }); } } // add more columns ListGridField parentField = new ListGridField(FIELD_PARENT, MSG.view_alerts_field_parent()); parentField.setWidth(100); parentField.setShowHover(true); parentField.setHoverCustomizer( new HoverCustomizer() { @Override public String hoverHTML(Object value, ListGridRecord record, int rowNum, int colNum) { if (record.getAttribute(FIELD_PARENT) != null) { return MSG.view_reports_alertDefinitions_parentHover(); } return MSG.common_val_na(); } }); parentField.addRecordClickHandler( new RecordClickHandler() { @Override public void onRecordClick(RecordClickEvent event) { // we only do something if we really have a parent. // if we have a template parent, we have to get the resource's type and go to the // template page for that type // if we have a group parent, we can directly go to the group's alert def page Record record = event.getRecord(); AlertDefinition alertDef = copyValues(record); if (alertDef.getParentId() != null && alertDef.getParentId().intValue() > 0) { final Integer templateId = alertDef.getParentId().intValue(); final Integer resourceId = alertDef.getResource().getId(); ResourceCriteria resCriteria = new ResourceCriteria(); resCriteria.addFilterId(resourceId); resCriteria.fetchResourceType(true); GWTServiceLookup.getResourceService() .findResourcesByCriteria( resCriteria, new AsyncCallback<PageList<Resource>>() { @Override public void onSuccess(PageList<Resource> result) { if (result == null || result.size() != 1) { CoreGUI.getErrorHandler() .handleError( MSG.view_reports_alertDefinitions_resTypeLoadError()); } else { int typeId = result.get(0).getResourceType().getId(); CoreGUI.goToView( LinkManager.getAdminTemplatesLink() + "/Alert/" + typeId + "/" + templateId); } } @Override public void onFailure(Throwable caught) { CoreGUI.getErrorHandler() .handleError( MSG.view_reports_alertDefinitions_resTypeLoadError(), caught); } }); } else if (alertDef.getGroupAlertDefinition() != null) { AlertDefinition groupAlertDef = alertDef.getGroupAlertDefinition(); CoreGUI.goToView( LinkManager.getEntityTabLink( EntityContext.forGroup(groupAlertDef.getResourceGroup()), "Alert", "Definitions") + "/" + groupAlertDef.getId()); } } }); fields.add(parentField); ListGridField resourceField = new ListGridField(FIELD_RESOURCE, MSG.common_title_resource()); resourceField.setCellFormatter( new CellFormatter() { public String format(Object value, ListGridRecord listGridRecord, int i, int i1) { String url = LinkManager.getResourceLink( listGridRecord.getAttributeAsInt(AncestryUtil.RESOURCE_ID)); return SeleniumUtility.getLocatableHref( url, StringUtility.escapeHtml(value.toString()), null); } }); resourceField.setShowHover(true); resourceField.setHoverCustomizer( new HoverCustomizer() { public String hoverHTML( Object value, ListGridRecord listGridRecord, int rowNum, int colNum) { return AncestryUtil.getResourceHoverHTML(listGridRecord, 0); } }); fields.add(resourceField); ListGridField ancestryField = AncestryUtil.setupAncestryListGridField(); fields.add(ancestryField); return fields; }
public Tasks() { super(); SectionStack sectionStack = new SectionStack(); sectionStack.setVisibilityMode(VisibilityMode.MULTIPLE); sectionStack.setWidth100(); sectionStack.setHeight100(); sections = new SectionStackSection[3]; for (int i = 0; i < 2; i++) { sections[i] = new SectionStackSection(i == 0 ? "My Tasks" : "Available Tasks"); sections[i].setExpanded(true); sections[i].setResizeable(false); ListGridField complete = new ListGridField("complete", " "); complete.setType(ListGridFieldType.BOOLEAN); complete.setCanEdit(true); complete.setCanToggle(true); if (i == 0) { final MyTasksListGrid taskgrid = new MyTasksListGrid(); taskgrid.setWidth100(); taskgrid.setHeight100(); taskgrid.setCanExpandRecords(true); taskgrid.setCanExpandMultipleRecords(false); taskgrid.setExpansionMode(ExpansionMode.DETAILS); taskgrid.setShowAllRecords(true); taskgrid.setExpansionCanEdit(true); taskgrid.addCellDoubleClickHandler( new CellDoubleClickHandler() { public void onCellDoubleClick(CellDoubleClickEvent event) { taskgrid.expandRecord(taskgrid.getRecord(event.getRowNum())); } }); ListGridField processIntanceID = new ListGridField("$#processInstanceId", "Workflow"); processIntanceID.setBaseStyle("linkLabel"); processIntanceID.addRecordClickHandler( new RecordClickHandler() { public void onRecordClick(RecordClickEvent event) { Object[] args = {event.getValue(), true}; PageManager.getInstance().setPageHistory(Pages.VIEWWORKFLOW, args); } }); taskgrid.setFields( complete, new ListGridField("taskname", "Name"), new ListGridField("$#createTime", "Time"), new ListGridField("$#priority", "Priority"), new ListGridField("$#assignee", "Assignee"), new ListGridField("$#activityName", "ActivityName"), processIntanceID); sections[i].addItem(taskgrid); } else { CustomListGrid grid = new CustomListGrid(); grid.setWidth100(); grid.setHeight100(); grid.setCanExpandRecords(true); grid.setCanExpandMultipleRecords(false); grid.setExpansionMode(ExpansionMode.DETAILS); grid.setShowAllRecords(true); complete.addRecordClickHandler(getRecordClickHandler(grid, i == 1)); grid.setShowRecordComponents(true); grid.setShowRecordComponentsByCell(true); ListGridField assign = new ListGridField("Assign", "Assign"); assign.setAlign(Alignment.CENTER); grid.setFields( complete, new ListGridField("taskname", "Name"), new ListGridField("$#createTime", "Time"), new ListGridField("$#priority", "Priority"), assign); sections[i].addItem(grid); } } sections[2] = new SectionStackSection("Event Log"); sections[2].setExpanded(true); sections[2].setResizeable(false); ListGrid grid = new ListGrid(); grid.setWidth100(); grid.setHeight100(); grid.setCanExpandRecords(false); grid.setShowAllRecords(true); grid.setCanEdit(false); grid.setFields( new ListGridField("$#endTime", "Time"), new ListGridField("$#id", "Task"), new ListGridField("$#assignee", "User"), new ListGridField("$#state", "Action"), new ListGridField("outcome", "Outcome"), new ListGridField("$#processInstanceId", "Workflow")); sections[2].addItem(grid); sectionStack.addSection(sections[0]); sectionStack.addSection(sections[1]); sectionStack.addSection(sections[2]); BpmServiceMain.sendGet( "/processInstances/tasks?assignee=" + BpmServiceMain.getUser(), new AsyncCallback<String>() { public void onFailure(Throwable arg0) {} public void onSuccess(String arg0) { ArrayList<Task> tasks = Parse.parseProcessTasks(arg0); records1 = new ListGridRecord[MAX_TASKS]; int i = 0; for (Task t : tasks) { records1[i++] = createLGR(false, t); } ((MyTasksListGrid) sections[0].getItems()[0]).setData(records1); } }); BpmServiceMain.sendGet( "/processInstances/tasks?candidate=" + BpmServiceMain.getUser(), new AsyncCallback<String>() { public void onFailure(Throwable arg0) {} public void onSuccess(String arg0) { ArrayList<Task> tasks = Parse.parseProcessTasks(arg0); records2 = new ListGridRecord[MAX_TASKS]; int i = 0; for (Task t : tasks) { records2[i++] = createLGR(false, t); } ((CustomListGrid) sections[1].getItems()[0]).setData(records2); } }); int dayLength = 24 * 60 * 60 * 1000; Date d = new Date(); d.setTime(d.getTime() + dayLength); String end = (1900 + d.getYear()) + "-" + (d.getMonth() < 9 ? "0" : "") + (d.getMonth() + 1) + "-" + (d.getDate() < 9 ? "0" : "") + d.getDate(); d = new Date(); d.setTime(d.getTime() - dayLength * 3); String start = (1900 + d.getYear()) + "-" + (d.getMonth() < 9 ? "0" : "") + (d.getMonth() + 1) + "-" + (d.getDate() < 9 ? "0" : "") + d.getDate(); BpmServiceMain.sendGet( "/tasks/history?assignee=" + BpmServiceMain.getUser() + "&start=" + start + "&end=" + end, new AsyncCallback<String>() { public void onFailure(Throwable arg0) {} public void onSuccess(String arg0) { ArrayList<Task> tasks = Parse.parseTasks(arg0); records3 = new ListGridRecord[MAX_TASKS]; int i = 0; for (Task t : tasks) { records3[i++] = createLGR(true, t); } ((ListGrid) sections[2].getItems()[0]).setData(records3); ((ListGrid) sections[2].getItems()[0]).sort(0, SortDirection.DESCENDING); } }); createPage(sectionStack, PageWidget.PAGE_TASKS); timer = new Timer() { public void run() { updateTasks(); } }; timer.scheduleRepeating(BpmServiceMain.getPollingRate()); }