[rhq] 2 commits - modules/enterprise
by ips
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/admin/roles/RoleEditView.java | 2
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/admin/roles/RolesView.java | 3
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/admin/users/UserEditView.java | 6
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/admin/users/UsersDataSource.java | 4
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/admin/users/UsersView.java | 5
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/definitions/AbstractAlertDefinitionsView.java | 13 +
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/definitions/GeneralPropertiesAlertDefinitionForm.java | 4
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/bundle/deployment/BundleDeploymentListView.java | 11 +
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/bundle/deployment/BundleDeploymentView.java | 7
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/bundle/destination/BundleDestinationListView.java | 16 +-
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/bundle/destination/BundleDestinationView.java | 11 -
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/bundle/list/BundleView.java | 5
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/bundle/list/BundlesListView.java | 11 +
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/bundle/revert/GetRevertInfoStep.java | 16 +-
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/bundle/tree/BundleTreeDataSource.java | 10 -
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/configuration/ConfigurationEditor.java | 5
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/form/EnhancedDynamicForm.java | 8 -
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/table/EscapedHtmlCellFormatter.java | 19 ++
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/table/IconField.java | 73 ++++++++++
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/table/TableSection.java | 14 +
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/tree/EnhancedTreeNode.java | 6
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/recent/problems/ProblemResourcesPortlet.java | 6
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/util/MessagePortlet.java | 11 -
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/common/detail/operation/history/AbstractOperationHistoryDetailsView.java | 2
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/common/detail/operation/schedule/AbstractOperationScheduleDetailsView.java | 4
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/common/detail/summary/AbstractActivityView.java | 2
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/detail/ResourceGroupTreeView.java | 10 -
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/AncestryUtil.java | 58 ++++---
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/ResourceSearchView.java | 23 +--
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/ResourceTitleBar.java | 3
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/ResourceTreeDatasource.java | 8 -
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/StringUtility.java | 65 ++++++++
32 files changed, 343 insertions(+), 98 deletions(-)
New commits:
commit ce940eefcecc42c3a4c545dc17010d7773725a6c
Author: Ian Springer <ian.springer(a)redhat.com>
Date: Thu Mar 31 17:28:25 2011 -0400
...
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/StringUtility.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/StringUtility.java
index 0c93099..e14b9db 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/StringUtility.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/StringUtility.java
@@ -1,6 +1,6 @@
/*
* RHQ Management Platform
- * Copyright 2011, Red Hat Middleware LLC, and individual contributors
+ * Copyright 2010-2011, Red Hat Middleware LLC, and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
@@ -19,6 +19,9 @@
*/
package org.rhq.enterprise.gui.coregui.client.util;
+import java.util.ArrayList;
+import java.util.List;
+
/**
* A collection of utility methods for working with Strings.
*
@@ -27,6 +30,41 @@ package org.rhq.enterprise.gui.coregui.client.util;
public class StringUtility {
/**
+ * Split a string on delimiter boundaries, and place each element into a List.
+ *
+ * @param s String to split up
+ * @param delim Delimiting token, ala StringTokenizer
+ *
+ * @return a List comprised of elements split by the tokenizing
+ */
+ public static List<String> explode(String s, String delim) {
+ List<String> res = new ArrayList<String>();
+ if (s == null)
+ return res;
+
+ String[] tokens = s.split(delim);
+ for (String token : tokens) {
+ res.add(token);
+ }
+
+ return res;
+ }
+
+ // TODO: I18N. The logic here may need to be pluggable for different localizations.
+ public static String pluralize(String singularNoun) {
+ String pluralNoun;
+ if (singularNoun.endsWith("y") && !singularNoun.endsWith("ay") && !singularNoun.endsWith("ey")
+ && !singularNoun.endsWith("oy")) {
+ pluralNoun = singularNoun.substring(0, singularNoun.length() - 1) + "ies";
+ } else if (!singularNoun.endsWith("s")) {
+ pluralNoun = singularNoun + "s";
+ } else {
+ pluralNoun = singularNoun;
+ }
+ return pluralNoun;
+ }
+
+ /**
* Escapes HTML in a string to eliminate cross site scripting (XSS) vulnerabilities. Note, this impl is designed
* to be highly efficient to minimize the impact on performance.
*
commit 170b9a147fce855f8196a7e13803e5a0e3d2f7bb
Author: Ian Springer <ian.springer(a)redhat.com>
Date: Thu Mar 31 17:25:56 2011 -0400
escape or sanitize HTML in user-controlled text, which could be used for XSS attacks
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/admin/roles/RoleEditView.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/admin/roles/RoleEditView.java
index 58cde04..178acd0 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/admin/roles/RoleEditView.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/admin/roles/RoleEditView.java
@@ -305,11 +305,13 @@ public class RoleEditView extends AbstractRecordEditor<RolesDataSource> implemen
TextItem nameItem = new TextItem(RolesDataSource.Field.NAME);
nameItem.setShowTitle(true);
+ nameItem.setAttribute(EnhancedDynamicForm.OUTPUT_AS_HTML_ATTRIBUTE, true);
items.add(nameItem);
TextItem descriptionItem = new TextItem(RolesDataSource.Field.DESCRIPTION);
descriptionItem.setShowTitle(true);
descriptionItem.setColSpan(form.getNumCols());
+ descriptionItem.setAttribute(EnhancedDynamicForm.OUTPUT_AS_HTML_ATTRIBUTE, true);
items.add(descriptionItem);
return items;
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/admin/roles/RolesView.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/admin/roles/RolesView.java
index 46fa148..6aaf418 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/admin/roles/RolesView.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/admin/roles/RolesView.java
@@ -34,6 +34,7 @@ import org.rhq.enterprise.gui.coregui.client.BookmarkableView;
import org.rhq.enterprise.gui.coregui.client.PermissionsLoadedListener;
import org.rhq.enterprise.gui.coregui.client.PermissionsLoader;
import org.rhq.enterprise.gui.coregui.client.admin.AdministrationView;
+import org.rhq.enterprise.gui.coregui.client.components.table.EscapedHtmlCellFormatter;
import org.rhq.enterprise.gui.coregui.client.components.table.TableAction;
import org.rhq.enterprise.gui.coregui.client.components.table.TableSection;
import org.rhq.enterprise.gui.coregui.client.components.view.ViewName;
@@ -62,6 +63,7 @@ public class RolesView extends TableSection<RolesDataSource> implements Bookmark
final RolesDataSource datasource = RolesDataSource.getInstance();
setDataSource(datasource);
setHeaderIcon(HEADER_ICON);
+ setEscapeHtmlInDetailsLinkColumn(true);
}
@Override
@@ -108,6 +110,7 @@ public class RolesView extends TableSection<RolesDataSource> implements Bookmark
fields.add(nameField);
ListGridField descriptionField = new ListGridField(RolesDataSource.Field.DESCRIPTION);
+ descriptionField.setCellFormatter(new EscapedHtmlCellFormatter());
fields.add(descriptionField);
return fields;
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/admin/users/UserEditView.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/admin/users/UserEditView.java
index 4ce9950..ba10fef 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/admin/users/UserEditView.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/admin/users/UserEditView.java
@@ -137,6 +137,7 @@ public class UserEditView extends AbstractRecordEditor<UsersDataSource> {
nameItem = new TextItem(UsersDataSource.Field.NAME);
} else {
nameItem = new StaticTextItem(UsersDataSource.Field.NAME);
+ ((StaticTextItem)nameItem).setOutputAsHTML(true);
}
items.add(nameItem);
@@ -167,20 +168,25 @@ public class UserEditView extends AbstractRecordEditor<UsersDataSource> {
TextItem firstNameItem = new TextItem(UsersDataSource.Field.FIRST_NAME);
firstNameItem.setShowTitle(true);
+ firstNameItem.setAttribute(EnhancedDynamicForm.OUTPUT_AS_HTML_ATTRIBUTE, true);
items.add(firstNameItem);
TextItem lastNameItem = new TextItem(UsersDataSource.Field.LAST_NAME);
lastNameItem.setShowTitle(true);
+ lastNameItem.setAttribute(EnhancedDynamicForm.OUTPUT_AS_HTML_ATTRIBUTE, true);
items.add(lastNameItem);
TextItem emailAddressItem = new TextItem(UsersDataSource.Field.EMAIL_ADDRESS);
emailAddressItem.setShowTitle(true);
+ emailAddressItem.setAttribute(EnhancedDynamicForm.OUTPUT_AS_HTML_ATTRIBUTE, true);
items.add(emailAddressItem);
TextItem phoneNumberItem = new TextItem(UsersDataSource.Field.PHONE_NUMBER);
+ phoneNumberItem.setAttribute(EnhancedDynamicForm.OUTPUT_AS_HTML_ATTRIBUTE, true);
items.add(phoneNumberItem);
TextItem departmentItem = new TextItem(UsersDataSource.Field.DEPARTMENT);
+ departmentItem.setAttribute(EnhancedDynamicForm.OUTPUT_AS_HTML_ATTRIBUTE, true);
items.add(departmentItem);
boolean userBeingEditedIsRhqadmin = (getRecordId() == SUBJECT_ID_RHQADMIN);
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/admin/users/UsersDataSource.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/admin/users/UsersDataSource.java
index d6f536b..6bdf6a5 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/admin/users/UsersDataSource.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/admin/users/UsersDataSource.java
@@ -107,7 +107,9 @@ public class UsersDataSource extends RPCDataSource<Subject, SubjectCriteria> {
fields.add(idDataField);
DataSourceTextField usernameField = createTextField(Field.NAME, MSG.dataSource_users_field_name(), 3, 100, true);
-
+ // Don't allow characters that could be used in HTML intended for an XSS attack.
+ RegExpValidator regExpValidator = new RegExpValidator("[^&<]*");
+ usernameField.setValidators(regExpValidator);
fields.add(usernameField);
DataSourceTextField ldapField = createBooleanField(Field.LDAP, MSG.dataSource_users_field_ldap(), true);
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/admin/users/UsersView.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/admin/users/UsersView.java
index f124703..4fae91e 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/admin/users/UsersView.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/admin/users/UsersView.java
@@ -33,6 +33,7 @@ import org.rhq.core.domain.authz.Permission;
import org.rhq.enterprise.gui.coregui.client.PermissionsLoadedListener;
import org.rhq.enterprise.gui.coregui.client.PermissionsLoader;
import org.rhq.enterprise.gui.coregui.client.admin.AdministrationView;
+import org.rhq.enterprise.gui.coregui.client.components.table.EscapedHtmlCellFormatter;
import org.rhq.enterprise.gui.coregui.client.components.table.TableAction;
import org.rhq.enterprise.gui.coregui.client.components.table.TableSection;
import org.rhq.enterprise.gui.coregui.client.components.view.ViewName;
@@ -64,6 +65,7 @@ public class UsersView extends TableSection<UsersDataSource> {
setDataSource(dataSource);
setHeaderIcon(HEADER_ICON);
+ setEscapeHtmlInDetailsLinkColumn(true);
fetchManageSecurityPermissionAsync();
}
@@ -131,12 +133,15 @@ public class UsersView extends TableSection<UsersDataSource> {
fields.add(ldapField);
ListGridField firstNameField = new ListGridField(UsersDataSource.Field.FIRST_NAME, 150);
+ firstNameField.setCellFormatter(new EscapedHtmlCellFormatter());
fields.add(firstNameField);
ListGridField lastNameField = new ListGridField(UsersDataSource.Field.LAST_NAME, 150);
+ lastNameField.setCellFormatter(new EscapedHtmlCellFormatter());
fields.add(lastNameField);
ListGridField departmentField = new ListGridField(UsersDataSource.Field.DEPARTMENT, 150);
+ departmentField.setCellFormatter(new EscapedHtmlCellFormatter());
fields.add(departmentField);
// TODO: instead of fetching roles, use a composite object that will pull the role count across the wire.
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/definitions/AbstractAlertDefinitionsView.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/definitions/AbstractAlertDefinitionsView.java
index 376d659..4d8b846 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/definitions/AbstractAlertDefinitionsView.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/definitions/AbstractAlertDefinitionsView.java
@@ -1,6 +1,6 @@
/*
* RHQ Management Platform
- * Copyright (C) 2005-2010 Red Hat, Inc.
+ * Copyright (C) 2005-2011 Red Hat, Inc.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
@@ -21,6 +21,7 @@ package org.rhq.enterprise.gui.coregui.client.alert.definitions;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.smartgwt.client.data.Criteria;
import com.smartgwt.client.widgets.Canvas;
+import com.smartgwt.client.widgets.grid.CellFormatter;
import com.smartgwt.client.widgets.grid.ListGrid;
import com.smartgwt.client.widgets.grid.ListGridField;
import com.smartgwt.client.widgets.grid.ListGridRecord;
@@ -34,9 +35,11 @@ import org.rhq.core.domain.resource.ResourceType;
import org.rhq.core.domain.util.PageList;
import org.rhq.enterprise.gui.coregui.client.CoreGUI;
import org.rhq.enterprise.gui.coregui.client.components.table.AbstractTableAction;
+import org.rhq.enterprise.gui.coregui.client.components.table.EscapedHtmlCellFormatter;
import org.rhq.enterprise.gui.coregui.client.components.table.TableActionEnablement;
import org.rhq.enterprise.gui.coregui.client.components.table.TableSection;
import org.rhq.enterprise.gui.coregui.client.gwt.GWTServiceLookup;
+import org.rhq.enterprise.gui.coregui.client.util.StringUtility;
/**
* Superclass to the different alert definition views. This should be subclassed
@@ -48,6 +51,8 @@ public abstract class AbstractAlertDefinitionsView extends TableSection<Abstract
public AbstractAlertDefinitionsView(String locatorId, String tableTitle) {
super(locatorId, tableTitle);
+
+ setEscapeHtmlInDetailsLinkColumn(true);
}
@Override
@@ -66,6 +71,12 @@ public abstract class AbstractAlertDefinitionsView extends TableSection<Abstract
listGrid.setFixedRecordHeights(false);
//listGrid.getField("id").setWidth(55);
+ // name and description are user-editable, so escape HTML to prevent XSS attacks
+ ListGridField nameField = listGrid.getField(AbstractAlertDefinitionsDataSource.FIELD_NAME);
+ nameField.setCellFormatter(new EscapedHtmlCellFormatter());
+ ListGridField descriptionField = listGrid.getField(AbstractAlertDefinitionsDataSource.FIELD_DESCRIPTION);
+ descriptionField.setCellFormatter(new EscapedHtmlCellFormatter());
+
boolean permitted = isAllowedToModifyAlertDefinitions();
TableActionEnablement enablement = (permitted) ? TableActionEnablement.ALWAYS : TableActionEnablement.NEVER;
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/definitions/GeneralPropertiesAlertDefinitionForm.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/definitions/GeneralPropertiesAlertDefinitionForm.java
index 90f09f4..7d6b0d5 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/definitions/GeneralPropertiesAlertDefinitionForm.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/definitions/GeneralPropertiesAlertDefinitionForm.java
@@ -209,11 +209,15 @@ public class GeneralPropertiesAlertDefinitionForm extends LocatableDynamicForm i
nameTextField.setWidth(300);
nameTextField.setDefaultValue("");
nameStatic = new StaticTextItem("nameStatic", MSG.common_title_name());
+ // name is user-editable, so escape HTML to prevent XSS attacks
+ nameStatic.setOutputAsHTML(true);
descriptionTextField = new TextAreaItem("description", MSG.common_title_description());
descriptionTextField.setWidth(300);
descriptionTextField.setDefaultValue("");
descriptionStatic = new StaticTextItem("descriptionStatic", MSG.common_title_description());
+ // description is user-editable, so escape HTML to prevent XSS attacks
+ descriptionStatic.setOutputAsHTML(true);
prioritySelection = new SelectItem("priority", MSG.view_alerts_field_priority());
LinkedHashMap<String, String> priorities = new LinkedHashMap<String, String>(3);
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/bundle/deployment/BundleDeploymentListView.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/bundle/deployment/BundleDeploymentListView.java
index 42711b6..b2763d9 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/bundle/deployment/BundleDeploymentListView.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/bundle/deployment/BundleDeploymentListView.java
@@ -40,8 +40,10 @@ import org.rhq.enterprise.gui.coregui.client.CoreGUI;
import org.rhq.enterprise.gui.coregui.client.ErrorMessageWindow;
import org.rhq.enterprise.gui.coregui.client.LinkManager;
import org.rhq.enterprise.gui.coregui.client.bundle.list.BundleVersionDataSource;
+import org.rhq.enterprise.gui.coregui.client.components.table.EscapedHtmlCellFormatter;
import org.rhq.enterprise.gui.coregui.client.components.table.Table;
import org.rhq.enterprise.gui.coregui.client.components.table.TimestampCellFormatter;
+import org.rhq.enterprise.gui.coregui.client.util.StringUtility;
/**
* @author Greg Hinkle
@@ -76,16 +78,21 @@ public class BundleDeploymentListView extends Table<BundleDeploymentDataSource>
// only users that are authorized can see deployments
if (canManageBundles) {
nameField.setCellFormatter(new CellFormatter() {
- public String format(Object o, ListGridRecord record, int i, int i1) {
+ public String format(Object value, ListGridRecord record, int i, int i1) {
return "<a href=\""
+ LinkManager.getBundleDeploymentLink(record
.getAttributeAsInt(BundleDeploymentDataSource.FIELD_BUNDLE_ID), record
- .getAttributeAsInt(BundleDeploymentDataSource.FIELD_ID)) + "\">" + String.valueOf(o)
+ .getAttributeAsInt(BundleDeploymentDataSource.FIELD_ID)) + "\">"
+ + StringUtility.escapeHtml(String.valueOf(value))
+ "</a>";
}
});
+ } else {
+ nameField.setCellFormatter(new EscapedHtmlCellFormatter());
}
+ descriptionField.setCellFormatter(new EscapedHtmlCellFormatter());
+
bundleVersionField.setCellFormatter(new CellFormatter() {
public String format(Object o, ListGridRecord record, int i, int i1) {
return "<a href=\""
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/bundle/deployment/BundleDeploymentView.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/bundle/deployment/BundleDeploymentView.java
index c00a454..62bf4ed 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/bundle/deployment/BundleDeploymentView.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/bundle/deployment/BundleDeploymentView.java
@@ -77,6 +77,7 @@ import org.rhq.enterprise.gui.coregui.client.components.tagging.TagEditorView;
import org.rhq.enterprise.gui.coregui.client.components.tagging.TagsChangedCallback;
import org.rhq.enterprise.gui.coregui.client.gwt.BundleGWTServiceAsync;
import org.rhq.enterprise.gui.coregui.client.gwt.GWTServiceLookup;
+import org.rhq.enterprise.gui.coregui.client.util.StringUtility;
import org.rhq.enterprise.gui.coregui.client.util.message.Message;
import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableDynamicForm;
import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableIButton;
@@ -146,7 +147,7 @@ public class BundleDeploymentView extends LocatableVLayout implements Bookmarkab
LinkItem bundleName = new LinkItem("bundle");
bundleName.setTitle(MSG.view_bundle_bundle());
bundleName.setValue(LinkManager.getBundleLink(bundle.getId()));
- bundleName.setLinkTitle(bundle.getName());
+ bundleName.setLinkTitle(StringUtility.escapeHtml(bundle.getName()));
bundleName.setTarget("_self");
CanvasItem actionItem = new CanvasItem("actions");
@@ -172,14 +173,14 @@ public class BundleDeploymentView extends LocatableVLayout implements Bookmarkab
LinkItem destinationGroup = new LinkItem("group");
destinationGroup.setTitle(MSG.common_title_resource_group());
destinationGroup.setValue(LinkManager.getResourceGroupLink(deployment.getDestination().getGroup().getId()));
- destinationGroup.setLinkTitle(deployment.getDestination().getGroup().getName());
+ destinationGroup.setLinkTitle(StringUtility.escapeHtml((deployment.getDestination().getGroup().getName())));
destinationGroup.setTarget("_self");
StaticTextItem path = new StaticTextItem("path", MSG.view_bundle_deployDir());
path.setValue(deployment.getDestination().getDeployDir());
StaticTextItem description = new StaticTextItem("description", MSG.common_title_description());
- description.setValue(deployment.getDescription());
+ description.setValue(StringUtility.escapeHtml(deployment.getDescription()));
StaticTextItem status = new StaticTextItem("status", MSG.common_title_status());
status.setValue(deployment.getStatus().name());
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/bundle/destination/BundleDestinationListView.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/bundle/destination/BundleDestinationListView.java
index d3ca12c..bbd20f6 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/bundle/destination/BundleDestinationListView.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/bundle/destination/BundleDestinationListView.java
@@ -38,6 +38,7 @@ import org.rhq.enterprise.gui.coregui.client.CoreGUI;
import org.rhq.enterprise.gui.coregui.client.LinkManager;
import org.rhq.enterprise.gui.coregui.client.components.table.Table;
import org.rhq.enterprise.gui.coregui.client.components.table.TimestampCellFormatter;
+import org.rhq.enterprise.gui.coregui.client.util.StringUtility;
/**
* @author Greg Hinkle
@@ -77,24 +78,27 @@ public class BundleDestinationListView extends Table<BundleDestinationDataSource
TimestampCellFormatter.prepareDateField(latestDeploymentDateField);
nameField.setCellFormatter(new CellFormatter() {
- public String format(Object o, ListGridRecord listGridRecord, int i, int i1) {
+ public String format(Object value, ListGridRecord listGridRecord, int i, int i1) {
Integer bundleId = listGridRecord.getAttributeAsInt(BundleDestinationDataSource.FIELD_BUNDLE_ID);
Integer bundleDestId = listGridRecord.getAttributeAsInt(BundleDestinationDataSource.FIELD_ID);
- return "<a href=\"" + LinkManager.getBundleDestinationLink(bundleId, bundleDestId) + "\">" + o + "</a>";
+ return "<a href=\"" + LinkManager.getBundleDestinationLink(bundleId, bundleDestId) + "\">"
+ + StringUtility.escapeHtml(value.toString()) + "</a>";
}
});
groupNameField.setCellFormatter(new CellFormatter() {
- public String format(Object o, ListGridRecord listGridRecord, int i, int i1) {
+ public String format(Object value, ListGridRecord listGridRecord, int i, int i1) {
Integer groupId = listGridRecord.getAttributeAsInt(BundleDestinationDataSource.FIELD_GROUP_ID);
- return "<a href=\"" + LinkManager.getResourceGroupLink(groupId) + "\">" + o + "</a>";
+ return "<a href=\"" + LinkManager.getResourceGroupLink(groupId) + "\">"
+ + StringUtility.escapeHtml(value.toString()) + "</a>";
}
});
bundleNameField.setCellFormatter(new CellFormatter() {
- public String format(Object o, ListGridRecord listGridRecord, int i, int i1) {
+ public String format(Object value, ListGridRecord listGridRecord, int i, int i1) {
Integer bid = listGridRecord.getAttributeAsInt(BundleDestinationDataSource.FIELD_BUNDLE_ID);
- return "<a href=\"" + LinkManager.getBundleLink(bid) + "\">" + o + "</a>";
+ return "<a href=\"" + LinkManager.getBundleLink(bid) + "\">"
+ + StringUtility.escapeHtml(value.toString()) + "</a>";
}
});
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/bundle/destination/BundleDestinationView.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/bundle/destination/BundleDestinationView.java
index da52896..0a805e0 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/bundle/destination/BundleDestinationView.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/bundle/destination/BundleDestinationView.java
@@ -57,6 +57,7 @@ import org.rhq.enterprise.gui.coregui.client.components.tagging.TagEditorView;
import org.rhq.enterprise.gui.coregui.client.components.tagging.TagsChangedCallback;
import org.rhq.enterprise.gui.coregui.client.gwt.BundleGWTServiceAsync;
import org.rhq.enterprise.gui.coregui.client.gwt.GWTServiceLookup;
+import org.rhq.enterprise.gui.coregui.client.util.StringUtility;
import org.rhq.enterprise.gui.coregui.client.util.message.Message;
import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableDynamicForm;
import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableIButton;
@@ -89,10 +90,10 @@ public class BundleDestinationView extends LocatableVLayout implements Bookmarka
this.bundle = bundleDestination.getBundle();
BackButton backButton = new BackButton(extendLocatorId("BackButton"), MSG.view_bundle_dest_backToBundle()
- + ": " + bundle.getName(), "Bundles/Bundle/" + bundle.getId());
+ + ": " + StringUtility.escapeHtml(bundle.getName()), "Bundles/Bundle/" + bundle.getId());
HeaderLabel header = new HeaderLabel(Canvas.getImgURL("subsystems/bundle/BundleDestination_24.png"),
- destination.getName());
+ StringUtility.escapeHtml(destination.getName()));
detail = new Canvas();
detail.setHeight("50%");
@@ -121,7 +122,7 @@ public class BundleDestinationView extends LocatableVLayout implements Bookmarka
LinkItem bundleName = new LinkItem("bundle");
bundleName.setTitle(MSG.view_bundle_bundle());
bundleName.setValue(LinkManager.getBundleLink(bundle.getId()));
- bundleName.setLinkTitle(bundle.getName());
+ bundleName.setLinkTitle(StringUtility.escapeHtml(bundle.getName()));
bundleName.setTarget("_self");
CanvasItem actionItem = new CanvasItem("actions");
@@ -136,14 +137,14 @@ public class BundleDestinationView extends LocatableVLayout implements Bookmarka
LinkItem destinationGroup = new LinkItem("group");
destinationGroup.setTitle(MSG.view_bundle_dest_group());
destinationGroup.setValue(LinkManager.getResourceGroupLink(destination.getGroup().getId()));
- destinationGroup.setLinkTitle(destination.getGroup().getName());
+ destinationGroup.setLinkTitle(StringUtility.escapeHtml(destination.getGroup().getName()));
destinationGroup.setTarget("_self");
StaticTextItem path = new StaticTextItem("path", MSG.view_bundle_dest_deployDir());
path.setValue(destination.getDeployDir());
StaticTextItem description = new StaticTextItem("description", MSG.common_title_description());
- description.setValue(destination.getDescription());
+ description.setValue(StringUtility.escapeHtml(destination.getDescription()));
form.setFields(bundleName, actionItem, created, destinationGroup, path, description);
return form;
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/bundle/list/BundleView.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/bundle/list/BundleView.java
index f4801ea..74eaa68 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/bundle/list/BundleView.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/bundle/list/BundleView.java
@@ -60,6 +60,7 @@ import org.rhq.enterprise.gui.coregui.client.components.tagging.TagEditorView;
import org.rhq.enterprise.gui.coregui.client.components.tagging.TagsChangedCallback;
import org.rhq.enterprise.gui.coregui.client.gwt.BundleGWTServiceAsync;
import org.rhq.enterprise.gui.coregui.client.gwt.GWTServiceLookup;
+import org.rhq.enterprise.gui.coregui.client.util.StringUtility;
import org.rhq.enterprise.gui.coregui.client.util.message.Message;
import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableDynamicForm;
import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableIButton;
@@ -98,7 +99,7 @@ public class BundleView extends LocatableVLayout implements BookmarkableView {
BackButton backButton = new BackButton(extendLocatorId("BackButton"), MSG.view_bundle_list_backToAll(),
BundleTopView.VIEW_ID.getTitle());
- headerLabel = new HeaderLabel("subsystems/bundle/Bundle_24.png", bundle.getName());
+ headerLabel = new HeaderLabel("subsystems/bundle/Bundle_24.png", StringUtility.escapeHtml(bundle.getName()));
tabs = new LocatableTabSet(getLocatorId());
versionsTab = createVersionsTab();
destinationsTab = createDestinationsTab();
@@ -188,7 +189,7 @@ public class BundleView extends LocatableVLayout implements BookmarkableView {
destinationsCountItem.setValue(bundle.getDestinations() != null ? bundle.getDestinations().size() : 0);
StaticTextItem descriptionItem = new StaticTextItem("description", MSG.common_title_description());
- descriptionItem.setValue(bundle.getDescription());
+ descriptionItem.setValue(StringUtility.escapeHtml(bundle.getDescription()));
form.setFields(versionCountItem, actionItem, destinationsCountItem, descriptionItem);
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/bundle/list/BundlesListView.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/bundle/list/BundlesListView.java
index 023fd1f..ea25046 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/bundle/list/BundlesListView.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/bundle/list/BundlesListView.java
@@ -47,6 +47,7 @@ import org.rhq.enterprise.gui.coregui.client.components.table.TableActionEnablem
import org.rhq.enterprise.gui.coregui.client.gwt.BundleGWTServiceAsync;
import org.rhq.enterprise.gui.coregui.client.gwt.GWTServiceLookup;
import org.rhq.enterprise.gui.coregui.client.util.ErrorHandler;
+import org.rhq.enterprise.gui.coregui.client.util.StringUtility;
import org.rhq.enterprise.gui.coregui.client.util.message.Message;
import org.rhq.enterprise.gui.coregui.client.util.message.Message.Severity;
@@ -80,7 +81,6 @@ public class BundlesListView extends Table<BundlesWithLatestVersionDataSource> {
@Override
protected void configureTable() {
-
ListGridField idField = new ListGridField(BundlesWithLatestVersionDataSource.FIELD_ID, MSG.common_title_id());
idField.setType(ListGridFieldType.INTEGER);
idField.setWidth("50");
@@ -89,15 +89,20 @@ public class BundlesListView extends Table<BundlesWithLatestVersionDataSource> {
.common_title_name());
nameField.setWidth("33%");
nameField.setCellFormatter(new CellFormatter() {
- public String format(Object o, ListGridRecord record, int i, int i1) {
+ public String format(Object value, ListGridRecord record, int i, int i1) {
return "<a href=\"" + record.getAttribute(BundlesWithLatestVersionDataSource.FIELD_NAMELINK) + "\">"
- + String.valueOf(o) + "</a>";
+ + StringUtility.escapeHtml(String.valueOf(value)) + "</a>";
}
});
ListGridField descField = new ListGridField(BundlesWithLatestVersionDataSource.FIELD_DESCRIPTION, MSG
.common_title_description());
descField.setWidth("33%");
+ descField.setCellFormatter(new CellFormatter() {
+ public String format(Object value, ListGridRecord record, int i, int i1) {
+ return StringUtility.escapeHtml(String.valueOf(value));
+ }
+ });
ListGridField latestVersionField = new ListGridField(BundlesWithLatestVersionDataSource.FIELD_LATEST_VERSION,
MSG.view_bundle_latestVersion());
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/bundle/revert/GetRevertInfoStep.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/bundle/revert/GetRevertInfoStep.java
index 552ab4d..33d20e2 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/bundle/revert/GetRevertInfoStep.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/bundle/revert/GetRevertInfoStep.java
@@ -31,6 +31,7 @@ import org.rhq.enterprise.gui.coregui.client.CoreGUI;
import org.rhq.enterprise.gui.coregui.client.components.wizard.AbstractWizardStep;
import org.rhq.enterprise.gui.coregui.client.gwt.BundleGWTServiceAsync;
import org.rhq.enterprise.gui.coregui.client.gwt.GWTServiceLookup;
+import org.rhq.enterprise.gui.coregui.client.util.StringUtility;
import org.rhq.enterprise.gui.coregui.client.util.selenium.Locatable;
import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableDynamicForm;
@@ -68,24 +69,27 @@ public class GetRevertInfoStep extends AbstractWizardStep {
.getId(), //
new AsyncCallback<String>() {
- public void onSuccess(String result) {
+ public void onSuccess(String bundleDeploymentName) {
final StaticTextItem nameTextItem = new StaticTextItem("name", MSG
.view_bundle_revertWizard_getInfoStep_revertDeployName());
nameTextItem.setWidth(300);
- wizard.setSubtitle(result);
- nameTextItem.setValue(result);
+ String escapedBundleDeploymentName = StringUtility.escapeHtml(bundleDeploymentName);
+ wizard.setSubtitle(escapedBundleDeploymentName);
+ nameTextItem.setValue(escapedBundleDeploymentName);
final TextAreaItem descriptionTextAreaItem = new TextAreaItem("description", MSG
.view_bundle_revertWizard_getInfoStep_revertDeployDesc());
descriptionTextAreaItem.setWidth(300);
String liveDesc = wizard.getLiveDeployment().getDescription();
liveDesc = (null == liveDesc) ? wizard.getLiveDeployment().getName() : liveDesc;
+ String escapedLiveDesc = StringUtility.escapeHtml(liveDesc);
String prevDesc = wizard.getPreviousDeployment().getDescription();
prevDesc = (null == prevDesc) ? wizard.getPreviousDeployment().getName() : prevDesc;
- wizard.setDeploymentDescription("[REVERT From]\n" + liveDesc + "\n\n[REVERT To]\n" + prevDesc);
+ String escapedPrevDesc = StringUtility.escapeHtml(prevDesc);
+ wizard.setDeploymentDescription("[REVERT From]\n" + escapedLiveDesc + "\n\n[REVERT To]\n" + escapedPrevDesc);
wizard.setDeploymentDescription(MSG.view_bundle_revertWizard_getInfoStep_revertDeployDescFull(
- liveDesc, prevDesc));
- descriptionTextAreaItem.setValue(wizard.getDeploymentDescription());
+ escapedLiveDesc, escapedPrevDesc));
+ descriptionTextAreaItem.setValue(StringUtility.escapeHtml(wizard.getDeploymentDescription()));
descriptionTextAreaItem.addChangedHandler(new ChangedHandler() {
public void onChanged(ChangedEvent event) {
Object value = event.getValue();
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/bundle/tree/BundleTreeDataSource.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/bundle/tree/BundleTreeDataSource.java
index 039bc3e..39b84e7 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/bundle/tree/BundleTreeDataSource.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/bundle/tree/BundleTreeDataSource.java
@@ -49,6 +49,7 @@ import org.rhq.enterprise.gui.coregui.client.CoreGUI;
import org.rhq.enterprise.gui.coregui.client.gwt.BundleGWTServiceAsync;
import org.rhq.enterprise.gui.coregui.client.gwt.GWTServiceLookup;
import org.rhq.enterprise.gui.coregui.client.util.RPCDataSource;
+import org.rhq.enterprise.gui.coregui.client.util.StringUtility;
/**
* @author Greg Hinkle
@@ -244,7 +245,7 @@ public class BundleTreeDataSource extends RPCDataSource<Object, Criteria> {
node.setIsFolder(true);
node.setIcon("subsystems/bundle/Bundle_16.png");
node.setID(String.valueOf(bundle.getId()));
- node.setName(bundle.getName());
+ node.setName(StringUtility.escapeHtml(bundle.getName()));
} else if (from instanceof BundleVersion) {
BundleVersion version = (BundleVersion) from;
@@ -262,10 +263,11 @@ public class BundleTreeDataSource extends RPCDataSource<Object, Criteria> {
parentID = bundleId + "_destinations_" + deployment.getDestination().getId();
node.setParentID(parentID);
node.setID(bundleId + "_deployments_" + deployment.getId());
+ String name = StringUtility.escapeHtml(deployment.getName());
if (deployment.isLive()) {
- node.setName("<span style=\"color: green; font-weight: bold\">(live)</span> " + deployment.getName());
+ node.setName("<span style=\"color: green; font-weight: bold\">(live)</span> " + name);
} else {
- node.setName(deployment.getName());
+ node.setName(name);
}
} else if (from instanceof BundleDestination) {
@@ -275,7 +277,7 @@ public class BundleTreeDataSource extends RPCDataSource<Object, Criteria> {
parentID = destination.getBundle().getId() + "_destinations";
node.setParentID(parentID);
node.setID(parentID + '_' + destination.getId());
- node.setName(destination.getName());
+ node.setName(StringUtility.escapeHtml(destination.getName()));
}
return node;
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/configuration/ConfigurationEditor.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/configuration/ConfigurationEditor.java
index ac2d132..35d61f2 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/configuration/ConfigurationEditor.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/configuration/ConfigurationEditor.java
@@ -1261,7 +1261,10 @@ public class ConfigurationEditor extends LocatableVLayout {
// TODO (ips, 03/25/11): We eventually want to use StaticTextItems for read-only PASSWORD props too, but we have
// to wait until we implement masking/unmasking of PASSWORD props at the SLSB layer first.
if (propertyIsReadOnly && propertyDefinitionSimple.getType() != PropertySimpleType.PASSWORD) {
- valueItem = new StaticTextItem();
+ StaticTextItem staticItem = new StaticTextItem();
+ // Property values are user-editable, so escape HTML to prevent an XSS attack.
+ staticItem.setOutputAsHTML(true);
+ valueItem = staticItem;
} else {
List<PropertyDefinitionEnumeration> enumeratedValues = propertyDefinitionSimple.getEnumeratedValues();
if (enumeratedValues != null && !enumeratedValues.isEmpty()) {
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/form/EnhancedDynamicForm.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/form/EnhancedDynamicForm.java
index 59c8b9d..02c2752 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/form/EnhancedDynamicForm.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/form/EnhancedDynamicForm.java
@@ -1,6 +1,6 @@
/*
* RHQ Management Platform
- * Copyright (C) 2010 Red Hat, Inc.
+ * Copyright (C) 2010-2011 Red Hat, Inc.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
@@ -45,6 +45,8 @@ import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableDynamicForm;
*/
public class EnhancedDynamicForm extends LocatableDynamicForm {
+ public static final String OUTPUT_AS_HTML_ATTRIBUTE = "outputAsHTML";
+
private static final String FIELD_ID = "id";
private boolean isReadOnly;
@@ -116,6 +118,10 @@ public class EnhancedDynamicForm extends LocatableDynamicForm {
staticItem.setTooltip(item.getTooltip());
staticItem.setValue(item.getDisplayValue());
staticItem.setColSpan(item.getAttribute("colSpan"));
+ Boolean outputAsHtml = item.getAttributeAsBoolean(OUTPUT_AS_HTML_ATTRIBUTE);
+ if (Boolean.TRUE.equals(outputAsHtml)) {
+ staticItem.setOutputAsHTML(true);
+ }
// TODO: Any other fields we should copy? icons?
if ((item instanceof BooleanItem) || (item instanceof CheckboxItem)) {
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/table/EscapedHtmlCellFormatter.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/table/EscapedHtmlCellFormatter.java
new file mode 100644
index 0000000..c60236c
--- /dev/null
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/table/EscapedHtmlCellFormatter.java
@@ -0,0 +1,19 @@
+package org.rhq.enterprise.gui.coregui.client.components.table;
+
+import com.smartgwt.client.widgets.grid.CellFormatter;
+import com.smartgwt.client.widgets.grid.ListGridRecord;
+import org.rhq.enterprise.gui.coregui.client.ImageManager;
+import org.rhq.enterprise.gui.coregui.client.util.StringUtility;
+
+/**
+ * A cell formatter that escapes any HTML in the cell's value.
+ *
+ * @author Ian Springer
+ */
+public class EscapedHtmlCellFormatter implements CellFormatter {
+
+ public String format(Object value, ListGridRecord record, int rowNum, int colNum) {
+ return (value != null) ? StringUtility.escapeHtml(value.toString()) : "";
+ }
+
+}
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/table/IconField.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/table/IconField.java
new file mode 100644
index 0000000..82d6071
--- /dev/null
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/table/IconField.java
@@ -0,0 +1,73 @@
+/*
+ * RHQ Management Platform
+ * Copyright 2011, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+package org.rhq.enterprise.gui.coregui.client.components.table;
+
+import com.google.gwt.core.client.JavaScriptObject;
+import com.smartgwt.client.types.Alignment;
+import com.smartgwt.client.types.ListGridFieldType;
+import com.smartgwt.client.widgets.grid.ListGridField;
+
+/**
+ * @author Ian Springer
+ */
+public class IconField extends ListGridField {
+
+ private static final String DEFAULT_NAME = "icon";
+ private static final String DEFAULT_TITLE = " ";
+ private static final int DEFAULT_WIDTH = 25;
+
+ public IconField() {
+ super(DEFAULT_NAME, DEFAULT_TITLE, DEFAULT_WIDTH);
+ init();
+ }
+
+ public IconField(JavaScriptObject jsObj) {
+ super(DEFAULT_NAME, DEFAULT_TITLE, DEFAULT_WIDTH);
+ setJsObj(jsObj);
+ init();
+ }
+
+ public IconField(String name) {
+ super(name, DEFAULT_TITLE, DEFAULT_WIDTH);
+ init();
+ }
+
+ public IconField(String name, int width) {
+ super(name, DEFAULT_TITLE, width);
+ init();
+ }
+
+ public IconField(String name, String title) {
+ super(name, title, DEFAULT_WIDTH);
+ init();
+ }
+
+ public IconField(String name, String title, int width) {
+ super(name, title, width);
+ init();
+ }
+
+ private void init() {
+ setType(ListGridFieldType.IMAGE);
+ setAlign(Alignment.CENTER);
+ setShowDefaultContextMenu(false);
+ }
+
+}
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/table/TableSection.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/table/TableSection.java
index e551deb..b19abfd 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/table/TableSection.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/table/TableSection.java
@@ -44,6 +44,7 @@ import org.rhq.enterprise.gui.coregui.client.DetailsView;
import org.rhq.enterprise.gui.coregui.client.ViewPath;
import org.rhq.enterprise.gui.coregui.client.components.buttons.BackButton;
import org.rhq.enterprise.gui.coregui.client.util.RPCDataSource;
+import org.rhq.enterprise.gui.coregui.client.util.StringUtility;
import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableVLayout;
import org.rhq.enterprise.gui.coregui.client.util.selenium.SeleniumUtility;
@@ -56,6 +57,7 @@ public abstract class TableSection<DS extends RPCDataSource> extends Table<DS> i
private VLayout detailsHolder;
private Canvas detailsView;
private String basePath;
+ private boolean escapeHtmlInDetailsLinkColumn;
protected TableSection(String locatorId, String tableTitle) {
super(locatorId, tableTitle);
@@ -110,7 +112,7 @@ public abstract class TableSection<DS extends RPCDataSource> extends Table<DS> i
/**
* The default implementation wraps the {@link getDetailsLinkColumnCellFormatter()} column with the
- * {@link getDetailsLinkColumnCellFormatter()}. This is typically the 'name' column linking to the detail
+ * {@link #getDetailsLinkColumnCellFormatter()}. This is typically the 'name' column linking to the detail
* view, given the 'id'. Also, establishes a double click handler for the row which invokes
* {@link showDetails()}</br>
* </br>
@@ -146,6 +148,10 @@ public abstract class TableSection<DS extends RPCDataSource> extends Table<DS> i
return true;
}
+ public void setEscapeHtmlInDetailsLinkColumn(boolean escapeHtmlInDetailsLinkColumn) {
+ this.escapeHtmlInDetailsLinkColumn = escapeHtmlInDetailsLinkColumn;
+ }
+
/**
* Override if you don't want FIELD_NAME to be wrapped ina link.
* @return the name of the field to be wrapped, or null if no field should be wrapped.
@@ -161,9 +167,13 @@ public abstract class TableSection<DS extends RPCDataSource> extends Table<DS> i
protected CellFormatter getDetailsLinkColumnCellFormatter() {
return new CellFormatter() {
public String format(Object value, ListGridRecord record, int i, int i1) {
+ if (value == null) {
+ return "";
+ }
Integer recordId = getId(record);
String detailsUrl = "#" + getBasePath() + "/" + recordId;
- return SeleniumUtility.getLocatableHref(detailsUrl, value.toString(), null);
+ String formattedValue = (escapeHtmlInDetailsLinkColumn) ? StringUtility.escapeHtml(value.toString()) : value.toString();
+ return SeleniumUtility.getLocatableHref(detailsUrl, formattedValue, null);
}
};
}
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/tree/EnhancedTreeNode.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/tree/EnhancedTreeNode.java
index 15e13fa..1bae1e2 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/tree/EnhancedTreeNode.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/tree/EnhancedTreeNode.java
@@ -1,6 +1,6 @@
/*
* RHQ Management Platform
- * Copyright (C) 2010 Red Hat, Inc.
+ * Copyright (C) 2010-2011 Red Hat, Inc.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
@@ -24,6 +24,7 @@ import com.smartgwt.client.widgets.tree.TreeNode;
* @author Ian Springer
*/
public class EnhancedTreeNode extends TreeNode {
+
public EnhancedTreeNode() {
super();
}
@@ -55,7 +56,7 @@ public class EnhancedTreeNode extends TreeNode {
public void setName(String name) {
super.setName(name);
if (name != null && getTitle() == null) {
- setTitle(name);
+ super.setTitle(name);
}
}
@@ -110,4 +111,5 @@ public class EnhancedTreeNode extends TreeNode {
private Attributes() {
}
}
+
}
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/recent/problems/ProblemResourcesPortlet.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/recent/problems/ProblemResourcesPortlet.java
index 8fcaba0..f91c4cf 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/recent/problems/ProblemResourcesPortlet.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/recent/problems/ProblemResourcesPortlet.java
@@ -49,6 +49,7 @@ import org.rhq.core.domain.configuration.definition.PropertyDefinitionSimple;
import org.rhq.core.domain.configuration.definition.PropertySimpleType;
import org.rhq.core.domain.dashboard.DashboardPortlet;
import org.rhq.enterprise.gui.coregui.client.LinkManager;
+import org.rhq.enterprise.gui.coregui.client.components.table.IconField;
import org.rhq.enterprise.gui.coregui.client.components.table.Table;
import org.rhq.enterprise.gui.coregui.client.components.table.TableWidget;
import org.rhq.enterprise.gui.coregui.client.dashboard.AutoRefreshPortlet;
@@ -139,12 +140,9 @@ public class ProblemResourcesPortlet extends Table<ProblemResourcesDataSource> i
ListGridField alertsField = new ListGridField(ALERTS.propertyName(), ALERTS.title(), 70);
- ListGridField availabilityField = new ListGridField(AVAILABILITY.propertyName(), AVAILABILITY.title(), 70);
- availabilityField.setType(ListGridFieldType.IMAGE);
- availabilityField.setAlign(Alignment.CENTER);
+ IconField availabilityField = new IconField(AVAILABILITY.propertyName(), AVAILABILITY.title(), 70);
setListGridFields(resourceField, ancestryField, alertsField, availabilityField);
-
}
@Override
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/util/MessagePortlet.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/util/MessagePortlet.java
index 8da6a8b..ead9cc2 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/util/MessagePortlet.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/util/MessagePortlet.java
@@ -34,6 +34,7 @@ import org.rhq.enterprise.gui.coregui.client.dashboard.ConfigurablePortlet;
import org.rhq.enterprise.gui.coregui.client.dashboard.Portlet;
import org.rhq.enterprise.gui.coregui.client.dashboard.PortletViewFactory;
import org.rhq.enterprise.gui.coregui.client.dashboard.PortletWindow;
+import org.rhq.enterprise.gui.coregui.client.util.StringUtility;
import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableHTMLPane;
/**
@@ -46,15 +47,17 @@ public class MessagePortlet extends LocatableHTMLPane implements ConfigurablePor
// A default displayed, persisted name for the portlet
public static final String NAME = MSG.view_portlet_defaultName_message();
+ private static final String MESSAGE_PROPERTY = "message";
+
public MessagePortlet(String locatorId) {
super(locatorId);
setContentsType(ContentsType.PAGE);
}
public void configure(PortletWindow portletWindow, DashboardPortlet storedPortlet) {
- String contents = storedPortlet.getConfiguration().getSimpleValue("message", null);
+ String contents = storedPortlet.getConfiguration().getSimpleValue(MESSAGE_PROPERTY, null);
if (contents != null) {
- setContents(contents);
+ setContents(StringUtility.sanitizeHtml(contents));
} else {
setContents("<br/><i>" + MSG.view_portlet_configure_needed() + "</i>");
}
@@ -68,7 +71,7 @@ public class MessagePortlet extends LocatableHTMLPane implements ConfigurablePor
ConfigurationDefinition definition = new ConfigurationDefinition(MSG.view_portlet_configure_definitionTitle(),
MSG.view_portlet_configure_definitionDesc());
- definition.put(new PropertyDefinitionSimple("message", MSG.view_portlet_message_title(), true,
+ definition.put(new PropertyDefinitionSimple(MESSAGE_PROPERTY, MSG.view_portlet_message_title(), true,
PropertySimpleType.LONG_STRING));
return definition;
@@ -78,8 +81,8 @@ public class MessagePortlet extends LocatableHTMLPane implements ConfigurablePor
public static PortletViewFactory INSTANCE = new Factory();
public final Portlet getInstance(String locatorId) {
-
return new MessagePortlet(locatorId);
}
}
+
}
\ No newline at end of file
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/common/detail/operation/history/AbstractOperationHistoryDetailsView.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/common/detail/operation/history/AbstractOperationHistoryDetailsView.java
index 27b1040..236e994 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/common/detail/operation/history/AbstractOperationHistoryDetailsView.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/common/detail/operation/history/AbstractOperationHistoryDetailsView.java
@@ -167,6 +167,8 @@ public abstract class AbstractOperationHistoryDetailsView<T extends OperationHis
StaticTextItem requesterItem = new StaticTextItem(AbstractOperationHistoryDataSource.Field.SUBJECT, MSG
.view_operationHistoryDetails_requestor());
+
+ requesterItem.setOutputAsHTML(true);
requesterItem.setValue(operationHistory.getSubjectName());
items.add(requesterItem);
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/common/detail/operation/schedule/AbstractOperationScheduleDetailsView.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/common/detail/operation/schedule/AbstractOperationScheduleDetailsView.java
index ff577d0..387c4d5 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/common/detail/operation/schedule/AbstractOperationScheduleDetailsView.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/common/detail/operation/schedule/AbstractOperationScheduleDetailsView.java
@@ -263,7 +263,9 @@ public abstract class AbstractOperationScheduleDetailsView extends AbstractRecor
Integer integerValue = TypeConversionUtility.toInteger(value);
timeoutItem.setValue(integerValue, UnitType.TIME);
- FormItem notesItem = this.notesForm.getField(AbstractOperationScheduleDataSource.Field.DESCRIPTION);
+ StaticTextItem notesItem = (StaticTextItem) this.notesForm.getField(AbstractOperationScheduleDataSource.Field.DESCRIPTION);
+ // Notes field is user-editable, so escape HTML to prevent an XSS attack.
+ notesItem.setOutputAsHTML(true);
notesItem.setValue(getForm().getValue(AbstractOperationScheduleDataSource.Field.DESCRIPTION));
this.parameters = (Configuration) record.getAttributeAsObject(AbstractOperationScheduleDataSource.Field.PARAMETERS);
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/common/detail/summary/AbstractActivityView.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/common/detail/summary/AbstractActivityView.java
index 82ac645..5fec813 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/common/detail/summary/AbstractActivityView.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/common/detail/summary/AbstractActivityView.java
@@ -401,7 +401,7 @@ public abstract class AbstractActivityView extends LocatableVLayout implements R
/** Create empty display row(LocatableDynamicForm) that is constently defined and displayed.
*
- * @param column Locatable parent colum.
+ * @param locatorId locator ID of Locatable parent column
* @param emptyMessage Contents of the empty region
* @return
*/
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/detail/ResourceGroupTreeView.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/detail/ResourceGroupTreeView.java
index 04fbfbd..a469fa9 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/detail/ResourceGroupTreeView.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/detail/ResourceGroupTreeView.java
@@ -1,6 +1,6 @@
/*
* RHQ Management Platform
- * Copyright (C) 2005-2010 Red Hat, Inc.
+ * Copyright (C) 2005-2011 Red Hat, Inc.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
@@ -281,7 +281,9 @@ public class ResourceGroupTreeView extends LocatableVLayout implements Bookmarka
ResourceGroupTreeView.this.rootResourceGroup = group;
ResourceGroupTreeView.this.rootGroupId = rootResourceGroup.getId();
ResourceGroupEnhancedTreeNode fakeRoot = new ResourceGroupEnhancedTreeNode("fakeRootNode");
- ResourceGroupEnhancedTreeNode rootNode = new ResourceGroupEnhancedTreeNode(group.getName());
+ String groupName = group.getName();
+ String escapedGroupName = StringUtility.escapeHtml(groupName);
+ ResourceGroupEnhancedTreeNode rootNode = new ResourceGroupEnhancedTreeNode(escapedGroupName);
String icon = ImageManager.getGroupIcon(GroupCategory.MIXED);
rootNode.setIcon(icon);
rootNode.setID(String.valueOf(rootResourceGroup.getId()));
@@ -387,7 +389,9 @@ public class ResourceGroupTreeView extends LocatableVLayout implements Bookmarka
ResourceGroupEnhancedTreeNode fakeRoot = new ResourceGroupEnhancedTreeNode("fakeRootNode");
fakeRoot.setID(FAKE_ROOT_ID);
- ResourceGroupEnhancedTreeNode rootNode = new ResourceGroupEnhancedTreeNode(rootResourceGroup.getName());
+ String groupName = rootResourceGroup.getName();
+ String escapedGroupName = StringUtility.escapeHtml(groupName);
+ ResourceGroupEnhancedTreeNode rootNode = new ResourceGroupEnhancedTreeNode(escapedGroupName);
rootNode.setID(rootKey.getKey());
rootNode.setParentID(fakeRoot.getID());
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/AncestryUtil.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/AncestryUtil.java
index 2393132..ba890d4 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/AncestryUtil.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/AncestryUtil.java
@@ -34,6 +34,7 @@ import org.rhq.core.domain.resource.Resource;
import org.rhq.core.domain.resource.ResourceType;
import org.rhq.enterprise.gui.coregui.client.CoreGUI;
import org.rhq.enterprise.gui.coregui.client.LinkManager;
+import org.rhq.enterprise.gui.coregui.client.util.StringUtility;
import org.rhq.enterprise.gui.coregui.client.util.selenium.SeleniumUtility;
/**
@@ -42,6 +43,7 @@ import org.rhq.enterprise.gui.coregui.client.util.selenium.SeleniumUtility;
* @author Jay Shaughnessy
*/
public abstract class AncestryUtil {
+
// ListGrid Record attribute names expected to be set on records processed by the utility
public static final String RESOURCE_ANCESTRY = "resourceAncestry";
public static final String RESOURCE_ANCESTRY_VALUE = "resourceAncestryDecoded";
@@ -115,8 +117,8 @@ public abstract class AncestryUtil {
continue;
}
String[] ancestryEntries = ancestry.split(Resource.ANCESTRY_DELIM);
- for (int i = 0; i < ancestryEntries.length; ++i) {
- String[] entryTokens = ancestryEntries[i].split(Resource.ANCESTRY_ENTRY_DELIM);
+ for (String ancestryEntry : ancestryEntries) {
+ String[] entryTokens = ancestryEntry.split(Resource.ANCESTRY_ENTRY_DELIM);
int rtId = Integer.valueOf(entryTokens[0]);
result.add(rtId);
}
@@ -148,7 +150,7 @@ public abstract class AncestryUtil {
String[] entryTokens = ancestryEntries[i].split(Resource.ANCESTRY_ENTRY_DELIM);
int ancestorTypeId = Integer.valueOf(entryTokens[0]);
int ancestorResourceId = Integer.valueOf(entryTokens[1]);
- String ancestorName = entryTokens[2];
+ String ancestorName = StringUtility.escapeHtml(entryTokens[2]);
sbResources.append((i > 0) ? " < " : "");
//sbResources.append(" < ");
@@ -201,17 +203,15 @@ public abstract class AncestryUtil {
return "";
}
- Integer resourceId = record.getAttributeAsInt(RESOURCE_ID);
- // if not set assume the standard "id" attr is a resourceId
- resourceId = (null != resourceId) ? resourceId : record.getAttributeAsInt("id");
+ Integer resourceId = getResourceId(record);
StringBuilder sbResources = new StringBuilder();
String[] ancestryEntries = ancestry.split(Resource.ANCESTRY_DELIM);
for (int i = 0; i < ancestryEntries.length; ++i) {
String[] entryTokens = ancestryEntries[i].split(Resource.ANCESTRY_ENTRY_DELIM);
int ancestorResourceId = Integer.valueOf(entryTokens[1]);
- String ancestorName = entryTokens[2];
+ String ancestorName = StringUtility.escapeHtml(entryTokens[2]);
- sbResources.append((i > 0) ? " < " : "");
+ sbResources.append((i > 0) ? " < " : "");
if (generateLinks) {
String url = LinkManager.getResourceLink(ancestorResourceId);
String suffix = resourceId + "_" + entryTokens[1];
@@ -231,18 +231,14 @@ public abstract class AncestryUtil {
return ancestryHover;
}
- Integer resourceId = listGridRecord.getAttributeAsInt(RESOURCE_ID);
- // if not set assume the standard "id" attr is a resourceId
- resourceId = (null != resourceId) ? resourceId : listGridRecord.getAttributeAsInt("id");
- String resourceName = listGridRecord.getAttribute(RESOURCE_NAME);
- // if not set assume the standard "name" attr is a resourceName
- resourceName = (null != resourceName) ? resourceName : listGridRecord.getAttribute("name");
+ String resourceName = getResourceName(listGridRecord);
+
Map<Integer, ResourceType> types = ((MapWrapper) listGridRecord.getAttributeAsObject(RESOURCE_ANCESTRY_TYPES))
.getMap();
Integer resourceTypeId = listGridRecord.getAttributeAsInt(RESOURCE_TYPE_ID);
String ancestry = listGridRecord.getAttributeAsString(RESOURCE_ANCESTRY);
- String result = getAncestryHoverHTMLString(resourceId, resourceName, ancestry, resourceTypeId, types, width);
+ String result = getAncestryHoverHTMLString(resourceName, ancestry, resourceTypeId, types, width);
listGridRecord.setAttribute(RESOURCE_ANCESTRY_HOVER, result);
return result;
@@ -250,12 +246,12 @@ public abstract class AncestryUtil {
public static String getAncestryHoverHTMLForResource(Resource resource, Map<Integer, ResourceType> types, int width) {
- return getAncestryHoverHTMLString(resource.getId(), resource.getName(), resource.getAncestry(), resource
+ return getAncestryHoverHTMLString(resource.getName(), resource.getAncestry(), resource
.getResourceType().getId(), types, width);
}
- private static String getAncestryHoverHTMLString(int resourceId, String resourceName, String ancestry,
- int resourceTypeId, Map<Integer, ResourceType> types, int width) {
+ private static String getAncestryHoverHTMLString(String resourceName, String ancestry,
+ int resourceTypeId, Map<Integer, ResourceType> types, int width) {
ResourceType type = types.get(resourceTypeId);
String resourceLongName = getResourceLongName(resourceName, type);
@@ -282,7 +278,7 @@ public abstract class AncestryUtil {
for (int i = ancestryEntries.length - 1, j = 0; i >= 0; --i, ++j) {
String[] entryTokens = ancestryEntries[i].split(Resource.ANCESTRY_ENTRY_DELIM);
int ancestorTypeId = Integer.valueOf(entryTokens[0]);
- String ancestorName = entryTokens[2];
+ String ancestorName = StringUtility.escapeHtml(entryTokens[2]);
// indent with spaces
if (j > 0) {
@@ -323,9 +319,10 @@ public abstract class AncestryUtil {
/**
* Get a resource name that combines type and resource information. This is useful for when we want to
- * use a single column for dispay of the resource "name". The name is wrapped in a navigable link.
+ * use a single column for display of the resource "name". The name is wrapped in a navigable link.
*
- * @param resource The resource
+ * @param record the resource record
+ * @param width the width, in pixels, of the returned HTML <code>p</code> tag
*
* @return the long name for the resource
*/
@@ -335,9 +332,7 @@ public abstract class AncestryUtil {
return resourceHover;
}
- String resourceName = record.getAttribute(RESOURCE_NAME);
- // if not set assume the standard "name" attr is a resourceName
- resourceName = (null != resourceName) ? resourceName : record.getAttribute("name");
+ String resourceName = getResourceName(record);
Map<Integer, ResourceType> types = ((MapWrapper) record.getAttributeAsObject(RESOURCE_ANCESTRY_TYPES)).getMap();
Integer resourceTypeId = record.getAttributeAsInt(RESOURCE_TYPE_ID);
ResourceType type = types.get(resourceTypeId);
@@ -365,6 +360,21 @@ public abstract class AncestryUtil {
return result;
}
+ private static Integer getResourceId(Record record) {
+ Integer resourceId = record.getAttributeAsInt(RESOURCE_ID);
+ // if not set assume the standard "id" attr is a resourceId
+ resourceId = (null != resourceId) ? resourceId : record.getAttributeAsInt("id");
+ return resourceId;
+ }
+
+ private static String getResourceName(Record record) {
+ String resourceName = record.getAttribute(RESOURCE_NAME);
+ // if not set assume the standard "name" attr is a resourceName
+ resourceName = (null != resourceName) ? resourceName : record.getAttribute("name");
+ resourceName = StringUtility.escapeHtml(resourceName);
+ return resourceName;
+ }
+
// We do not want smargwt to see we are storing our map into an attribute because it barfs on our key/value pairs
// so instead we have to wrap it in a non-Map POJO Object so smartgwt just handles it as a java.lang.Object.
public static class MapWrapper {
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/ResourceSearchView.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/ResourceSearchView.java
index 32a6227..b53a127 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/ResourceSearchView.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/ResourceSearchView.java
@@ -33,8 +33,6 @@ import com.google.gwt.user.client.rpc.AsyncCallback;
import com.smartgwt.client.data.Criteria;
import com.smartgwt.client.data.Record;
import com.smartgwt.client.data.SortSpecifier;
-import com.smartgwt.client.types.Alignment;
-import com.smartgwt.client.types.ListGridFieldType;
import com.smartgwt.client.widgets.events.DoubleClickEvent;
import com.smartgwt.client.widgets.events.DoubleClickHandler;
import com.smartgwt.client.widgets.grid.CellFormatter;
@@ -52,12 +50,14 @@ import org.rhq.enterprise.gui.coregui.client.CoreGUI;
import org.rhq.enterprise.gui.coregui.client.LinkManager;
import org.rhq.enterprise.gui.coregui.client.components.table.RecordExtractor;
import org.rhq.enterprise.gui.coregui.client.components.table.ResourceAuthorizedTableAction;
+import org.rhq.enterprise.gui.coregui.client.components.table.IconField;
import org.rhq.enterprise.gui.coregui.client.components.table.ResourceCategoryCellFormatter;
import org.rhq.enterprise.gui.coregui.client.components.table.Table;
import org.rhq.enterprise.gui.coregui.client.components.table.TableActionEnablement;
import org.rhq.enterprise.gui.coregui.client.gwt.GWTServiceLookup;
import org.rhq.enterprise.gui.coregui.client.gwt.ResourceGWTServiceAsync;
import org.rhq.enterprise.gui.coregui.client.util.RPCDataSource;
+import org.rhq.enterprise.gui.coregui.client.util.StringUtility;
import org.rhq.enterprise.gui.coregui.client.util.TableUtility;
import org.rhq.enterprise.gui.coregui.client.util.message.Message;
import org.rhq.enterprise.gui.coregui.client.util.message.Message.Severity;
@@ -125,14 +125,9 @@ public class ResourceSearchView extends Table {
@Override
protected void configureTable() {
- ListGridField iconField = new ListGridField("icon", MSG.common_title_icon(), 25);
- iconField.setType(ListGridFieldType.IMAGE);
- iconField.setShowDefaultContextMenu(false);
- iconField.setCanSort(false);
- iconField.setTitle(" ");
+ IconField iconField = new IconField();
iconField.setShowHover(true);
iconField.setHoverCustomizer(new HoverCustomizer() {
- @Override
public String hoverHTML(Object value, ListGridRecord record, int rowNum, int colNum) {
String resCat = record.getAttribute(CATEGORY.propertyName());
switch (ResourceCategory.valueOf(resCat)) {
@@ -149,14 +144,14 @@ public class ResourceSearchView extends Table {
ListGridField nameField = new ListGridField(NAME.propertyName(), NAME.title(), 250);
nameField.setCellFormatter(new CellFormatter() {
- public String format(Object o, ListGridRecord listGridRecord, int i, int i1) {
- String url = LinkManager.getResourceLink(listGridRecord.getAttributeAsInt("id"));
- return SeleniumUtility.getLocatableHref(url, o.toString(), null);
+ public String format(Object value, ListGridRecord record, int rowNum, int colNum) {
+ String url = LinkManager.getResourceLink(record.getAttributeAsInt("id"));
+ String name = StringUtility.escapeHtml(value.toString());
+ return SeleniumUtility.getLocatableHref(url, name, null);
}
});
nameField.setShowHover(true);
nameField.setHoverCustomizer(new HoverCustomizer() {
-
public String hoverHTML(Object value, ListGridRecord listGridRecord, int rowNum, int colNum) {
return AncestryUtil.getResourceHoverHTML(listGridRecord, 0);
}
@@ -174,9 +169,7 @@ public class ResourceSearchView extends Table {
categoryField.setCellFormatter(new ResourceCategoryCellFormatter());
categoryField.setHidden(true); // the icon field already shows us this, no need to show it in another column
- ListGridField availabilityField = new ListGridField(AVAILABILITY.propertyName(), AVAILABILITY.title(), 70);
- availabilityField.setType(ListGridFieldType.IMAGE);
- availabilityField.setAlign(Alignment.CENTER);
+ IconField availabilityField = new IconField(AVAILABILITY.propertyName(), AVAILABILITY.title(), 70);
setListGridFields(iconField, nameField, ancestryField, descriptionField, typeNameField, pluginNameField,
categoryField, availabilityField);
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/ResourceTitleBar.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/ResourceTitleBar.java
index bd86104..dcdffd9 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/ResourceTitleBar.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/ResourceTitleBar.java
@@ -49,6 +49,7 @@ import org.rhq.enterprise.gui.coregui.client.UserSessionManager;
import org.rhq.enterprise.gui.coregui.client.components.tagging.TagEditorView;
import org.rhq.enterprise.gui.coregui.client.components.tagging.TagsChangedCallback;
import org.rhq.enterprise.gui.coregui.client.gwt.GWTServiceLookup;
+import org.rhq.enterprise.gui.coregui.client.util.StringUtility;
import org.rhq.enterprise.gui.coregui.client.util.message.Message;
import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableHLayout;
import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableImg;
@@ -310,7 +311,7 @@ public class ResourceTitleBar extends LocatableVLayout {
if (!resource.getName().equals(resourceName)) {
resource.setName(resourceName); // the name must have been changed by the user via the editable field
}
- this.title.setContents("<span class=\"SectionHeader\">" + resource.getName()
+ this.title.setContents("<span class=\"SectionHeader\">" + StringUtility.escapeHtml(resourceName)
+ "</span> <span class=\"subtitle\">" + resource.getResourceType().getName() + "</span>");
this.title.markForRedraw();
}
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/ResourceTreeDatasource.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/ResourceTreeDatasource.java
index 336e12e..6a38008 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/ResourceTreeDatasource.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/ResourceTreeDatasource.java
@@ -334,10 +334,14 @@ public class ResourceTreeDatasource extends DataSource {
}
this.setParentID(parentId);
+ // name and description are user-editable, so escape HTML to prevent XSS attacks
String name = resource.getName();
- setName(name);
+ String escapedName = StringUtility.escapeHtml(name);
+ setName(escapedName);
- setAttribute(Attributes.DESCRIPTION, resource.getDescription());
+ String description = resource.getDescription();
+ String escapedDescription = StringUtility.escapeHtml(description);
+ setAttribute(Attributes.DESCRIPTION, escapedDescription);
Set<ResourceType> childTypes = resource.getResourceType().getChildResourceTypes();
setIsFolder((childTypes != null && !childTypes.isEmpty()));
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/StringUtility.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/StringUtility.java
index 984ca22..0c93099 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/StringUtility.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/StringUtility.java
@@ -1,6 +1,6 @@
/*
* RHQ Management Platform
- * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * Copyright 2011, Red Hat Middleware LLC, and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
@@ -19,53 +19,72 @@
*/
package org.rhq.enterprise.gui.coregui.client.util;
-import java.util.ArrayList;
-import java.util.List;
-
/**
* A collection of utility methods for working with Strings.
- *
- * TODO: I18N. The logic here may need to be pluggable for different localizations.
*
* @author Ian Springer
*/
public class StringUtility {
/**
- * Split a string on delimiter boundaries, and place each element into a List.
+ * Escapes HTML in a string to eliminate cross site scripting (XSS) vulnerabilities. Note, this impl is designed
+ * to be highly efficient to minimize the impact on performance.
*
- * @param s String to split up
- * @param delim Delimiting token, ala StringTokenizer
+ * @param string the string to be escaped
*
- * @return a List comprised of elements split by the tokenizing
+ * @return the escaped string
*/
-
- public static List<String> explode(String s, String delim) {
- List<String> res = new ArrayList<String>();
- if (s == null)
- return res;
-
- String[] tokens = s.split(delim);
- for (String token : tokens) {
- res.add(token);
+ public static String escapeHtml(String string) {
+ if (string == null) {
+ return null;
}
-
- return res;
+ StringBuilder buffer = null;
+ for (int i = 0; i < string.length(); i++) {
+ char c = string.charAt(i);
+ if (c == '&') {
+ if (buffer == null) {
+ buffer = new StringBuilder(string.substring(0, i));
+ }
+ buffer.append("&");
+ } else if (c == '<') {
+ if (buffer == null) {
+ buffer = new StringBuilder(string.substring(0, i));
+ }
+ buffer.append("<");
+ } else if (c == '>') {
+ if (buffer == null) {
+ buffer = new StringBuilder(string.substring(0, i));
+ }
+ buffer.append(">");
+ } else {
+ if (buffer != null) {
+ buffer.append(c);
+ }
+ }
+ }
+ return (buffer != null) ? buffer.toString() : string;
}
- public static String pluralize(String singularNoun) {
- String pluralNoun;
- if (singularNoun.endsWith("y") && !singularNoun.endsWith("ay") && !singularNoun.endsWith("ey")
- && !singularNoun.endsWith("oy")) {
- pluralNoun = singularNoun.substring(0, singularNoun.length() - 1) + "ies";
- } else if (!singularNoun.endsWith("s")) {
- pluralNoun = singularNoun + "s";
- } else {
- pluralNoun = singularNoun;
+ /**
+ * Sanitizes HTML (i.e. removes unsafe HTML such as SCRIPT tags) in a string to eliminate cross site scripting (XSS)
+ * vulnerabilities.
+ *
+ * @param string the string to be sanitized
+ *
+ * @return the sanitized string
+ */
+ // TODO (ips, 03/31/11): Replace this lame impl with a much more robust one - easiest way would be to upgrade to GWT
+ // 2.1 or later and use the new Safe HTML APIs. See also
+ // http://tomerdoron.blogspot.com/2011/03/less-simple-safe-html-sanitizer.html.
+ public static String sanitizeHtml(String string) {
+ if (string == null) {
+ return null;
}
- return pluralNoun;
+
+ return string.replaceAll("<script", "<script").replaceAll("<SCRIPT", "<SCRIPT");
}
private StringUtility() {
}
+
}
12 years, 8 months
[rhq] modules/enterprise
by mazz
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/detail/GeneralProperties.java | 6
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/detail/ResourceGroupTitleBar.java | 26
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/OverviewForm.java | 336 ++++++++++
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/ResourceErrorsDataSource.java | 106 +++
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/ResourceErrorsView.java | 189 +++++
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/ResourceTitleBar.java | 17
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/summary/OverviewForm.java | 333 ---------
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/summary/ResourceErrorsDataSource.java | 106 ---
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/summary/ResourceErrorsView.java | 189 -----
9 files changed, 665 insertions(+), 643 deletions(-)
New commits:
commit fec4fb5d697c886ca6ba8cb03b4686efedcb8815
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Thu Mar 31 16:55:59 2011 -0400
BZ 640396 - when you change the name of a resource or group, the title bar header name also changes now
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/detail/GeneralProperties.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/detail/GeneralProperties.java
index ba62aa4..fde8d13 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/detail/GeneralProperties.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/detail/GeneralProperties.java
@@ -54,10 +54,12 @@ import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableVLayout;
public class GeneralProperties extends LocatableVLayout {
private ResourceGroupGWTServiceAsync resourceGroupService = GWTServiceLookup.getResourceGroupService();
private ResourceGroupComposite groupComposite;
+ private final ResourceGroupTitleBar titleBar;
- public GeneralProperties(String locatorId, ResourceGroupComposite groupComposite) {
+ public GeneralProperties(String locatorId, ResourceGroupComposite groupComposite, ResourceGroupTitleBar titleBar) {
super(locatorId);
this.groupComposite = groupComposite;
+ this.titleBar = titleBar;
}
@Override
@@ -108,6 +110,8 @@ public class GeneralProperties extends LocatableVLayout {
}
public void onSuccess(Void result) {
+ titleBar.displayGroupName(newName);
+
CoreGUI.getMessageCenter().notify(
new Message(MSG.view_group_summary_nameUpdateSuccessful(String.valueOf(group
.getId()), oldName, newName), Message.Severity.Info));
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/detail/ResourceGroupTitleBar.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/detail/ResourceGroupTitleBar.java
index 26e826c..d8020f3 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/detail/ResourceGroupTitleBar.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/detail/ResourceGroupTitleBar.java
@@ -137,7 +137,8 @@ public class ResourceGroupTitleBar extends LocatableVLayout {
ResourceGroupComposite resultComposite = result.get(0);
setGroupIcons(resultComposite);
- generalProperties = new GeneralProperties(extendLocatorId("genProps"), resultComposite);
+ generalProperties = new GeneralProperties(extendLocatorId("genProps"), resultComposite,
+ ResourceGroupTitleBar.this);
generalProperties.setVisible(false);
ResourceGroupTitleBar.this.addMember(generalProperties);
expandCollapseArrow.addClickHandler(new ClickHandler() {
@@ -234,6 +235,21 @@ public class ResourceGroupTitleBar extends LocatableVLayout {
this.group = groupComposite.getResourceGroup();
update();
+ displayGroupName(group.getName());
+
+ Set<Integer> favorites = UserSessionManager.getUserPreferences().getFavoriteResourceGroups();
+ this.favorite = favorites.contains(group.getId());
+ updateFavoriteButton();
+
+ setGroupIcons(groupComposite);
+ markForRedraw();
+ }
+
+ void displayGroupName(String groupName) {
+ if (!group.getName().equals(groupName)) {
+ group.setName(groupName); // the name must have been changed by the user via the editable field
+ }
+
String catName = null;
switch (group.getGroupCategory()) {
case COMPATIBLE: {
@@ -248,13 +264,7 @@ public class ResourceGroupTitleBar extends LocatableVLayout {
this.title.setContents("<span class=\"SectionHeader\">" + group.getName()
+ "</span> <span class=\"subtitle\">" + catName + "</span>");
-
- Set<Integer> favorites = UserSessionManager.getUserPreferences().getFavoriteResourceGroups();
- this.favorite = favorites.contains(group.getId());
- updateFavoriteButton();
-
- setGroupIcons(groupComposite);
- markForRedraw();
+ this.title.markForRedraw();
}
private void setGroupIcons(ResourceGroupComposite groupComposite) {
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/OverviewForm.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/OverviewForm.java
new file mode 100644
index 0000000..7547339
--- /dev/null
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/OverviewForm.java
@@ -0,0 +1,336 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2010 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+package org.rhq.enterprise.gui.coregui.client.inventory.resource.detail;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.EnumSet;
+import java.util.List;
+
+import com.google.gwt.user.client.rpc.AsyncCallback;
+import com.smartgwt.client.widgets.form.fields.FormItem;
+import com.smartgwt.client.widgets.form.fields.HeaderItem;
+import com.smartgwt.client.widgets.form.fields.SpacerItem;
+import com.smartgwt.client.widgets.form.fields.StaticTextItem;
+
+import org.rhq.core.domain.measurement.DataType;
+import org.rhq.core.domain.measurement.DisplayType;
+import org.rhq.core.domain.measurement.MeasurementDataTrait;
+import org.rhq.core.domain.measurement.MeasurementDefinition;
+import org.rhq.core.domain.resource.Resource;
+import org.rhq.core.domain.resource.ResourceType;
+import org.rhq.core.domain.resource.composite.ResourceComposite;
+import org.rhq.enterprise.gui.coregui.client.CoreGUI;
+import org.rhq.enterprise.gui.coregui.client.components.form.EditableFormItem;
+import org.rhq.enterprise.gui.coregui.client.components.form.EnhancedDynamicForm;
+import org.rhq.enterprise.gui.coregui.client.components.form.StringLengthValidator;
+import org.rhq.enterprise.gui.coregui.client.components.form.EditableFormItem.ValueEditedHandler;
+import org.rhq.enterprise.gui.coregui.client.gwt.GWTServiceLookup;
+import org.rhq.enterprise.gui.coregui.client.gwt.ResourceGWTServiceAsync;
+import org.rhq.enterprise.gui.coregui.client.inventory.resource.AncestryUtil;
+import org.rhq.enterprise.gui.coregui.client.inventory.resource.type.ResourceTypeRepository;
+import org.rhq.enterprise.gui.coregui.client.util.message.Message;
+
+/**
+ * The Resource Summary>Overview tab - Resource general properties + summary traits.
+ *
+ * @author Greg Hinkle
+ * @author Ian Springer
+ */
+public class OverviewForm extends EnhancedDynamicForm {
+
+ private ResourceGWTServiceAsync resourceService = GWTServiceLookup.getResourceService();
+ private ResourceComposite resourceComposite;
+ private boolean headerEnabled = true;
+ private boolean displayCondensed = false;
+ private final ResourceTitleBar titleBar;
+
+ public OverviewForm(String locatorId, ResourceComposite resourceComposite, ResourceTitleBar titleBar) {
+ super(locatorId);
+ this.resourceComposite = resourceComposite;
+ this.titleBar = titleBar;
+ }
+
+ @Override
+ protected void onDraw() {
+ super.onDraw();
+
+ setLeft("10%");
+ setWidth("80%");
+ if (isDisplayCondensed()) {
+ setPadding(5);
+ setColWidths(150, 220, 150, 220);
+ setWidth("45%");
+ }
+
+ if (this.resourceComposite != null) {
+ setResource(this.resourceComposite);
+ }
+ }
+
+ public void setResource(ResourceComposite resourceComposite) {
+
+ this.resourceComposite = resourceComposite;
+ Resource resource = resourceComposite.getResource();
+
+ // Load metric defs.
+ ResourceTypeRepository.Cache.getInstance().getResourceTypes(resource.getResourceType().getId(),
+ EnumSet.of(ResourceTypeRepository.MetadataType.measurements),
+ new ResourceTypeRepository.TypeLoadedCallback() {
+ public void onTypesLoaded(ResourceType type) {
+ buildForm(type);
+ loadTraitValues();
+ }
+ });
+ }
+
+ private void loadTraitValues() {
+ final Resource resource = resourceComposite.getResource();
+ GWTServiceLookup.getMeasurementDataService().findCurrentTraitsForResource(resource.getId(),
+ DisplayType.SUMMARY, new AsyncCallback<List<MeasurementDataTrait>>() {
+ public void onFailure(Throwable caught) {
+ CoreGUI.getErrorHandler().handleError(
+ MSG.view_summaryOverviewForm_error_traitsLoadFailure(resource.toString()), caught);
+ }
+
+ public void onSuccess(List<MeasurementDataTrait> result) {
+ for (MeasurementDataTrait trait : result) {
+ String formItemId = buildFormItemIdFromTraitDisplayName(trait.getName());
+ FormItem item = getItem(formItemId);
+ if (item != null) {
+ setValue(formItemId, trait.getValue());
+ }
+ }
+ markForRedraw();
+ }
+ });
+ }
+
+ private static String buildFormItemIdFromTraitDisplayName(String traitName) {
+ return traitName.replaceAll("\\.", "_").replaceAll(" ", "__");
+ }
+
+ private void buildForm(ResourceType type) {
+ List<MeasurementDefinition> traits = new ArrayList<MeasurementDefinition>();
+
+ for (MeasurementDefinition measurement : type.getMetricDefinitions()) {
+ if (measurement.getDataType() == DataType.TRAIT && measurement.getDisplayType() == DisplayType.SUMMARY) {
+ traits.add(measurement);
+ }
+ }
+
+ StringLengthValidator notEmptyOrNullValidator = new StringLengthValidator(1, null, false);
+ StringLengthValidator notNullValidator = new StringLengthValidator(null, null, false);
+
+ List<FormItem> formItems = new ArrayList<FormItem>();
+
+ if (isHeaderEnabled()) {//conditionally display header
+ HeaderItem headerItem = new HeaderItem("header", MSG.view_summaryOverviewForm_header_summary());
+ headerItem.setValue(MSG.view_summaryOverviewForm_header_summary());
+ formItems.add(headerItem);
+ }
+
+ // Type
+ StaticTextItem typeItem = new StaticTextItem("type", MSG.view_summaryOverviewForm_field_type());
+ typeItem.setTooltip(MSG.view_summaryOverviewForm_label_plugin() + type.getPlugin() + "\n<br>"
+ + MSG.view_summaryOverviewForm_label_type() + type.getName());
+ typeItem.setValue(AncestryUtil.getFormattedType(type));
+ formItems.add(typeItem);
+
+ final Resource resource = this.resourceComposite.getResource();
+ boolean modifiable = this.resourceComposite.getResourcePermission().isInventory();
+
+ // Name
+ final FormItem nameItem = (modifiable) ? new EditableFormItem() : new StaticTextItem();
+ nameItem.setName("name");
+ nameItem.setTitle(MSG.view_summaryOverviewForm_field_name());
+ nameItem.setValue(resource.getName());
+ if (nameItem instanceof EditableFormItem) {
+ EditableFormItem togglableNameItem = (EditableFormItem) nameItem;
+ togglableNameItem.setValidators(notEmptyOrNullValidator);
+ togglableNameItem.setValueEditedHandler(new ValueEditedHandler() {
+ public void editedValue(Object newValue) {
+ final String newName = newValue.toString();
+ final String oldName = resource.getName();
+ if (newName.equals(oldName)) {
+ return;
+ }
+ resource.setName(newName);
+ OverviewForm.this.resourceService.updateResource(resource, new AsyncCallback<Void>() {
+ public void onFailure(Throwable caught) {
+ CoreGUI.getErrorHandler().handleError(
+ MSG.view_summaryOverviewForm_error_nameChangeFailure(String.valueOf(resource.getId()),
+ oldName, newName), caught);
+ // We failed to update it on the Server, so change back the Resource and the form item to
+ // the original value.
+ resource.setName(oldName);
+ nameItem.setValue(oldName);
+ }
+
+ public void onSuccess(Void result) {
+ titleBar.displayResourceName(newName);
+ CoreGUI.getMessageCenter().notify(
+ new Message(MSG.view_summaryOverviewForm_message_nameChangeSuccess(String
+ .valueOf(resource.getId()), oldName, newName), Message.Severity.Info));
+ }
+ });
+ }
+ });
+ }
+ formItems.add(nameItem);
+
+ // Description
+ final FormItem descriptionItem = (modifiable) ? new EditableFormItem() : new StaticTextItem();
+ descriptionItem.setName("description");
+ descriptionItem.setTitle(MSG.view_summaryOverviewForm_field_description());
+ descriptionItem.setValue(resource.getDescription());
+ if (descriptionItem instanceof EditableFormItem) {
+ EditableFormItem togglableDescriptionItem = (EditableFormItem) descriptionItem;
+ togglableDescriptionItem.setValidators(notNullValidator);
+ togglableDescriptionItem.setValueEditedHandler(new ValueEditedHandler() {
+ public void editedValue(Object newValue) {
+ final String newDescription = newValue.toString();
+ final String oldDescription = resource.getDescription();
+ if (newDescription.equals(oldDescription)) {
+ return;
+ }
+ resource.setDescription(newDescription);
+ OverviewForm.this.resourceService.updateResource(resource, new AsyncCallback<Void>() {
+ public void onFailure(Throwable caught) {
+ CoreGUI.getErrorHandler().handleError(
+ MSG.view_summaryOverviewForm_error_descriptionChangeFailure(String.valueOf(resource
+ .getId()), oldDescription, newDescription), caught);
+ // We failed to update it on the Server, so change back the Resource and the form item to
+ // the original value.
+ resource.setDescription(oldDescription);
+ descriptionItem.setValue(oldDescription);
+ }
+
+ public void onSuccess(Void result) {
+ CoreGUI.getMessageCenter()
+ .notify(
+ new Message(MSG.view_summaryOverviewForm_message_nameChangeSuccess(String
+ .valueOf(resource.getId()), oldDescription, newDescription),
+ Message.Severity.Info));
+ }
+ });
+ }
+ });
+ }
+ formItems.add(descriptionItem);
+
+ // Location
+ final FormItem locationItem = (modifiable) ? new EditableFormItem() : new StaticTextItem();
+ locationItem.setName("location");
+ locationItem.setTitle(MSG.view_summaryOverviewForm_field_location());
+ locationItem.setValue(resource.getLocation());
+ if (locationItem instanceof EditableFormItem) {
+ EditableFormItem togglableLocationItem = (EditableFormItem) locationItem;
+ togglableLocationItem.setValidators(notNullValidator);
+ togglableLocationItem.setValueEditedHandler(new ValueEditedHandler() {
+ public void editedValue(Object newValue) {
+ final String newLocation = newValue.toString();
+ final String oldLocation = resource.getLocation();
+ if (newLocation.equals(oldLocation)) {
+ return;
+ }
+ resource.setLocation(newLocation);
+ OverviewForm.this.resourceService.updateResource(resource, new AsyncCallback<Void>() {
+ public void onFailure(Throwable caught) {
+ CoreGUI.getErrorHandler().handleError(
+ MSG.view_summaryOverviewForm_error_locationChangeFailure(String.valueOf(resource
+ .getId()), oldLocation, newLocation), caught);
+ // We failed to update it on the Server, so change back the Resource and the form item to
+ // the original value.
+ resource.setLocation(oldLocation);
+ locationItem.setValue(oldLocation);
+ }
+
+ public void onSuccess(Void result) {
+ CoreGUI.getMessageCenter().notify(
+ new Message(MSG.view_summaryOverviewForm_message_nameChangeSuccess(String
+ .valueOf(resource.getId()), oldLocation, newLocation), Message.Severity.Info));
+ }
+ });
+ }
+ });
+ }
+ formItems.add(locationItem);
+
+ // Version
+ StaticTextItem versionItem = new StaticTextItem("version", MSG.view_summaryOverviewForm_field_version());
+ versionItem.setValue((resource.getVersion() != null) ? resource.getVersion() : "<i>" + MSG.common_label_none()
+ + "</i>");
+ versionItem.setEndRow(true);
+ formItems.add(versionItem);
+
+ // Traits
+ Collections.sort(traits, new Comparator<MeasurementDefinition>() {
+ public int compare(MeasurementDefinition o1, MeasurementDefinition o2) {
+ return new Integer(o1.getDisplayOrder()).compareTo(o2.getDisplayOrder());
+ }
+ });
+
+ for (MeasurementDefinition trait : traits) {
+ String formItemId = buildFormItemIdFromTraitDisplayName(trait.getDisplayName());
+ StaticTextItem formItem = new StaticTextItem(formItemId, trait.getDisplayName());
+ formItem.setTooltip(trait.getDescription());
+ formItems.add(formItem);
+ // item.setValue("?");
+ }
+
+ // SectionItem section = new SectionItem("Summary", "Summary");
+ // section.setTitle("Summary");
+ // section.setDefaultValue("Summary");
+ // section.setCanCollapse(true);
+ // section.setCellStyle("HidablePlainSectionHeader");
+ // section.setItemIds(itemIds.toArray(new String[itemIds.size()]));
+ // formItems.add(0, section);
+ if (!isDisplayCondensed()) {
+ formItems.add(new SpacerItem());
+ }
+
+ setItems(formItems.toArray(new FormItem[formItems.size()]));
+ }
+
+ public void loadData() {
+ // TODO: Reload the ResourceComposite too.
+ loadTraitValues();
+ markForRedraw();
+ }
+
+ public boolean isHeaderEnabled() {
+ return headerEnabled;
+ }
+
+ public void setHeaderEnabled(boolean headerEnabled) {
+ this.headerEnabled = headerEnabled;
+ }
+
+ public boolean isDisplayCondensed() {
+ return displayCondensed;
+ }
+
+ public void setDisplayCondensed(boolean displayCondensed) {
+ this.displayCondensed = displayCondensed;
+ }
+
+}
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/ResourceErrorsDataSource.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/ResourceErrorsDataSource.java
new file mode 100644
index 0000000..0b8f830
--- /dev/null
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/ResourceErrorsDataSource.java
@@ -0,0 +1,106 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2010 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+package org.rhq.enterprise.gui.coregui.client.inventory.resource.detail;
+
+import java.util.Date;
+import java.util.List;
+
+import com.google.gwt.user.client.rpc.AsyncCallback;
+import com.smartgwt.client.data.DSRequest;
+import com.smartgwt.client.data.DSResponse;
+import com.smartgwt.client.data.DataSourceField;
+import com.smartgwt.client.data.Record;
+import com.smartgwt.client.rpc.RPCResponse;
+import com.smartgwt.client.widgets.grid.ListGridRecord;
+
+import org.rhq.core.domain.criteria.Criteria;
+import org.rhq.core.domain.resource.ResourceError;
+import org.rhq.enterprise.gui.coregui.client.CoreGUI;
+import org.rhq.enterprise.gui.coregui.client.gwt.GWTServiceLookup;
+import org.rhq.enterprise.gui.coregui.client.gwt.ResourceGWTServiceAsync;
+import org.rhq.enterprise.gui.coregui.client.util.RPCDataSource;
+
+/**
+ * @author Lukas Krejci
+ * @author Simeon Pinder
+ * @author John Mazzitelli
+ */
+public class ResourceErrorsDataSource extends RPCDataSource<ResourceError, Criteria> {
+
+ public static abstract class Field {
+ public static final String ID = "id";
+ public static final String SUMMARY = "summary";
+ public static final String DETAIL = "detail";
+ public static final String ERROR_TYPE = "errorType";
+ public static final String TIME_OCCURED = "timeOccured";
+ }
+
+ ResourceGWTServiceAsync resourceService;
+ int resourceId;
+
+ public ResourceErrorsDataSource(int resourceId) {
+ resourceService = GWTServiceLookup.getResourceService();
+ this.resourceId = resourceId;
+ List<DataSourceField> fields = addDataSourceFields();
+ addFields(fields);
+ }
+
+ @Override
+ protected void executeFetch(final DSRequest request, final DSResponse response, final Criteria unused) {
+ resourceService.findResourceErrors(resourceId, new AsyncCallback<List<ResourceError>>() {
+ public void onFailure(Throwable caught) {
+ CoreGUI.getErrorHandler().handleError(
+ MSG.dataSource_resourceErrors_error_fetchFailure(String.valueOf(resourceId)), caught);
+ response.setStatus(RPCResponse.STATUS_FAILURE);
+ processResponse(request.getRequestId(), response);
+ }
+
+ public void onSuccess(List<ResourceError> result) {
+ response.setData(buildRecords(result));
+ processResponse(request.getRequestId(), response);
+ }
+ });
+ }
+
+ @Override
+ protected Criteria getFetchCriteria(DSRequest request) {
+ // we don't use criterias for this datasource, just return null
+ return null;
+ }
+
+ @Override
+ public ResourceError copyValues(Record from) {
+ //This is read-only datasource, so no need to implement this.
+ return null;
+ }
+
+ @Override
+ public ListGridRecord copyValues(ResourceError from) {
+ ListGridRecord record = new ListGridRecord();
+
+ record.setAttribute(Field.ID, from.getId());
+ record.setAttribute(Field.DETAIL, from.getDetail());
+ record.setAttribute(Field.ERROR_TYPE, from.getErrorType().name());
+ record.setAttribute(Field.SUMMARY, from.getSummary());
+ record.setAttribute(Field.TIME_OCCURED, new Date(from.getTimeOccurred()));
+
+ return record;
+ }
+}
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/ResourceErrorsView.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/ResourceErrorsView.java
new file mode 100644
index 0000000..c881819
--- /dev/null
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/ResourceErrorsView.java
@@ -0,0 +1,189 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2011 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+package org.rhq.enterprise.gui.coregui.client.inventory.resource.detail;
+
+import com.google.gwt.user.client.rpc.AsyncCallback;
+import com.smartgwt.client.data.Criteria;
+import com.smartgwt.client.types.Alignment;
+import com.smartgwt.client.types.AutoFitWidthApproach;
+import com.smartgwt.client.types.ListGridFieldType;
+import com.smartgwt.client.types.Overflow;
+import com.smartgwt.client.types.SelectionStyle;
+import com.smartgwt.client.widgets.Window;
+import com.smartgwt.client.widgets.events.CloseClickHandler;
+import com.smartgwt.client.widgets.events.CloseClientEvent;
+import com.smartgwt.client.widgets.events.DoubleClickEvent;
+import com.smartgwt.client.widgets.events.DoubleClickHandler;
+import com.smartgwt.client.widgets.grid.HoverCustomizer;
+import com.smartgwt.client.widgets.grid.ListGrid;
+import com.smartgwt.client.widgets.grid.ListGridField;
+import com.smartgwt.client.widgets.grid.ListGridRecord;
+import com.smartgwt.client.widgets.grid.events.RecordClickEvent;
+import com.smartgwt.client.widgets.grid.events.RecordClickHandler;
+
+import org.rhq.enterprise.gui.coregui.client.CoreGUI;
+import org.rhq.enterprise.gui.coregui.client.components.table.AbstractTableAction;
+import org.rhq.enterprise.gui.coregui.client.components.table.Table;
+import org.rhq.enterprise.gui.coregui.client.components.table.TableActionEnablement;
+import org.rhq.enterprise.gui.coregui.client.components.table.TimestampCellFormatter;
+import org.rhq.enterprise.gui.coregui.client.gwt.GWTServiceLookup;
+import org.rhq.enterprise.gui.coregui.client.inventory.resource.detail.ResourceErrorsDataSource.Field;
+import org.rhq.enterprise.gui.coregui.client.util.message.Message;
+import org.rhq.enterprise.gui.coregui.client.util.message.Message.Severity;
+import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableHTMLPane;
+import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableWindow;
+
+public class ResourceErrorsView extends Table<ResourceErrorsDataSource> {
+ private static final String ERROR_ICON = "[SKIN]/Dialog/warn.png";
+
+ public ResourceErrorsView(String locatorId, String string, Criteria criteria, Object object, String[] strings) {
+ super(locatorId, MSG.common_title_component_errors(), criteria);
+ setWidth100();
+ setHeight100();
+ setShowHeader(false);
+ }
+
+ @Override
+ protected SelectionStyle getDefaultSelectionStyle() {
+ return SelectionStyle.MULTIPLE;
+ }
+
+ @Override
+ protected void configureTable() {
+ ListGridField errorTypeField = new ListGridField(Field.ERROR_TYPE, MSG
+ .dataSource_resourceErrors_field_errorType());
+ errorTypeField.setAlign(Alignment.CENTER);
+ errorTypeField.setAutoFitWidth(true);
+ errorTypeField.setAutoFitWidthApproach(AutoFitWidthApproach.BOTH);
+
+ ListGridField timeField = new ListGridField(Field.TIME_OCCURED, MSG
+ .dataSource_resourceErrors_field_timeOccured());
+ timeField.setType(ListGridFieldType.DATE);
+ timeField.setAlign(Alignment.CENTER);
+ timeField.setWidth("20%");
+ TimestampCellFormatter.prepareDateField(timeField);
+
+ ListGridField summaryField = new ListGridField(Field.SUMMARY, MSG.dataSource_resourceErrors_field_summary());
+ summaryField.setAlign(Alignment.CENTER);
+ summaryField.setCellAlign(Alignment.LEFT);
+ summaryField.setWidth("*");
+
+ ListGridField iconField = new ListGridField("icon");
+ iconField.setType(ListGridFieldType.ICON);
+ iconField.setAlign(Alignment.CENTER);
+ iconField.setIcon(ERROR_ICON);
+ iconField.setCellIcon(ERROR_ICON);
+ iconField.setWidth("50");
+ iconField.setCanSort(false);
+ iconField.addRecordClickHandler(new RecordClickHandler() {
+ @Override
+ public void onRecordClick(RecordClickEvent event) {
+ String details = event.getRecord().getAttribute(Field.DETAIL);
+ popupDetails(details);
+ }
+ });
+ iconField.setShowHover(true);
+ iconField.setHoverCustomizer(new HoverCustomizer() {
+ @Override
+ public String hoverHTML(Object value, ListGridRecord record, int rowNum, int colNum) {
+ String html = record.getAttribute(Field.DETAIL);
+ if (html.length() > 80) {
+ // this was probably an error stack trace, snip it so the tooltip isn't too big
+ html = "<pre>" + html.substring(0, 80) + "...</pre><p>"
+ + MSG.dataSource_resourceErrors_clickStatusIcon() + "</p>";
+ }
+ return html;
+ }
+ });
+
+ setListGridDoubleClickHandler(new DoubleClickHandler() {
+ @Override
+ public void onDoubleClick(DoubleClickEvent event) {
+ ListGrid listGrid = (ListGrid) event.getSource();
+ ListGridRecord[] selectedRows = listGrid.getSelection();
+ if (selectedRows != null && selectedRows.length > 0) {
+ String details = selectedRows[0].getAttribute(Field.DETAIL);
+ popupDetails(details);
+ }
+ }
+ });
+
+ setListGridFields(errorTypeField, timeField, summaryField, iconField);
+
+ addTableAction(extendLocatorId("delete"), MSG.common_button_delete(), MSG.common_msg_areYouSure(),
+ new AbstractTableAction(TableActionEnablement.ANY) {
+ @Override
+ public void executeAction(final ListGridRecord[] selection, Object actionValue) {
+ if (selection == null || selection.length == 0) {
+ return;
+ }
+ int[] resourceErrorIds = new int[selection.length];
+ int i = 0;
+ for (ListGridRecord record : selection) {
+ resourceErrorIds[i++] = record.getAttributeAsInt(Field.ID);
+ }
+ GWTServiceLookup.getResourceService().deleteResourceErrors(resourceErrorIds,
+ new AsyncCallback<Void>() {
+ @Override
+ public void onSuccess(Void result) {
+ Message msg = new Message(MSG.dataSource_resourceErrors_deleteSuccess(String
+ .valueOf(selection.length)), Severity.Info);
+ CoreGUI.getMessageCenter().notify(msg);
+ refresh();
+ }
+
+ @Override
+ public void onFailure(Throwable caught) {
+ CoreGUI.getErrorHandler().handleError(MSG.dataSource_resourceErrors_deleteFailure(),
+ caught);
+ }
+ });
+ }
+ });
+ }
+
+ private void popupDetails(String details) {
+ final Window winModal = new LocatableWindow(extendLocatorId("errorDetailsWin"));
+ winModal.setTitle(MSG.common_title_component_errors());
+ winModal.setOverflow(Overflow.VISIBLE);
+ winModal.setShowMinimizeButton(false);
+ winModal.setShowMaximizeButton(true);
+ winModal.setIsModal(true);
+ winModal.setShowModalMask(true);
+ winModal.setAutoSize(true);
+ winModal.setAutoCenter(true);
+ winModal.setShowResizer(true);
+ winModal.setCanDragResize(true);
+ winModal.centerInPage();
+ winModal.addCloseClickHandler(new CloseClickHandler() {
+ @Override
+ public void onCloseClick(CloseClientEvent event) {
+ winModal.markForDestroy();
+ }
+ });
+
+ LocatableHTMLPane htmlPane = new LocatableHTMLPane(extendLocatorId("errorDetailsPane"));
+ htmlPane.setMargin(10);
+ htmlPane.setDefaultWidth(700);
+ htmlPane.setDefaultHeight(500);
+ htmlPane.setContents("<pre>" + details + "</pre>");
+ winModal.addItem(htmlPane);
+ winModal.show();
+ }
+}
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/ResourceTitleBar.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/ResourceTitleBar.java
index 7bc1cdd..bd86104 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/ResourceTitleBar.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/ResourceTitleBar.java
@@ -49,9 +49,6 @@ import org.rhq.enterprise.gui.coregui.client.UserSessionManager;
import org.rhq.enterprise.gui.coregui.client.components.tagging.TagEditorView;
import org.rhq.enterprise.gui.coregui.client.components.tagging.TagsChangedCallback;
import org.rhq.enterprise.gui.coregui.client.gwt.GWTServiceLookup;
-import org.rhq.enterprise.gui.coregui.client.inventory.resource.detail.summary.OverviewForm;
-import org.rhq.enterprise.gui.coregui.client.inventory.resource.detail.summary.ResourceErrorsDataSource;
-import org.rhq.enterprise.gui.coregui.client.inventory.resource.detail.summary.ResourceErrorsView;
import org.rhq.enterprise.gui.coregui.client.util.message.Message;
import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableHLayout;
import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableImg;
@@ -243,7 +240,7 @@ public class ResourceTitleBar extends LocatableVLayout {
detailsForm.setHeight(10);
detailsForm.setAlign(Alignment.LEFT);
- detailsFormSummary = new OverviewForm(extendLocatorId("Title_Optional_Summary"), resourceComposite);
+ detailsFormSummary = new OverviewForm(extendLocatorId("Title_Optional_Summary"), resourceComposite, this);
detailsFormSummary.setWidth100();
detailsFormSummary.setPadding(3);
detailsFormSummary.setMargin(3);
@@ -294,8 +291,7 @@ public class ResourceTitleBar extends LocatableVLayout {
this.resourceComposite = resourceComposite;
update();
- this.title.setContents("<span class=\"SectionHeader\">" + resource.getName()
- + "</span> <span class=\"subtitle\">" + resource.getResourceType().getName() + "</span>");
+ displayResourceName(resource.getName());
Set<Integer> favorites = UserSessionManager.getUserPreferences().getFavoriteResources();
this.favorite = favorites.contains(resource.getId());
@@ -310,6 +306,15 @@ public class ResourceTitleBar extends LocatableVLayout {
}
}
+ void displayResourceName(String resourceName) {
+ if (!resource.getName().equals(resourceName)) {
+ resource.setName(resourceName); // the name must have been changed by the user via the editable field
+ }
+ this.title.setContents("<span class=\"SectionHeader\">" + resource.getName()
+ + "</span> <span class=\"subtitle\">" + resource.getResourceType().getName() + "</span>");
+ this.title.markForRedraw();
+ }
+
private void updateFavoriteButton() {
this.favoriteButton.setSrc(favorite ? FAV_ICON : NOT_FAV_ICON);
if (favorite) {
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/summary/OverviewForm.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/summary/OverviewForm.java
deleted file mode 100644
index 3cecbe9..0000000
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/summary/OverviewForm.java
+++ /dev/null
@@ -1,333 +0,0 @@
-/*
- * RHQ Management Platform
- * Copyright (C) 2005-2010 Red Hat, Inc.
- * All rights reserved.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation version 2 of the License.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
-package org.rhq.enterprise.gui.coregui.client.inventory.resource.detail.summary;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.EnumSet;
-import java.util.List;
-
-import com.google.gwt.user.client.rpc.AsyncCallback;
-import com.smartgwt.client.widgets.form.fields.FormItem;
-import com.smartgwt.client.widgets.form.fields.HeaderItem;
-import com.smartgwt.client.widgets.form.fields.SpacerItem;
-import com.smartgwt.client.widgets.form.fields.StaticTextItem;
-
-import org.rhq.core.domain.measurement.DataType;
-import org.rhq.core.domain.measurement.DisplayType;
-import org.rhq.core.domain.measurement.MeasurementDataTrait;
-import org.rhq.core.domain.measurement.MeasurementDefinition;
-import org.rhq.core.domain.resource.Resource;
-import org.rhq.core.domain.resource.ResourceType;
-import org.rhq.core.domain.resource.composite.ResourceComposite;
-import org.rhq.enterprise.gui.coregui.client.CoreGUI;
-import org.rhq.enterprise.gui.coregui.client.components.form.EditableFormItem;
-import org.rhq.enterprise.gui.coregui.client.components.form.EnhancedDynamicForm;
-import org.rhq.enterprise.gui.coregui.client.components.form.StringLengthValidator;
-import org.rhq.enterprise.gui.coregui.client.components.form.EditableFormItem.ValueEditedHandler;
-import org.rhq.enterprise.gui.coregui.client.gwt.GWTServiceLookup;
-import org.rhq.enterprise.gui.coregui.client.gwt.ResourceGWTServiceAsync;
-import org.rhq.enterprise.gui.coregui.client.inventory.resource.AncestryUtil;
-import org.rhq.enterprise.gui.coregui.client.inventory.resource.type.ResourceTypeRepository;
-import org.rhq.enterprise.gui.coregui.client.util.message.Message;
-
-/**
- * The Resource Summary>Overview tab - Resource general properties + summary traits.
- *
- * @author Greg Hinkle
- * @author Ian Springer
- */
-public class OverviewForm extends EnhancedDynamicForm {
-
- private ResourceGWTServiceAsync resourceService = GWTServiceLookup.getResourceService();
- private ResourceComposite resourceComposite;
- private boolean headerEnabled = true;
- private boolean displayCondensed = false;
-
- public OverviewForm(String locatorId, ResourceComposite resourceComposite) {
- super(locatorId);
- this.resourceComposite = resourceComposite;
- }
-
- @Override
- protected void onDraw() {
- super.onDraw();
-
- setLeft("10%");
- setWidth("80%");
- if (isDisplayCondensed()) {
- setPadding(5);
- setColWidths(150, 220, 150, 220);
- setWidth("45%");
- }
-
- if (this.resourceComposite != null) {
- setResource(this.resourceComposite);
- }
- }
-
- public void setResource(ResourceComposite resourceComposite) {
-
- this.resourceComposite = resourceComposite;
- Resource resource = resourceComposite.getResource();
-
- // Load metric defs.
- ResourceTypeRepository.Cache.getInstance().getResourceTypes(resource.getResourceType().getId(),
- EnumSet.of(ResourceTypeRepository.MetadataType.measurements),
- new ResourceTypeRepository.TypeLoadedCallback() {
- public void onTypesLoaded(ResourceType type) {
- buildForm(type);
- loadTraitValues();
- }
- });
- }
-
- private void loadTraitValues() {
- final Resource resource = resourceComposite.getResource();
- GWTServiceLookup.getMeasurementDataService().findCurrentTraitsForResource(resource.getId(),
- DisplayType.SUMMARY, new AsyncCallback<List<MeasurementDataTrait>>() {
- public void onFailure(Throwable caught) {
- CoreGUI.getErrorHandler().handleError(
- MSG.view_summaryOverviewForm_error_traitsLoadFailure(resource.toString()), caught);
- }
-
- public void onSuccess(List<MeasurementDataTrait> result) {
- for (MeasurementDataTrait trait : result) {
- String formItemId = buildFormItemIdFromTraitDisplayName(trait.getName());
- FormItem item = getItem(formItemId);
- if (item != null) {
- setValue(formItemId, trait.getValue());
- }
- }
- markForRedraw();
- }
- });
- }
-
- private static String buildFormItemIdFromTraitDisplayName(String traitName) {
- return traitName.replaceAll("\\.", "_").replaceAll(" ", "__");
- }
-
- private void buildForm(ResourceType type) {
- List<MeasurementDefinition> traits = new ArrayList<MeasurementDefinition>();
-
- for (MeasurementDefinition measurement : type.getMetricDefinitions()) {
- if (measurement.getDataType() == DataType.TRAIT && measurement.getDisplayType() == DisplayType.SUMMARY) {
- traits.add(measurement);
- }
- }
-
- StringLengthValidator notEmptyOrNullValidator = new StringLengthValidator(1, null, false);
- StringLengthValidator notNullValidator = new StringLengthValidator(null, null, false);
-
- List<FormItem> formItems = new ArrayList<FormItem>();
-
- if (isHeaderEnabled()) {//conditionally display header
- HeaderItem headerItem = new HeaderItem("header", MSG.view_summaryOverviewForm_header_summary());
- headerItem.setValue(MSG.view_summaryOverviewForm_header_summary());
- formItems.add(headerItem);
- }
-
- // Type
- StaticTextItem typeItem = new StaticTextItem("type", MSG.view_summaryOverviewForm_field_type());
- typeItem.setTooltip(MSG.view_summaryOverviewForm_label_plugin() + type.getPlugin() + "\n<br>"
- + MSG.view_summaryOverviewForm_label_type() + type.getName());
- typeItem.setValue(AncestryUtil.getFormattedType(type));
- formItems.add(typeItem);
-
- final Resource resource = this.resourceComposite.getResource();
- boolean modifiable = this.resourceComposite.getResourcePermission().isInventory();
-
- // Name
- final FormItem nameItem = (modifiable) ? new EditableFormItem() : new StaticTextItem();
- nameItem.setName("name");
- nameItem.setTitle(MSG.view_summaryOverviewForm_field_name());
- nameItem.setValue(resource.getName());
- if (nameItem instanceof EditableFormItem) {
- EditableFormItem togglableNameItem = (EditableFormItem) nameItem;
- togglableNameItem.setValidators(notEmptyOrNullValidator);
- togglableNameItem.setValueEditedHandler(new ValueEditedHandler() {
- public void editedValue(Object newValue) {
- final String newName = newValue.toString();
- final String oldName = resource.getName();
- if (newName.equals(oldName)) {
- return;
- }
- resource.setName(newName);
- OverviewForm.this.resourceService.updateResource(resource, new AsyncCallback<Void>() {
- public void onFailure(Throwable caught) {
- CoreGUI.getErrorHandler().handleError(
- MSG.view_summaryOverviewForm_error_nameChangeFailure(String.valueOf(resource.getId()),
- oldName, newName), caught);
- // We failed to update it on the Server, so change back the Resource and the form item to
- // the original value.
- resource.setName(oldName);
- nameItem.setValue(oldName);
- }
-
- public void onSuccess(Void result) {
- CoreGUI.getMessageCenter().notify(
- new Message(MSG.view_summaryOverviewForm_message_nameChangeSuccess(String
- .valueOf(resource.getId()), oldName, newName), Message.Severity.Info));
- }
- });
- }
- });
- }
- formItems.add(nameItem);
-
- // Description
- final FormItem descriptionItem = (modifiable) ? new EditableFormItem() : new StaticTextItem();
- descriptionItem.setName("description");
- descriptionItem.setTitle(MSG.view_summaryOverviewForm_field_description());
- descriptionItem.setValue(resource.getDescription());
- if (descriptionItem instanceof EditableFormItem) {
- EditableFormItem togglableDescriptionItem = (EditableFormItem) descriptionItem;
- togglableDescriptionItem.setValidators(notNullValidator);
- togglableDescriptionItem.setValueEditedHandler(new ValueEditedHandler() {
- public void editedValue(Object newValue) {
- final String newDescription = newValue.toString();
- final String oldDescription = resource.getDescription();
- if (newDescription.equals(oldDescription)) {
- return;
- }
- resource.setDescription(newDescription);
- OverviewForm.this.resourceService.updateResource(resource, new AsyncCallback<Void>() {
- public void onFailure(Throwable caught) {
- CoreGUI.getErrorHandler().handleError(
- MSG.view_summaryOverviewForm_error_descriptionChangeFailure(String.valueOf(resource
- .getId()), oldDescription, newDescription), caught);
- // We failed to update it on the Server, so change back the Resource and the form item to
- // the original value.
- resource.setDescription(oldDescription);
- descriptionItem.setValue(oldDescription);
- }
-
- public void onSuccess(Void result) {
- CoreGUI.getMessageCenter()
- .notify(
- new Message(MSG.view_summaryOverviewForm_message_nameChangeSuccess(String
- .valueOf(resource.getId()), oldDescription, newDescription),
- Message.Severity.Info));
- }
- });
- }
- });
- }
- formItems.add(descriptionItem);
-
- // Location
- final FormItem locationItem = (modifiable) ? new EditableFormItem() : new StaticTextItem();
- locationItem.setName("location");
- locationItem.setTitle(MSG.view_summaryOverviewForm_field_location());
- locationItem.setValue(resource.getLocation());
- if (locationItem instanceof EditableFormItem) {
- EditableFormItem togglableLocationItem = (EditableFormItem) locationItem;
- togglableLocationItem.setValidators(notNullValidator);
- togglableLocationItem.setValueEditedHandler(new ValueEditedHandler() {
- public void editedValue(Object newValue) {
- final String newLocation = newValue.toString();
- final String oldLocation = resource.getLocation();
- if (newLocation.equals(oldLocation)) {
- return;
- }
- resource.setLocation(newLocation);
- OverviewForm.this.resourceService.updateResource(resource, new AsyncCallback<Void>() {
- public void onFailure(Throwable caught) {
- CoreGUI.getErrorHandler().handleError(
- MSG.view_summaryOverviewForm_error_locationChangeFailure(String.valueOf(resource
- .getId()), oldLocation, newLocation), caught);
- // We failed to update it on the Server, so change back the Resource and the form item to
- // the original value.
- resource.setLocation(oldLocation);
- locationItem.setValue(oldLocation);
- }
-
- public void onSuccess(Void result) {
- CoreGUI.getMessageCenter().notify(
- new Message(MSG.view_summaryOverviewForm_message_nameChangeSuccess(String
- .valueOf(resource.getId()), oldLocation, newLocation), Message.Severity.Info));
- }
- });
- }
- });
- }
- formItems.add(locationItem);
-
- // Version
- StaticTextItem versionItem = new StaticTextItem("version", MSG.view_summaryOverviewForm_field_version());
- versionItem.setValue((resource.getVersion() != null) ? resource.getVersion() : "<i>" + MSG.common_label_none()
- + "</i>");
- versionItem.setEndRow(true);
- formItems.add(versionItem);
-
- // Traits
- Collections.sort(traits, new Comparator<MeasurementDefinition>() {
- public int compare(MeasurementDefinition o1, MeasurementDefinition o2) {
- return new Integer(o1.getDisplayOrder()).compareTo(o2.getDisplayOrder());
- }
- });
-
- for (MeasurementDefinition trait : traits) {
- String formItemId = buildFormItemIdFromTraitDisplayName(trait.getDisplayName());
- StaticTextItem formItem = new StaticTextItem(formItemId, trait.getDisplayName());
- formItem.setTooltip(trait.getDescription());
- formItems.add(formItem);
- // item.setValue("?");
- }
-
- // SectionItem section = new SectionItem("Summary", "Summary");
- // section.setTitle("Summary");
- // section.setDefaultValue("Summary");
- // section.setCanCollapse(true);
- // section.setCellStyle("HidablePlainSectionHeader");
- // section.setItemIds(itemIds.toArray(new String[itemIds.size()]));
- // formItems.add(0, section);
- if (!isDisplayCondensed()) {
- formItems.add(new SpacerItem());
- }
-
- setItems(formItems.toArray(new FormItem[formItems.size()]));
- }
-
- public void loadData() {
- // TODO: Reload the ResourceComposite too.
- loadTraitValues();
- markForRedraw();
- }
-
- public boolean isHeaderEnabled() {
- return headerEnabled;
- }
-
- public void setHeaderEnabled(boolean headerEnabled) {
- this.headerEnabled = headerEnabled;
- }
-
- public boolean isDisplayCondensed() {
- return displayCondensed;
- }
-
- public void setDisplayCondensed(boolean displayCondensed) {
- this.displayCondensed = displayCondensed;
- }
-
-}
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/summary/ResourceErrorsDataSource.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/summary/ResourceErrorsDataSource.java
deleted file mode 100644
index be76956..0000000
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/summary/ResourceErrorsDataSource.java
+++ /dev/null
@@ -1,106 +0,0 @@
-/*
- * RHQ Management Platform
- * Copyright (C) 2005-2010 Red Hat, Inc.
- * All rights reserved.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation version 2 of the License.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
-package org.rhq.enterprise.gui.coregui.client.inventory.resource.detail.summary;
-
-import java.util.Date;
-import java.util.List;
-
-import com.google.gwt.user.client.rpc.AsyncCallback;
-import com.smartgwt.client.data.DSRequest;
-import com.smartgwt.client.data.DSResponse;
-import com.smartgwt.client.data.DataSourceField;
-import com.smartgwt.client.data.Record;
-import com.smartgwt.client.rpc.RPCResponse;
-import com.smartgwt.client.widgets.grid.ListGridRecord;
-
-import org.rhq.core.domain.criteria.Criteria;
-import org.rhq.core.domain.resource.ResourceError;
-import org.rhq.enterprise.gui.coregui.client.CoreGUI;
-import org.rhq.enterprise.gui.coregui.client.gwt.GWTServiceLookup;
-import org.rhq.enterprise.gui.coregui.client.gwt.ResourceGWTServiceAsync;
-import org.rhq.enterprise.gui.coregui.client.util.RPCDataSource;
-
-/**
- * @author Lukas Krejci
- * @author Simeon Pinder
- * @author John Mazzitelli
- */
-public class ResourceErrorsDataSource extends RPCDataSource<ResourceError, Criteria> {
-
- public static abstract class Field {
- public static final String ID = "id";
- public static final String SUMMARY = "summary";
- public static final String DETAIL = "detail";
- public static final String ERROR_TYPE = "errorType";
- public static final String TIME_OCCURED = "timeOccured";
- }
-
- ResourceGWTServiceAsync resourceService;
- int resourceId;
-
- public ResourceErrorsDataSource(int resourceId) {
- resourceService = GWTServiceLookup.getResourceService();
- this.resourceId = resourceId;
- List<DataSourceField> fields = addDataSourceFields();
- addFields(fields);
- }
-
- @Override
- protected void executeFetch(final DSRequest request, final DSResponse response, final Criteria unused) {
- resourceService.findResourceErrors(resourceId, new AsyncCallback<List<ResourceError>>() {
- public void onFailure(Throwable caught) {
- CoreGUI.getErrorHandler().handleError(
- MSG.dataSource_resourceErrors_error_fetchFailure(String.valueOf(resourceId)), caught);
- response.setStatus(RPCResponse.STATUS_FAILURE);
- processResponse(request.getRequestId(), response);
- }
-
- public void onSuccess(List<ResourceError> result) {
- response.setData(buildRecords(result));
- processResponse(request.getRequestId(), response);
- }
- });
- }
-
- @Override
- protected Criteria getFetchCriteria(DSRequest request) {
- // we don't use criterias for this datasource, just return null
- return null;
- }
-
- @Override
- public ResourceError copyValues(Record from) {
- //This is read-only datasource, so no need to implement this.
- return null;
- }
-
- @Override
- public ListGridRecord copyValues(ResourceError from) {
- ListGridRecord record = new ListGridRecord();
-
- record.setAttribute(Field.ID, from.getId());
- record.setAttribute(Field.DETAIL, from.getDetail());
- record.setAttribute(Field.ERROR_TYPE, from.getErrorType().name());
- record.setAttribute(Field.SUMMARY, from.getSummary());
- record.setAttribute(Field.TIME_OCCURED, new Date(from.getTimeOccurred()));
-
- return record;
- }
-}
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/summary/ResourceErrorsView.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/summary/ResourceErrorsView.java
deleted file mode 100644
index e4e62e8..0000000
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/summary/ResourceErrorsView.java
+++ /dev/null
@@ -1,189 +0,0 @@
-/*
- * RHQ Management Platform
- * Copyright (C) 2005-2011 Red Hat, Inc.
- * All rights reserved.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation version 2 of the License.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-package org.rhq.enterprise.gui.coregui.client.inventory.resource.detail.summary;
-
-import com.google.gwt.user.client.rpc.AsyncCallback;
-import com.smartgwt.client.data.Criteria;
-import com.smartgwt.client.types.Alignment;
-import com.smartgwt.client.types.AutoFitWidthApproach;
-import com.smartgwt.client.types.ListGridFieldType;
-import com.smartgwt.client.types.Overflow;
-import com.smartgwt.client.types.SelectionStyle;
-import com.smartgwt.client.widgets.Window;
-import com.smartgwt.client.widgets.events.CloseClickHandler;
-import com.smartgwt.client.widgets.events.CloseClientEvent;
-import com.smartgwt.client.widgets.events.DoubleClickEvent;
-import com.smartgwt.client.widgets.events.DoubleClickHandler;
-import com.smartgwt.client.widgets.grid.HoverCustomizer;
-import com.smartgwt.client.widgets.grid.ListGrid;
-import com.smartgwt.client.widgets.grid.ListGridField;
-import com.smartgwt.client.widgets.grid.ListGridRecord;
-import com.smartgwt.client.widgets.grid.events.RecordClickEvent;
-import com.smartgwt.client.widgets.grid.events.RecordClickHandler;
-
-import org.rhq.enterprise.gui.coregui.client.CoreGUI;
-import org.rhq.enterprise.gui.coregui.client.components.table.AbstractTableAction;
-import org.rhq.enterprise.gui.coregui.client.components.table.Table;
-import org.rhq.enterprise.gui.coregui.client.components.table.TableActionEnablement;
-import org.rhq.enterprise.gui.coregui.client.components.table.TimestampCellFormatter;
-import org.rhq.enterprise.gui.coregui.client.gwt.GWTServiceLookup;
-import org.rhq.enterprise.gui.coregui.client.inventory.resource.detail.summary.ResourceErrorsDataSource.Field;
-import org.rhq.enterprise.gui.coregui.client.util.message.Message;
-import org.rhq.enterprise.gui.coregui.client.util.message.Message.Severity;
-import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableHTMLPane;
-import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableWindow;
-
-public class ResourceErrorsView extends Table<ResourceErrorsDataSource> {
- private static final String ERROR_ICON = "[SKIN]/Dialog/warn.png";
-
- public ResourceErrorsView(String locatorId, String string, Criteria criteria, Object object, String[] strings) {
- super(locatorId, MSG.common_title_component_errors(), criteria);
- setWidth100();
- setHeight100();
- setShowHeader(false);
- }
-
- @Override
- protected SelectionStyle getDefaultSelectionStyle() {
- return SelectionStyle.MULTIPLE;
- }
-
- @Override
- protected void configureTable() {
- ListGridField errorTypeField = new ListGridField(Field.ERROR_TYPE, MSG
- .dataSource_resourceErrors_field_errorType());
- errorTypeField.setAlign(Alignment.CENTER);
- errorTypeField.setAutoFitWidth(true);
- errorTypeField.setAutoFitWidthApproach(AutoFitWidthApproach.BOTH);
-
- ListGridField timeField = new ListGridField(Field.TIME_OCCURED, MSG
- .dataSource_resourceErrors_field_timeOccured());
- timeField.setType(ListGridFieldType.DATE);
- timeField.setAlign(Alignment.CENTER);
- timeField.setWidth("20%");
- TimestampCellFormatter.prepareDateField(timeField);
-
- ListGridField summaryField = new ListGridField(Field.SUMMARY, MSG.dataSource_resourceErrors_field_summary());
- summaryField.setAlign(Alignment.CENTER);
- summaryField.setCellAlign(Alignment.LEFT);
- summaryField.setWidth("*");
-
- ListGridField iconField = new ListGridField("icon");
- iconField.setType(ListGridFieldType.ICON);
- iconField.setAlign(Alignment.CENTER);
- iconField.setIcon(ERROR_ICON);
- iconField.setCellIcon(ERROR_ICON);
- iconField.setWidth("50");
- iconField.setCanSort(false);
- iconField.addRecordClickHandler(new RecordClickHandler() {
- @Override
- public void onRecordClick(RecordClickEvent event) {
- String details = event.getRecord().getAttribute(Field.DETAIL);
- popupDetails(details);
- }
- });
- iconField.setShowHover(true);
- iconField.setHoverCustomizer(new HoverCustomizer() {
- @Override
- public String hoverHTML(Object value, ListGridRecord record, int rowNum, int colNum) {
- String html = record.getAttribute(Field.DETAIL);
- if (html.length() > 80) {
- // this was probably an error stack trace, snip it so the tooltip isn't too big
- html = "<pre>" + html.substring(0, 80) + "...</pre><p>"
- + MSG.dataSource_resourceErrors_clickStatusIcon() + "</p>";
- }
- return html;
- }
- });
-
- setListGridDoubleClickHandler(new DoubleClickHandler() {
- @Override
- public void onDoubleClick(DoubleClickEvent event) {
- ListGrid listGrid = (ListGrid) event.getSource();
- ListGridRecord[] selectedRows = listGrid.getSelection();
- if (selectedRows != null && selectedRows.length > 0) {
- String details = selectedRows[0].getAttribute(Field.DETAIL);
- popupDetails(details);
- }
- }
- });
-
- setListGridFields(errorTypeField, timeField, summaryField, iconField);
-
- addTableAction(extendLocatorId("delete"), MSG.common_button_delete(), MSG.common_msg_areYouSure(),
- new AbstractTableAction(TableActionEnablement.ANY) {
- @Override
- public void executeAction(final ListGridRecord[] selection, Object actionValue) {
- if (selection == null || selection.length == 0) {
- return;
- }
- int[] resourceErrorIds = new int[selection.length];
- int i = 0;
- for (ListGridRecord record : selection) {
- resourceErrorIds[i++] = record.getAttributeAsInt(Field.ID);
- }
- GWTServiceLookup.getResourceService().deleteResourceErrors(resourceErrorIds,
- new AsyncCallback<Void>() {
- @Override
- public void onSuccess(Void result) {
- Message msg = new Message(MSG.dataSource_resourceErrors_deleteSuccess(String
- .valueOf(selection.length)), Severity.Info);
- CoreGUI.getMessageCenter().notify(msg);
- refresh();
- }
-
- @Override
- public void onFailure(Throwable caught) {
- CoreGUI.getErrorHandler().handleError(MSG.dataSource_resourceErrors_deleteFailure(),
- caught);
- }
- });
- }
- });
- }
-
- private void popupDetails(String details) {
- final Window winModal = new LocatableWindow(extendLocatorId("errorDetailsWin"));
- winModal.setTitle(MSG.common_title_component_errors());
- winModal.setOverflow(Overflow.VISIBLE);
- winModal.setShowMinimizeButton(false);
- winModal.setShowMaximizeButton(true);
- winModal.setIsModal(true);
- winModal.setShowModalMask(true);
- winModal.setAutoSize(true);
- winModal.setAutoCenter(true);
- winModal.setShowResizer(true);
- winModal.setCanDragResize(true);
- winModal.centerInPage();
- winModal.addCloseClickHandler(new CloseClickHandler() {
- @Override
- public void onCloseClick(CloseClientEvent event) {
- winModal.markForDestroy();
- }
- });
-
- LocatableHTMLPane htmlPane = new LocatableHTMLPane(extendLocatorId("errorDetailsPane"));
- htmlPane.setMargin(10);
- htmlPane.setDefaultWidth(700);
- htmlPane.setDefaultHeight(500);
- htmlPane.setContents("<pre>" + details + "</pre>");
- winModal.addItem(htmlPane);
- winModal.show();
- }
-}
12 years, 8 months
[rhq] modules/enterprise
by Jay Shaughnessy
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/table/AuthorizedTableAction.java | 95 +++++++++
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/table/RecordExtractor.java | 38 +++
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/table/ResourceAuthorizedTableAction.java | 101 ++++++++++
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/gwt/AuthorizationGWTService.java | 14 +
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/ResourceGroupListView.java | 8
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/ResourceSearchView.java | 21 +-
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/server/gwt/AuthorizationGWTServiceImpl.java | 11 -
modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages.properties | 2
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/ResourceManagerBean.java | 3
9 files changed, 287 insertions(+), 6 deletions(-)
New commits:
commit 5422bf4365ea656d41399ec67a4c91cf573b9f0e
Author: Jay Shaughnessy <jshaughn(a)redhat.com>
Date: Thu Mar 31 16:50:13 2011 -0400
Button Enablement Work
- Disable group Delete and New buttons for non inv-managers
- Disable uninventory button for non-resource-delete users
- updated text for delete perm on role detail page
- Added some support for authorized button enablement
(see AuthorizedTableAction)
- Added an interface for record extraction (see RecordExtractor)
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/table/AuthorizedTableAction.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/table/AuthorizedTableAction.java
new file mode 100644
index 0000000..710aa53
--- /dev/null
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/table/AuthorizedTableAction.java
@@ -0,0 +1,95 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2009 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+package org.rhq.enterprise.gui.coregui.client.components.table;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import com.smartgwt.client.widgets.grid.ListGridRecord;
+
+import org.rhq.core.domain.authz.Permission;
+import org.rhq.enterprise.gui.coregui.client.PermissionsLoadedListener;
+import org.rhq.enterprise.gui.coregui.client.PermissionsLoader;
+
+/**
+ * This class allows for TableAction (ie. Button) enablement based on row selection and global perm authorization.
+ *
+ * For Resource Perm authorization see {@link ResourceAuthorizedTableAction}.
+ *
+ * @author Jay Shaughnessy
+ */
+public abstract class AuthorizedTableAction extends AbstractTableAction {
+
+ Table<?> table;
+
+ HashSet<Permission> globalPermissions = new HashSet<Permission>();
+
+ Boolean isGlobalAuthorized;
+
+ protected AuthorizedTableAction(Table<?> table, Permission... permissions) {
+ this(table, TableActionEnablement.ALWAYS, permissions);
+ }
+
+ protected AuthorizedTableAction(Table<?> table, TableActionEnablement enablement, Permission... permissions) {
+ super(enablement);
+
+ this.table = table;
+
+ for (Permission p : permissions) {
+ switch (p.getTarget()) {
+ case GLOBAL:
+ globalPermissions.add(p);
+ break;
+ case RESOURCE:
+ throw new IllegalArgumentException("Does not support Resource permissions");
+ }
+ }
+
+ if (globalPermissions.isEmpty()) {
+ isGlobalAuthorized = Boolean.TRUE;
+ }
+ }
+
+ @Override
+ public boolean isEnabled(ListGridRecord[] selection) {
+ if (!super.isEnabled(selection)) {
+ return false;
+ }
+
+ if (null == isGlobalAuthorized) {
+ new PermissionsLoader().loadExplicitGlobalPermissions(new PermissionsLoadedListener() {
+
+ public void onPermissionsLoaded(Set<Permission> grantedPermissions) {
+ for (Permission requiredPermission : globalPermissions) {
+ if (!grantedPermissions.contains(requiredPermission)) {
+ return;
+ }
+ }
+ isGlobalAuthorized = true;
+ table.refreshTableInfo();
+ }
+ });
+
+ return false;
+ }
+
+ return isGlobalAuthorized;
+ }
+}
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/table/RecordExtractor.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/table/RecordExtractor.java
new file mode 100644
index 0000000..1fe84d0
--- /dev/null
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/table/RecordExtractor.java
@@ -0,0 +1,38 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2009 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+package org.rhq.enterprise.gui.coregui.client.components.table;
+
+import java.util.Collection;
+
+import com.smartgwt.client.data.Record;
+
+/**
+ * Typically used for anaonymous class definition for extracting any data from a set of Records, typically
+ * ListGridRecords. For example, a utility that needs the resource ids extracted from the record set's attributes
+ * but does not know what the attributes are, could be passed a RecordExtractor.
+ *
+ * @author Jay Shaughnessy
+ *
+ */
+public interface RecordExtractor<T extends Object> {
+
+ Collection<T> extract(Record[] records);
+
+}
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/table/ResourceAuthorizedTableAction.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/table/ResourceAuthorizedTableAction.java
new file mode 100644
index 0000000..8931446
--- /dev/null
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/table/ResourceAuthorizedTableAction.java
@@ -0,0 +1,101 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2009 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+package org.rhq.enterprise.gui.coregui.client.components.table;
+
+import java.util.Collection;
+
+import com.google.gwt.user.client.rpc.AsyncCallback;
+import com.smartgwt.client.widgets.grid.ListGridRecord;
+
+import org.rhq.core.domain.authz.Permission;
+import org.rhq.core.domain.authz.Permission.Target;
+import org.rhq.enterprise.gui.coregui.client.CoreGUI;
+import org.rhq.enterprise.gui.coregui.client.gwt.GWTServiceLookup;
+
+/**
+ * This class allows for TableAction (ie. Button) enablement based on row selection and resource perm authorization
+ * on the selected rows. If possible it is recommended that the table be built using composites that include the
+ * resource permission information already, as performance will be better. This approach will require an async
+ * authz call to the server on each refresh of the TableActions (i.e. each time selection changes in the Table).
+ *
+ * For Global Perm authorization see {@link AuthorizedTableAction}.
+ *
+ * TODO: This class has yet to be tested.
+ *
+ * @author Jay Shaughnessy
+ */
+public abstract class ResourceAuthorizedTableAction extends AbstractTableAction {
+
+ Table<?> table;
+ Permission requiredPermission;
+ RecordExtractor<Integer> extractor;
+
+ Boolean isAuthorized;
+
+ protected ResourceAuthorizedTableAction(Table<?> table, Permission requiredPermission,
+ RecordExtractor<Integer> extractor) {
+ this(table, TableActionEnablement.ALWAYS, requiredPermission, extractor);
+ }
+
+ protected ResourceAuthorizedTableAction(Table<?> table, TableActionEnablement enablement,
+ Permission requiredPermission, RecordExtractor<Integer> extractor) {
+ super(enablement);
+
+ this.table = table;
+ this.requiredPermission = requiredPermission;
+ this.extractor = extractor;
+
+ if (Target.RESOURCE != this.requiredPermission.getTarget()) {
+ throw new IllegalArgumentException("Does not support Global permission");
+ }
+ }
+
+ @Override
+ public boolean isEnabled(ListGridRecord[] selection) {
+ // first make sure row selection enablement passes
+ if (!super.isEnabled(selection)) {
+ return false;
+ }
+
+ // if we've performed the required auth check, return the result and reset.
+ if (null != isAuthorized) {
+ boolean result = isAuthorized;
+ isAuthorized = null;
+ return result;
+ }
+
+ // otherwise, kick off the async auth check. return false initially and update when the async call returns
+ Collection<Integer> resourceIds = extractor.extract(selection);
+ GWTServiceLookup.getAuthorizationService().hasResourcePermission(requiredPermission, resourceIds,
+ new AsyncCallback<Boolean>() {
+ public void onFailure(Throwable caught) {
+ CoreGUI.getErrorHandler().handleError("", caught);
+ }
+
+ public void onSuccess(Boolean result) {
+ isAuthorized = result;
+ table.refreshTableInfo();
+ }
+
+ });
+
+ return false;
+ }
+}
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/gwt/AuthorizationGWTService.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/gwt/AuthorizationGWTService.java
index 249a655..3d14c3a 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/gwt/AuthorizationGWTService.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/gwt/AuthorizationGWTService.java
@@ -18,6 +18,7 @@
*/
package org.rhq.enterprise.gui.coregui.client.gwt;
+import java.util.Collection;
import java.util.Set;
import com.google.gwt.user.client.rpc.RemoteService;
@@ -72,4 +73,17 @@ public interface AuthorizationGWTService extends RemoteService {
*/
Set<Permission> getExplicitGlobalPermissions() throws RuntimeException;
+ /**
+ * Returns true if the current user possesses either: 1) the specified resource permission for *all* of the
+ * specified resources, or 2) the global MANAGE_INVENTORY permission which, by definition, gives full access to the
+ * inventory (all resources and all groups) NOTE: The size of the collection must be less than or equal to 1000 (due
+ * to an Oracle limitation).
+ *
+ * @param permission a resource permission (i.e. permission.getTarget() == Permission.Target.RESOURCE)
+ * @param resourceIds the ids of some Resources to check permissions against (size of collection must be <= 1000)
+ *
+ * @return true if the current user possesses the specified resource permission for the specified resource
+ */
+ boolean hasResourcePermission(Permission permission, Collection<Integer> resourceIds);
+
}
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/ResourceGroupListView.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/ResourceGroupListView.java
index 8ed410d..066b4a2 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/ResourceGroupListView.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/ResourceGroupListView.java
@@ -40,12 +40,14 @@ import com.smartgwt.client.widgets.grid.ListGrid;
import com.smartgwt.client.widgets.grid.ListGridField;
import com.smartgwt.client.widgets.grid.ListGridRecord;
+import org.rhq.core.domain.authz.Permission;
import org.rhq.core.domain.resource.group.GroupCategory;
import org.rhq.core.domain.search.SearchSubsystem;
import org.rhq.enterprise.gui.coregui.client.CoreGUI;
import org.rhq.enterprise.gui.coregui.client.ImageManager;
import org.rhq.enterprise.gui.coregui.client.LinkManager;
import org.rhq.enterprise.gui.coregui.client.components.table.AbstractTableAction;
+import org.rhq.enterprise.gui.coregui.client.components.table.AuthorizedTableAction;
import org.rhq.enterprise.gui.coregui.client.components.table.Table;
import org.rhq.enterprise.gui.coregui.client.components.table.TableActionEnablement;
import org.rhq.enterprise.gui.coregui.client.gwt.GWTServiceLookup;
@@ -169,7 +171,8 @@ public class ResourceGroupListView extends Table<ResourceGroupCompositeDataSourc
if (this.showDeleteButton) {
addTableAction(extendLocatorId("Delete"), MSG.common_button_delete(), MSG.common_msg_areYouSure(),
- new AbstractTableAction(TableActionEnablement.ANY) {
+ new AuthorizedTableAction(this, TableActionEnablement.ANY, Permission.MANAGE_INVENTORY) {
+
public void executeAction(ListGridRecord[] selections, Object actionValue) {
int[] groupIds = new int[selections.length];
int index = 0;
@@ -195,7 +198,8 @@ public class ResourceGroupListView extends Table<ResourceGroupCompositeDataSourc
}
if (this.showNewButton) {
- addTableAction(extendLocatorId("New"), MSG.common_button_new(), new AbstractTableAction() {
+ addTableAction(extendLocatorId("New"), MSG.common_button_new(), new AuthorizedTableAction(this,
+ Permission.MANAGE_INVENTORY) {
public void executeAction(ListGridRecord[] selection, Object actionValue) {
new GroupCreateWizard(ResourceGroupListView.this).startWizard();
}
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/ResourceSearchView.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/ResourceSearchView.java
index 27e67d7..32a6227 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/ResourceSearchView.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/ResourceSearchView.java
@@ -26,10 +26,12 @@ import static org.rhq.enterprise.gui.coregui.client.inventory.resource.ResourceD
import static org.rhq.enterprise.gui.coregui.client.inventory.resource.ResourceDataSourceField.TYPE;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.List;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.smartgwt.client.data.Criteria;
+import com.smartgwt.client.data.Record;
import com.smartgwt.client.data.SortSpecifier;
import com.smartgwt.client.types.Alignment;
import com.smartgwt.client.types.ListGridFieldType;
@@ -41,13 +43,15 @@ import com.smartgwt.client.widgets.grid.ListGrid;
import com.smartgwt.client.widgets.grid.ListGridField;
import com.smartgwt.client.widgets.grid.ListGridRecord;
+import org.rhq.core.domain.authz.Permission;
import org.rhq.core.domain.criteria.ResourceCriteria;
import org.rhq.core.domain.resource.Resource;
import org.rhq.core.domain.resource.ResourceCategory;
import org.rhq.core.domain.search.SearchSubsystem;
import org.rhq.enterprise.gui.coregui.client.CoreGUI;
import org.rhq.enterprise.gui.coregui.client.LinkManager;
-import org.rhq.enterprise.gui.coregui.client.components.table.AbstractTableAction;
+import org.rhq.enterprise.gui.coregui.client.components.table.RecordExtractor;
+import org.rhq.enterprise.gui.coregui.client.components.table.ResourceAuthorizedTableAction;
import org.rhq.enterprise.gui.coregui.client.components.table.ResourceCategoryCellFormatter;
import org.rhq.enterprise.gui.coregui.client.components.table.Table;
import org.rhq.enterprise.gui.coregui.client.components.table.TableActionEnablement;
@@ -100,6 +104,7 @@ public class ResourceSearchView extends Table {
*
* @param headerIcons 24x24 icon(s) to be displayed in the header
*/
+ @SuppressWarnings("unchecked")
public ResourceSearchView(String locatorId, Criteria criteria, String title, SortSpecifier[] sortSpecifier,
String[] excludeFields, String... headerIcons) {
super(locatorId, title, criteria, sortSpecifier, excludeFields);
@@ -177,7 +182,19 @@ public class ResourceSearchView extends Table {
categoryField, availabilityField);
addTableAction(extendLocatorId("Uninventory"), MSG.common_button_uninventory(), MSG
- .view_inventory_resources_uninventoryConfirm(), new AbstractTableAction(TableActionEnablement.ANY) {
+ .view_inventory_resources_uninventoryConfirm(), new ResourceAuthorizedTableAction(ResourceSearchView.this,
+ TableActionEnablement.ANY, Permission.DELETE_RESOURCE, new RecordExtractor<Integer>() {
+
+ public Collection<Integer> extract(Record[] records) {
+ List<Integer> result = new ArrayList<Integer>(records.length);
+ for (Record record : records) {
+ result.add(record.getAttributeAsInt("id"));
+ }
+
+ return result;
+ }
+ }) {
+
public void executeAction(ListGridRecord[] selection, Object actionValue) {
int[] resourceIds = TableUtility.getIds(selection);
ResourceGWTServiceAsync resourceManager = GWTServiceLookup.getResourceService();
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/server/gwt/AuthorizationGWTServiceImpl.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/server/gwt/AuthorizationGWTServiceImpl.java
index bf56c99..d31b5d8 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/server/gwt/AuthorizationGWTServiceImpl.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/server/gwt/AuthorizationGWTServiceImpl.java
@@ -18,11 +18,11 @@
*/
package org.rhq.enterprise.gui.coregui.server.gwt;
+import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import org.rhq.core.domain.authz.Permission;
-import org.rhq.core.util.exception.ThrowableUtil;
import org.rhq.enterprise.gui.coregui.client.gwt.AuthorizationGWTService;
import org.rhq.enterprise.gui.coregui.server.util.SerialUtility;
import org.rhq.enterprise.server.authz.AuthorizationManagerLocal;
@@ -83,4 +83,13 @@ public class AuthorizationGWTServiceImpl extends AbstractGWTServiceImpl implemen
}
}
+ public boolean hasResourcePermission(Permission permission, Collection<Integer> resourceIds) {
+ try {
+ boolean result = authorizationManager.hasResourcePermission(getSessionSubject(), permission, resourceIds);
+ return result;
+ } catch (Throwable t) {
+ throw getExceptionToThrowToClient(t);
+ }
+ }
+
}
diff --git a/modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages.properties b/modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages.properties
index 1867bf7..26b3bf0 100644
--- a/modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages.properties
+++ b/modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages.properties
@@ -702,7 +702,7 @@ view_adminRoles_permissions_permReadDesc_createChildResources = (IMPLIED) view c
view_adminRoles_permissions_permWriteDesc_createChildResources = create new child Resources (for child Resources of types that are creatable)
view_adminRoles_permissions_perm_deleteChildResources = Delete Child Resources
view_adminRoles_permissions_permReadDesc_deleteChildResources = (IMPLIED) view child Resource deletion history
-view_adminRoles_permissions_permWriteDesc_deleteChildResources = delete child Resources (for child Resources of types that are deletable)
+view_adminRoles_permissions_permWriteDesc_deleteChildResources = uninventory resources; delete Resources (for Resources of types that are deletable)
# Administration/Topology/RemoteAgentInstall/#
#--------------------------------
diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/ResourceManagerBean.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/ResourceManagerBean.java
index 30c2334..fdfb2d1 100644
--- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/ResourceManagerBean.java
+++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/ResourceManagerBean.java
@@ -267,6 +267,9 @@ public class ResourceManagerBean implements ResourceManagerLocal, ResourceManage
}
// make sure the user is authorized to delete this resource (which implies you can delete all its children)
+ // TODO: There is a pretty good argument for this being replaced with MANAGE_INVENTORY. It takes an
+ // inventory manager to import resources, so why not to remove them? But, since no one has complained
+ // we're timid about making a change that may hamstring existing setups.
if (!authorizationManager.hasResourcePermission(user, Permission.DELETE_RESOURCE, resourceId)) {
throw new PermissionException("You do not have permission to uninventory resource [" + resourceId + "]");
}
12 years, 8 months
[rhq] modules/enterprise
by mazz
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/detail/operation/history/GroupMemberResourceOperationHistoryListView.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
New commits:
commit 0ac2a805a2ebdeb345a6058fb77695f3ec907ac1
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Thu Mar 31 16:04:47 2011 -0400
BZ 692299 - correct the resource link
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/detail/operation/history/GroupMemberResourceOperationHistoryListView.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/detail/operation/history/GroupMemberResourceOperationHistoryListView.java
index b4e1257..87c8b14 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/detail/operation/history/GroupMemberResourceOperationHistoryListView.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/detail/operation/history/GroupMemberResourceOperationHistoryListView.java
@@ -47,7 +47,7 @@ public class GroupMemberResourceOperationHistoryListView extends
resourceField.setWidth("25%");
resourceField.setCellFormatter(new CellFormatter() {
public String format(Object o, ListGridRecord listGridRecord, int i, int i1) {
- String url = LinkManager.getResourceLink(listGridRecord.getAttributeAsInt("id"));
+ String url = LinkManager.getResourceLink(listGridRecord.getAttributeAsInt(AncestryUtil.RESOURCE_ID));
return SeleniumUtility.getLocatableHref(url, o.toString(), null);
}
});
12 years, 8 months
[rhq] modules/enterprise
by mazz
modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/measurement/graphs/EventsTimelineUIBean.java | 3 +++
modules/enterprise/gui/portal-war/src/main/webapp/rhq/common/monitor/events/data-plain.xhtml | 4 ++--
2 files changed, 5 insertions(+), 2 deletions(-)
New commits:
commit 8bd52cd028bd7fc6547c52c846de539fd46a21aa
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Thu Mar 31 15:39:49 2011 -0400
BZ 610791 - hide the event tracking bar in the monitor graphs jsf page since its broken. we'll fix this kind of display when we move the graph page to gwt
diff --git a/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/measurement/graphs/EventsTimelineUIBean.java b/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/measurement/graphs/EventsTimelineUIBean.java
index 5f9fb22..b7461c3 100644
--- a/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/measurement/graphs/EventsTimelineUIBean.java
+++ b/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/measurement/graphs/EventsTimelineUIBean.java
@@ -47,8 +47,11 @@ public class EventsTimelineUIBean {
context = WebUtility.getEntityContext();
+ /* see BZ 610791
EventSeverity[] eventsCounts = eventManager.getSeverityBucketsByContext(user.getSubject(), context, begin, end,
numberOfBuckets);
+ */
+ EventSeverity[] eventsCounts = new EventSeverity[numberOfBuckets]; // dummy event counts, all nulls, for BZ 610791
data = new ArrayList<TimelineBean>();
long interval = TimeUtil.getInterval(begin, end, numberOfBuckets);
diff --git a/modules/enterprise/gui/portal-war/src/main/webapp/rhq/common/monitor/events/data-plain.xhtml b/modules/enterprise/gui/portal-war/src/main/webapp/rhq/common/monitor/events/data-plain.xhtml
index 068f97b..90b09cc 100644
--- a/modules/enterprise/gui/portal-war/src/main/webapp/rhq/common/monitor/events/data-plain.xhtml
+++ b/modules/enterprise/gui/portal-war/src/main/webapp/rhq/common/monitor/events/data-plain.xhtml
@@ -55,6 +55,7 @@
<td colspan="62" style="height: 2px;"></td>
</tr>
+ <!-- BZ 610791
<tr style="height: 12px;">
<td></td>
<c:forEach var="timeTick" items="#{EventsTimelineUIBean.data}" varStatus="status">
@@ -84,7 +85,6 @@
</c:choose>
</c:if>
- <!-- put onmousedown in table data element not the div, which gives the user a larger clickable area -->
<c:if test="#{empty timeTick.severity}">
<td style="background-image: url(#{icon}); background-repeat:no-repeat;" align="center" valign="middle">
</td>
@@ -102,7 +102,7 @@
<h:outputFormat value="#{msg['resource.common.monitor.label.elc']}" />
</td>
</tr>
-
+ -->
<tr>
<td colspan="62" valign="top">
<a name="eventDetail"></a>
12 years, 8 months
[rhq] 2 commits - modules/enterprise modules/plugins
by Simeon Pinder
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/recent/alerts/AbstractRecentAlertsPortlet.java | 3
modules/plugins/jboss-as/src/main/java/org/rhq/plugins/jbossas/JBossASServerComponent.java | 2
modules/plugins/jboss-as/src/main/java/org/rhq/plugins/jbossas/JBossASServerOperationsDelegate.java | 78 ++++++----
modules/plugins/jboss-as/src/main/resources/META-INF/rhq-plugin.xml | 13 +
modules/plugins/tomcat/src/main/java/org/jboss/on/plugins/tomcat/TomcatServerComponent.java | 2
modules/plugins/tomcat/src/main/java/org/jboss/on/plugins/tomcat/TomcatServerOperationsDelegate.java | 27 +++
modules/plugins/tomcat/src/main/resources/META-INF/rhq-plugin.xml | 13 +
7 files changed, 108 insertions(+), 30 deletions(-)
New commits:
commit a3356e841e795aeaea76903e5b10bc0fef82c0fd
Author: Simeon Pinder <spinder(a)redhat.com>
Date: Thu Mar 31 10:07:12 2011 -0400
enable refresh for config changes and hide refresh button for portlets.
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/recent/alerts/AbstractRecentAlertsPortlet.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/recent/alerts/AbstractRecentAlertsPortlet.java
index 013e5be..388094a 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/recent/alerts/AbstractRecentAlertsPortlet.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/recent/alerts/AbstractRecentAlertsPortlet.java
@@ -66,6 +66,7 @@ public abstract class AbstractRecentAlertsPortlet extends AlertHistoryView imple
setShowFilterForm(false); //disable filter form for portlet
setOverflow(Overflow.VISIBLE);
+ setShowFooterRefresh(false); //disable footer refresh button as redundant for portlets
}
public Timer getRefreshTimer() {
@@ -171,6 +172,8 @@ public abstract class AbstractRecentAlertsPortlet extends AlertHistoryView imple
// persist and reload portlet
storedPortlet.setConfiguration(portletConfig);
configure(portletWindow, storedPortlet);
+ //apply latest settings to the visible result set
+ refresh();
}
});
commit 1756884b035d86857aba75d826fd19ef4a5a153b
Author: Simeon Pinder <spinder(a)redhat.com>
Date: Wed Mar 30 19:01:51 2011 -0400
BZ 689993: enable start/stop WAIT_MAX for AS4 and Tomcat server components.
diff --git a/modules/plugins/jboss-as/src/main/java/org/rhq/plugins/jbossas/JBossASServerComponent.java b/modules/plugins/jboss-as/src/main/java/org/rhq/plugins/jbossas/JBossASServerComponent.java
index 8e967ae..f241200 100644
--- a/modules/plugins/jboss-as/src/main/java/org/rhq/plugins/jbossas/JBossASServerComponent.java
+++ b/modules/plugins/jboss-as/src/main/java/org/rhq/plugins/jbossas/JBossASServerComponent.java
@@ -133,6 +133,8 @@ public class JBossASServerComponent implements MeasurementFacet, OperationFacet,
public static final String SCRIPT_PREFIX_CONFIG_PROP = "scriptPrefix";
public static final String CONFIGURATION_SET_CONFIG_PROP = "configurationSet";
public static final String START_SCRIPT_CONFIG_PROP = "startScript";
+ public static final String START_WAIT_MAX_PROP = "startWaitMax";
+ public static final String STOP_WAIT_MAX_PROP = "stopWaitMax";
public static final String SHUTDOWN_SCRIPT_CONFIG_PROP = "shutdownScript";
public static final String SHUTDOWN_MBEAN_CONFIG_PROP = "shutdownMbeanName";
public static final String SHUTDOWN_MBEAN_OPERATION_CONFIG_PROP = "shutdownMbeanOperation";
diff --git a/modules/plugins/jboss-as/src/main/java/org/rhq/plugins/jbossas/JBossASServerOperationsDelegate.java b/modules/plugins/jboss-as/src/main/java/org/rhq/plugins/jbossas/JBossASServerOperationsDelegate.java
index 7bb941d..269f16c 100644
--- a/modules/plugins/jboss-as/src/main/java/org/rhq/plugins/jbossas/JBossASServerOperationsDelegate.java
+++ b/modules/plugins/jboss-as/src/main/java/org/rhq/plugins/jbossas/JBossASServerOperationsDelegate.java
@@ -1,25 +1,25 @@
- /*
- * Jopr Management Platform
- * Copyright (C) 2005-2008 Red Hat, Inc.
- * All rights reserved.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 2, as
- * published by the Free Software Foundation, and/or the GNU Lesser
- * General Public License, version 2.1, also as published by the Free
- * Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License and the GNU Lesser General Public License
- * for more details.
- *
- * You should have received a copy of the GNU General Public License
- * and the GNU Lesser General Public License along with this program;
- * if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
+/*
+ * Jopr Management Platform
+ * Copyright (C) 2005-2008 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2, as
+ * published by the Free Software Foundation, and/or the GNU Lesser
+ * General Public License, version 2.1, also as published by the Free
+ * Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License and the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * and the GNU Lesser General Public License along with this program;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
package org.rhq.plugins.jbossas;
import java.io.File;
@@ -34,6 +34,7 @@ import org.mc4j.ems.connection.bean.operation.EmsOperation;
import org.mc4j.ems.connection.bean.parameter.EmsParameter;
import org.rhq.core.domain.configuration.Configuration;
+import org.rhq.core.domain.configuration.PropertySimple;
import org.rhq.core.domain.measurement.AvailabilityType;
import org.rhq.core.pluginapi.operation.OperationResult;
import org.rhq.core.pluginapi.util.ProcessExecutionUtility;
@@ -51,7 +52,7 @@ import org.rhq.core.system.SystemInfo;
public class JBossASServerOperationsDelegate {
/** max amount of time to wait for server to show as unavailable after executing stop - in milliseconds */
- private static final long STOP_WAIT_MAX = 1000L * 150; // 2.5 minutes
+ private static long STOP_WAIT_MAX = 1000L * 150; // 2.5 minutes
/** amount of time to wait between availability checks when performing a stop - in milliseconds */
private static final long STOP_WAIT_INTERVAL = 1000L * 10; // 10 seconds
@@ -61,7 +62,7 @@ public class JBossASServerOperationsDelegate {
private static final long STOP_WAIT_FINAL = 1000L * 30; // 30 seconds
/** max amount of time to wait for start to complete - in milliseconds */
- private static final long START_WAIT_MAX = 1000L * 300; // 5 minutes
+ private static long START_WAIT_MAX = 1000L * 300; // 5 minutes
/** amount of time to wait between availability checks when performing a start - in milliseconds */
private static final long START_WAIT_INTERVAL = 1000L * 10; // 10 seconds
@@ -369,24 +370,34 @@ public class JBossASServerOperationsDelegate {
try {
shutdown();
} catch (Exception e) {
- throw new RuntimeException("Shutdown may have failed: " +e );
+ throw new RuntimeException("Shutdown may have failed: " + e);
}
-
try {
// Perform the restart.
start();
} catch (Exception e) {
- throw new RuntimeException("Re-Startup may have failed: " +e );
+ throw new RuntimeException("Re-Startup may have failed: " + e);
}
- return"Server has been restarted.";
+ return "Server has been restarted.";
}
private AvailabilityType waitForServerToStart(long start) throws InterruptedException {
AvailabilityType avail;
+ //detect whether startWaitMax property has been set.
+ Configuration pluginConfig = serverComponent.getPluginConfiguration();
+ PropertySimple property = pluginConfig.getSimple(JBossASServerComponent.START_WAIT_MAX_PROP);
+ //if set and valid, update startWaitMax value
+ if ((property != null) && (property.getIntegerValue() != null)) {
+ int newValue = property.getIntegerValue();
+ if (newValue >= 1) {
+ START_WAIT_MAX = 1000L * 60 * newValue;
+ }
+ }
+
while (((avail = this.serverComponent.getAvailability()) == AvailabilityType.DOWN)
&& (System.currentTimeMillis() < (start + START_WAIT_MAX))) {
try {
@@ -399,6 +410,17 @@ public class JBossASServerOperationsDelegate {
}
private AvailabilityType waitForServerToShutdown() {
+ //detect whether stopWaitMax property has been set.
+ Configuration pluginConfig = serverComponent.getPluginConfiguration();
+ PropertySimple property = pluginConfig.getSimple(JBossASServerComponent.STOP_WAIT_MAX_PROP);
+ //if set and valid, update startWaitMax value
+ if ((property != null) && (property.getIntegerValue() != null)) {
+ int newValue = property.getIntegerValue();
+ if (newValue >= 1) {
+ STOP_WAIT_MAX = 1000L * 60 * newValue;
+ }
+ }
+
for (long wait = 0L; (wait < STOP_WAIT_MAX) && (AvailabilityType.UP == this.serverComponent.getAvailability()); wait += STOP_WAIT_INTERVAL) {
try {
Thread.sleep(STOP_WAIT_INTERVAL);
diff --git a/modules/plugins/jboss-as/src/main/resources/META-INF/rhq-plugin.xml b/modules/plugins/jboss-as/src/main/resources/META-INF/rhq-plugin.xml
index 28240ef..192c7f1 100644
--- a/modules/plugins/jboss-as/src/main/resources/META-INF/rhq-plugin.xml
+++ b/modules/plugins/jboss-as/src/main/resources/META-INF/rhq-plugin.xml
@@ -74,6 +74,19 @@
description="The absolute path to a JRE or JDK installation directory containing
the JVM that should be used to start and shutdown the JBossAS instance;
defaults to the home directory of the RHQ agent JRE."/>
+
+ <c:simple-property name="startWaitMax" required="false"
+ description="The time, in minutes,(e.g. 1 or 8) that must elapse before the server is considered to have failed to start up. The default is 5 minutes.">
+ <c:constraint>
+ <c:integer-constraint minimum="1"/>
+ </c:constraint>
+ </c:simple-property>
+ <c:simple-property name="stopWaitMax" required="false"
+ description="The time, in minutes,(e.g. 1 or 8) that must elapse before the server is considered to have failed to stop. The default is 2.5 minutes.">
+ <c:constraint>
+ <c:integer-constraint minimum="1"/>
+ </c:constraint>
+ </c:simple-property>
</c:group>
<c:group name="event" displayName="Events">
diff --git a/modules/plugins/tomcat/src/main/java/org/jboss/on/plugins/tomcat/TomcatServerComponent.java b/modules/plugins/tomcat/src/main/java/org/jboss/on/plugins/tomcat/TomcatServerComponent.java
index 89cbd72..d67f072 100644
--- a/modules/plugins/tomcat/src/main/java/org/jboss/on/plugins/tomcat/TomcatServerComponent.java
+++ b/modules/plugins/tomcat/src/main/java/org/jboss/on/plugins/tomcat/TomcatServerComponent.java
@@ -104,6 +104,8 @@ public class TomcatServerComponent implements JMXComponent, MeasurementFacet, Op
public static final String PLUGIN_CONFIG_SCRIPT_PREFIX = "scriptPrefix";
public static final String PLUGIN_CONFIG_SHUTDOWN_SCRIPT = "shutdownScript";
public static final String PLUGIN_CONFIG_START_SCRIPT = "startScript";
+ public static final String START_WAIT_MAX_PROP = "startWaitMax";
+ public static final String STOP_WAIT_MAX_PROP = "stopWaitMax";
private Log log = LogFactory.getLog(this.getClass());
diff --git a/modules/plugins/tomcat/src/main/java/org/jboss/on/plugins/tomcat/TomcatServerOperationsDelegate.java b/modules/plugins/tomcat/src/main/java/org/jboss/on/plugins/tomcat/TomcatServerOperationsDelegate.java
index b0f3f7c..ce542a9 100644
--- a/modules/plugins/tomcat/src/main/java/org/jboss/on/plugins/tomcat/TomcatServerOperationsDelegate.java
+++ b/modules/plugins/tomcat/src/main/java/org/jboss/on/plugins/tomcat/TomcatServerOperationsDelegate.java
@@ -41,6 +41,7 @@ import org.rhq.core.domain.configuration.Configuration;
import org.rhq.core.domain.configuration.Property;
import org.rhq.core.domain.configuration.PropertyList;
import org.rhq.core.domain.configuration.PropertyMap;
+import org.rhq.core.domain.configuration.PropertySimple;
import org.rhq.core.domain.measurement.AvailabilityType;
import org.rhq.core.pluginapi.operation.OperationResult;
import org.rhq.core.pluginapi.util.ProcessExecutionUtility;
@@ -64,7 +65,7 @@ public class TomcatServerOperationsDelegate {
private static final String SERVER_MBEAN_NAME = "Catalina:type=Server";
/** max amount of time to wait for server to show as unavailable after executing stop - in milliseconds */
- private static final long STOP_WAIT_MAX = 1000L * 150; // 2.5 minutes
+ private static long STOP_WAIT_MAX = 1000L * 150; // 2.5 minutes
/** amount of time to wait between availability checks when performing a stop - in milliseconds */
private static final long STOP_WAIT_INTERVAL = 1000L * 10; // 10 seconds
@@ -74,7 +75,7 @@ public class TomcatServerOperationsDelegate {
private static final long STOP_WAIT_FINAL = 1000L * 30; // 30 seconds
/** max amount of time to wait for start to complete - in milliseconds */
- private static final long START_WAIT_MAX = 1000L * 300; // 5 minutes
+ private static long START_WAIT_MAX = 1000L * 300; // 5 minutes
/** amount of time to wait between availability checks when performing a start - in milliseconds */
private static final long START_WAIT_INTERVAL = 1000L * 10; // 10 seconds
@@ -466,6 +467,18 @@ public class TomcatServerOperationsDelegate {
private AvailabilityType waitForServerToStart(long start) throws InterruptedException {
AvailabilityType avail;
+
+ //detect whether startWaitMax property has been set.
+ Configuration pluginConfig = serverComponent.getResourceContext().getPluginConfiguration();
+ PropertySimple property = pluginConfig.getSimple(TomcatServerComponent.START_WAIT_MAX_PROP);
+ //if set and valid, update startWaitMax value
+ if ((property != null) && (property.getIntegerValue() != null)) {
+ int newValue = property.getIntegerValue();
+ if (newValue >= 1) {
+ START_WAIT_MAX = 1000L * 60 * newValue;
+ }
+ }
+
while (((avail = this.serverComponent.getAvailability()) == AvailabilityType.DOWN)
&& (System.currentTimeMillis() < (start + START_WAIT_MAX))) {
try {
@@ -478,6 +491,16 @@ public class TomcatServerOperationsDelegate {
}
private AvailabilityType waitForServerToShutdown() {
+ //detect whether stopWaitMax property has been set.
+ Configuration pluginConfig = serverComponent.getResourceContext().getPluginConfiguration();
+ PropertySimple property = pluginConfig.getSimple(TomcatServerComponent.STOP_WAIT_MAX_PROP);
+ //if set and valid, update startWaitMax value
+ if ((property != null) && (property.getIntegerValue() != null)) {
+ int newValue = property.getIntegerValue();
+ if (newValue >= 1) {
+ STOP_WAIT_MAX = 1000L * 60 * newValue;
+ }
+ }
for (long wait = 0L; (wait < STOP_WAIT_MAX) && (AvailabilityType.UP == this.serverComponent.getAvailability()); wait += STOP_WAIT_INTERVAL) {
try {
Thread.sleep(STOP_WAIT_INTERVAL);
diff --git a/modules/plugins/tomcat/src/main/resources/META-INF/rhq-plugin.xml b/modules/plugins/tomcat/src/main/resources/META-INF/rhq-plugin.xml
index 5d511cc..24307ef 100644
--- a/modules/plugins/tomcat/src/main/resources/META-INF/rhq-plugin.xml
+++ b/modules/plugins/tomcat/src/main/resources/META-INF/rhq-plugin.xml
@@ -96,6 +96,19 @@
description="The path to the script used by the 'Shutdown' operation to shutdown this Tomcat server;
if the path is not absolute it will be resolved relative to {installationPath}." />
+ <c:simple-property name="startWaitMax" required="false"
+ description="The time, in minutes,(e.g. 1 or 8) that must elapse before the server is considered to have failed to start up. The default is 5 minutes.">
+ <c:constraint>
+ <c:integer-constraint minimum="1"/>
+ </c:constraint>
+ </c:simple-property>
+ <c:simple-property name="stopWaitMax" required="false"
+ description="The time, in minutes,(e.g. 1 or 8) that must elapse before the server is considered to have failed to stop. The default is 2.5 minutes.">
+ <c:constraint>
+ <c:integer-constraint minimum="1"/>
+ </c:constraint>
+ </c:simple-property>
+
<c:list-property
name="startScriptEnvironment"
displayName="Start Script Environment Variables"
12 years, 8 months
[rhq] Branch 'as7plugin' - 30 commits - modules/core modules/enterprise
by Heiko W. Rupp
modules/core/domain/src/main/java/org/rhq/core/domain/tagging/compsite/TagReportComposite.java | 7
modules/core/plugin-container/src/main/java/org/rhq/core/pc/StandaloneContainer.java | 239 ---
modules/core/plugin-container/src/main/java/org/rhq/core/pc/standaloneContainer/Command.java | 99 +
modules/core/plugin-container/src/main/java/org/rhq/core/pc/standaloneContainer/History.java | 147 ++
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/Footer.java | 10
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/ImageManager.java | 20
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/LinkManager.java | 6
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/AlertDataSource.java | 130 +-
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/AlertDetailsView.java | 45
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/AlertHistoryView.java | 55
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/AlertPortletConfigurationDataSource.java | 4
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/AlertPortletDataSource.java | 168 --
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/definitions/AbstractAlertDefinitionsDataSource.java | 6
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/bundle/deployment/BundleDeploymentListView.java | 5
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/bundle/deployment/BundleDeploymentView.java | 7
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/bundle/deployment/BundleResourceDeploymentHistoryListView.java | 2
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/bundle/destination/BundleDestinationListView.java | 5
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/configuration/ConfigurationEditor.java | 16
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/configuration/GroupConfigurationEditor.java | 371 +++--
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/table/TimestampCellFormatter.java | 76 +
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/DashboardView.java | 9
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/PortletWindow.java | 14
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/groups/GroupAlertsPortlet.java | 352 -----
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/groups/GroupAlertsPortlet3.java | 378 ------
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/recent/alerts/AbstractRecentAlertsPortlet.java | 376 ++++++
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/recent/alerts/PortletAlertSelector.java | 96 -
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/recent/alerts/RecentAlertsPortlet.java | 626 ----------
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/recent/imported/RecentlyAddedResourceDS.java | 3
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/recent/imported/RecentlyAddedResourcesPortlet.java | 3
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/recent/operations/OperationsPortlet.java | 3
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/resource/ResourceAlertsPortlet.java | 151 --
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/common/detail/AbstractTwoLevelTabSetView.java | 15
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/common/detail/operation/history/AbstractOperationHistoryDetailsView.java | 28
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/common/detail/operation/history/AbstractOperationHistoryListView.java | 12
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/common/detail/operation/schedule/AbstractOperationScheduleListView.java | 4
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/definitions/GroupDefinitionDataSource.java | 2
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/definitions/GroupDefinitionListView.java | 27
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/definitions/SingleGroupDefinitionView.java | 1
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/detail/GeneralProperties.java | 6
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/detail/configuration/HistoryGroupResourceConfigurationMembers.java | 3
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/detail/configuration/HistoryGroupResourceConfigurationTable.java | 4
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/detail/inventory/HistoryGroupPluginConfigurationMembers.java | 3
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/detail/inventory/HistoryGroupPluginConfigurationTable.java | 4
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/configuration/AbstractConfigurationHistoryDataSource.java | 6
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/summary/ResourceErrorsView.java | 4
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/discovery/ResourceAutodiscoveryView.java | 2
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/report/tag/TagCloudView.java | 125 +
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/report/tag/TaggedView.java | 73 -
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/message/MessageCenterView.java | 5
modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages.properties | 29
modules/enterprise/gui/portal-war/src/main/webapp/js/popup.js | 119 -
51 files changed, 1508 insertions(+), 2393 deletions(-)
New commits:
commit a3fdac16d1b0301ca4771c61ba7f7517d2880117
Merge: 7122b59 080e1d7
Author: Heiko W. Rupp <hwr(a)redhat.com>
Date: Thu Mar 31 12:56:44 2011 +0200
Merge branch 'master' into as7plugin
commit 080e1d77247f9fe6a730a3db01152554072fb7b3
Merge: 22cb9ff 8573843
Author: Heiko W. Rupp <hwr(a)redhat.com>
Date: Thu Mar 31 12:56:13 2011 +0200
Merge branch 'master' of ssh://git.fedorahosted.org/git/rhq/rhq
commit 22cb9ff2d4a08c96591f5e6a4670e38505cd6162
Author: Heiko W. Rupp <hwr(a)redhat.com>
Date: Thu Mar 31 12:53:14 2011 +0200
Be more relaxed when parsing the input.
diff --git a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/StandaloneContainer.java b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/StandaloneContainer.java
index 25130ec..fe4ee1c 100644
--- a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/StandaloneContainer.java
+++ b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/StandaloneContainer.java
@@ -199,6 +199,9 @@ public class StandaloneContainer {
if (tokens[0].startsWith("#"))
return false;
+ if (tokens[0].isEmpty())
+ return false;
+
Command com = Command.get(tokens[0]);
if (com == null) {
System.err.println("Command " + tokens[0] + " is unknown");
@@ -486,7 +489,7 @@ public class StandaloneContainer {
String pattern = tokens[2];
pattern = pattern.replaceAll("\\*", "\\.\\*");
- if (tokens[1].equals("r")) {
+ if (tokens[1].equals("r") || tokens[1].startsWith("res")) {
Set<Resource> resources = getResources();
for (Resource res : resources) {
if (res.getName().matches(pattern)) {
commit 3630e07e77391007034d71692a401a1fe8cd2e3c
Author: Heiko W. Rupp <hwr(a)redhat.com>
Date: Thu Mar 31 12:45:42 2011 +0200
Factor out Command enum and History handling.
Print command when input was a script.
diff --git a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/StandaloneContainer.java b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/StandaloneContainer.java
index 74ccf48..25130ec 100644
--- a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/StandaloneContainer.java
+++ b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/StandaloneContainer.java
@@ -1,6 +1,6 @@
/*
* RHQ Management Platform
- * Copyright (C) 2005-2009 Red Hat, Inc.
+ * Copyright (C) 2005-2011 Red Hat, Inc.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
@@ -22,10 +22,7 @@ import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
-import java.io.FileWriter;
-import java.io.IOException;
import java.io.InputStreamReader;
-import java.io.Writer;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.HashMap;
@@ -56,6 +53,8 @@ import org.rhq.core.pc.inventory.ResourceContainer;
import org.rhq.core.pc.measurement.MeasurementManager;
import org.rhq.core.pc.operation.OperationContextImpl;
import org.rhq.core.pc.plugin.FileSystemPluginFinder;
+import org.rhq.core.pc.standaloneContainer.Command;
+import org.rhq.core.pc.standaloneContainer.History;
import org.rhq.core.pluginapi.operation.OperationContext;
import org.rhq.core.pluginapi.operation.OperationServices;
import org.rhq.core.pluginapi.operation.OperationServicesResult;
@@ -80,29 +79,25 @@ public class StandaloneContainer {
InventoryManager inventoryManager;
/** Global operation counter */
Integer opId = 0;
- /** Holder for the command history */
- List<String> history = new ArrayList<String>(10);
/** Map of resource plugin configurations */
Map<Integer, Configuration> resConfigMap = new HashMap<Integer, Configuration>();
/** variable set by find() and which can be used in set() */
int dollarR = 0;
-
- private static final String HISTORY_HELP = "!! : repeat the last action\n" + //
- "!? : show the history of commands issued\n" + //
- "!h : show this help\n" + //
- "!nn : repeat history item with number nn\n" + //
- "!w fileName : write history to file with name fileName\n" + //
- "!dnn : delete history item with number nn";
+ /** Do we read from stdin ? */
+ static boolean isStdin;
public static void main(String[] argv) {
StandaloneContainer sc = new StandaloneContainer();
BufferedReader br = null;
- if (argv.length == 0)
+ if (argv.length == 0) {
br = new BufferedReader(new InputStreamReader(System.in));
+ isStdin = true;
+ }
else {
try {
br = new BufferedReader(new InputStreamReader(new FileInputStream(argv[0])));
+ isStdin=false;
} catch (FileNotFoundException fnfe) {
System.err.println("File " + argv[0] + " not found");
System.exit(1);
@@ -150,6 +145,8 @@ public class StandaloneContainer {
System.out.println("\nReady.");
+ History history = new History();
+
// Run the main loop
while (!shouldQuit) {
try {
@@ -158,13 +155,16 @@ public class StandaloneContainer {
if (answer == null) {
break;
}
+ if (!isStdin)
+ System.out.println(answer);
if (answer.equalsIgnoreCase(Command.STDIN.toString())) {
br = new BufferedReader(new InputStreamReader(System.in));
+ isStdin=true;
}
// Check for history commands
- answer = handleHistory(answer);
+ answer = history.handleHistory(answer);
// If we have a 'real' command, dispatch it
if (!answer.startsWith("!")) {
@@ -184,104 +184,6 @@ public class StandaloneContainer {
}
- /**
- * Handle processing of the command history. This gives some csh like commands
- * and records the commands given. Nice side effect is the possibility to write the
- * history to disk and to use this later as input so that testing can be scripted.
- * Commands are:
- * <ul>
- * <li>!! : repeat the last action</li>
- * <li>!? : show the history</li>
- * <li>!h : show history help</li>
- * <li>!<i>nnn</i> : repeat history item with number <i>nnn</i></li>
- * <li>!w <i>file</i> : write the history to the file <i>file</i></li>
- * <li>!d<i>nnn</i> : delete the history item with number <i>nnn</i>
- * </ul>
- * @param answer the input given on the command line
- * @return a command or '!' if no command substitution from the history was possible.
- */
- private String handleHistory(String answer) {
-
- // Normal command - just return it
- if (!answer.startsWith("!")) {
- history.add(answer);
- return answer;
- }
-
- // History commands
- if (answer.startsWith("!?")) {
- for (int i = 0; i < history.size(); i++)
- System.out.println("[" + i + "]: " + history.get(i));
- } else if (answer.startsWith("!h")) {
- System.out.println(HISTORY_HELP);
- return "!";
- } else if (answer.startsWith("!!")) {
- String text = history.get(history.size() - 1);
- System.out.println(text);
- history.add(text);
- return text;
- } else if (answer.matches("![0-9]+")) {
- String id = answer.substring(1);
- Integer i;
- try {
- i = Integer.valueOf(id);
- } catch (NumberFormatException nfe) {
- System.err.println(id + " is no valid history position");
- return "!";
- }
- if (i > history.size()) {
- System.err.println(i + " is no valid history position");
- return "!";
- } else {
- String text = history.get(i);
- System.out.println(text);
- history.add(text);
- return text;
- }
- } else if (answer.startsWith("!w")) {
- String[] tokens = answer.split(" ");
- if (tokens.length < 2) {
- System.err.println("Not enough parameters. You need to give a file name");
- }
- File file = new File(tokens[1]);
- try {
- file.createNewFile();
- if (file.canWrite()) {
- Writer writer = new FileWriter(file);
- for (String item : history) {
- writer.write(item);
- writer.write("\n");
- }
- writer.flush();
- writer.close();
- } else {
- System.err.println("Can not write to file " + file);
- }
- } catch (IOException ioe) {
- System.err.println("Saving the history to file " + file + " failed: " + ioe.getMessage());
- }
- return "!";
- } else if (answer.matches("!d[0-9]+")) {
- String id = answer.substring(2);
- Integer i;
- try {
- i = Integer.valueOf(id);
- } catch (NumberFormatException nfe) {
- System.err.println(id + " is no valid history position");
- return "!";
- }
- if (i > history.size()) {
- System.err.println(i + " is no valid history position");
- return "!";
- }
- history.remove(i.intValue());
- return "!";
- } else {
- System.err.println(answer + " is no valid history command");
- return "!";
- }
- return "!";
- }
/**
* Dispatches the input to various commands that do the actual work.
@@ -809,78 +711,4 @@ public class StandaloneContainer {
System.out.println(config.getProperties());
}
- /**
- * List of possible commands
- */
- private enum Command {
- ASCAN("as", "", 0, "Triggers an availability scan"), //
- AVAIL("a", " ( id )", 0,
- "Shows an availability report. If id is given, only shows availability for resource with id id"), //
- CHILDREN("chi", "[id]", 0, "Shows the direct children of the resource with the passed id, or if no id passed of the current resource"), //
- DISCOVER("disc", " s | i | all", 1, "Triggers a discovery scan for (s)erver, serv(i)ce or all resources"), //
- // EVENT("e", "", 0, "Pull events"), // TODO needs to be defined
- FIND("find", "r | t | rt <name>", 2,
- "Searches a (r)esource, resource (t)ype or resources of (rt)ype. Use * as wildcard.\n"
- + " Will set $r for the last resource shown."), HELP("h", "", 0, "Shows this help"), //
- INVOKE("i", "operation [params]", 1, "Triggers running an operation. If operation is '-list' it shows available operations"), //
- MEASURE("m", "datatype property+", 1, "Triggers getting metric values. All need to be of the same data type. If datatype is '-list' it shows the defined metrics"), //
- NATIVE("n", "e | d | s", 1, "Enables/disables native system or shows native status"), //
- QUIT("quit", "", 0, "Terminates the application"), //
- RESOURCES("res", "", 0, "Shows the discovered resources"), //
- SET("set", "'resource' N", 2,
- "Sets the resource id to work with. N can be a number or '$r' as result of last find resource call. 'id' is an alias for 'res'"), //
- STDIN("stdin","",0, "Stop reading the batch file and wait for commands on stdin"), //
- WAIT("w", "milliseconds", 1, "Waits the given amount of time"),
- P_CONFIG("pc", "", 0, "Shows the plugin configuration of the current resource."),
- R_CONFIG("rc", "", 0, "Shows the resource configuration of the current resource."),
- SR_CONFIG("rcs", "", 0, "[parameters] set resource config "),
- SP_CONFIG("pcs", "", 0, "[parameters] set plugin config ")
- ;
-
- private String abbrev;
- private String args;
- private String help;
- private int minArgs; // minimum number of args needed
-
- public String getArgs() {
- return args;
- }
-
- public String getHelp() {
- return help;
- }
-
- public int getMinArgs() {
- return minArgs;
- }
-
- /**
- * Construct a new Command
- * @param abbrev Abbreviation for this command
- * @param args Description of expected arguments
- * @param minArgs Minumum number of arguments that need to be present
- * @param help A short description of the command
- */
- private Command(String abbrev, String args, int minArgs, String help) {
- this.abbrev = abbrev;
- this.args = args;
- this.minArgs = minArgs;
- this.help = help;
- }
-
- public String getAbbrev() {
- return abbrev;
- }
-
- public static Command get(String s) {
-
- String upper = s.toUpperCase();
-
- for (Command c : EnumSet.allOf(Command.class)) {
- if (c.name().equals(upper) || c.getAbbrev().equals(s.toLowerCase()))
- return c;
- }
- return null;
- }
- }
}
diff --git a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/standaloneContainer/Command.java b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/standaloneContainer/Command.java
new file mode 100644
index 0000000..aa91e22
--- /dev/null
+++ b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/standaloneContainer/Command.java
@@ -0,0 +1,99 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2011 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+package org.rhq.core.pc.standaloneContainer;
+
+import java.util.EnumSet;
+
+import org.rhq.core.pc.StandaloneContainer;
+
+/**
+ * List of possible commands of the standalone container
+ * @author Heiko W. Rupp
+ */
+public enum Command {
+ ASCAN("as", "", 0, "Triggers an availability scan"), //
+ AVAIL("a", " ( id )", 0,
+ "Shows an availability report. If id is given, only shows availability for resource with id id"), //
+ CHILDREN("chi", "[id]", 0, "Shows the direct children of the resource with the passed id, or if no id passed of the current resource"), //
+ DISCOVER("disc", " s | i | all", 1, "Triggers a discovery scan for (s)erver, serv(i)ce or all resources"), //
+ // EVENT("e", "", 0, "Pull events"), // TODO needs to be defined
+ FIND("find", "r | t | rt <name>", 2,
+ "Searches a (r)esource, resource (t)ype or resources of (rt)ype. Use * as wildcard.\n"
+ + " Will set $r for the last resource shown."), HELP("h", "", 0, "Shows this help"), //
+ INVOKE("i", "operation [params]", 1, "Triggers running an operation. If operation is '-list' it shows available operations"), //
+ MEASURE("m", "datatype property+", 1, "Triggers getting metric values. All need to be of the same data type. If datatype is '-list' it shows the defined metrics"), //
+ NATIVE("n", "e | d | s", 1, "Enables/disables native system or shows native status"), //
+ QUIT("quit", "", 0, "Terminates the application"), //
+ RESOURCES("res", "", 0, "Shows the discovered resources"), //
+ SET("set", "'resource' N", 2,
+ "Sets the resource id to work with. N can be a number or '$r' as result of last find resource call. 'id' is an alias for 'res'"), //
+ STDIN("stdin","",0, "Stop reading the batch file and wait for commands on stdin"), //
+ WAIT("w", "milliseconds", 1, "Waits the given amount of time"),
+ P_CONFIG("pc", "", 0, "Shows the plugin configuration of the current resource."),
+ R_CONFIG("rc", "", 0, "Shows the resource configuration of the current resource."),
+ SR_CONFIG("rcs", "", 0, "[parameters] set resource config "),
+ SP_CONFIG("pcs", "", 0, "[parameters] set plugin config ")
+ ;
+
+ private String abbrev;
+ private String args;
+ private String help;
+ private int minArgs; // minimum number of args needed
+
+ public String getArgs() {
+ return args;
+ }
+
+ public String getHelp() {
+ return help;
+ }
+
+ public int getMinArgs() {
+ return minArgs;
+ }
+
+ /**
+ * Construct a new Command
+ * @param abbrev Abbreviation for this command
+ * @param args Description of expected arguments
+ * @param minArgs Minumum number of arguments that need to be present
+ * @param help A short description of the command
+ */
+ private Command(String abbrev, String args, int minArgs, String help) {
+ this.abbrev = abbrev;
+ this.args = args;
+ this.minArgs = minArgs;
+ this.help = help;
+ }
+
+ public String getAbbrev() {
+ return abbrev;
+ }
+
+ public static Command get(String s) {
+
+ String upper = s.toUpperCase();
+
+ for (Command c : EnumSet.allOf(Command.class)) {
+ if (c.name().equals(upper) || c.getAbbrev().equals(s.toLowerCase()))
+ return c;
+ }
+ return null;
+ }
+}
diff --git a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/standaloneContainer/History.java b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/standaloneContainer/History.java
new file mode 100644
index 0000000..37b5bf1
--- /dev/null
+++ b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/standaloneContainer/History.java
@@ -0,0 +1,147 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2011 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+package org.rhq.core.pc.standaloneContainer;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.Writer;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Handle command line history
+ * @author Heiko W. Rupp
+ */
+public class History {
+
+ private static final String HISTORY_HELP = "!! : repeat the last action\n" + //
+ "!? : show the history of commands issued\n" + //
+ "!h : show this help\n" + //
+ "!nn : repeat history item with number nn\n" + //
+ "!w fileName : write history to file with name fileName\n" + //
+ "!dnn : delete history item with number nn";
+ /** Holder for the command history */
+ List<String> history = new ArrayList<String>(10);
+
+
+ /**
+ * Handle processing of the command history. This gives some csh like commands
+ * and records the commands given. Nice side effect is the possibility to write the
+ * history to disk and to use this later as input so that testing can be scripted.
+ * Commands are:
+ * <ul>
+ * <li>!! : repeat the last action</li>
+ * <li>!? : show the history</li>
+ * <li>!h : show history help</li>
+ * <li>!<i>nnn</i> : repeat history item with number <i>nnn</i></li>
+ * <li>!w <i>file</i> : write the history to the file <i>file</i></li>
+ * <li>!d<i>nnn</i> : delete the history item with number <i>nnn</i>
+ * </ul>
+ * @param answer the input given on the command line
+ * @return a command or '!' if no command substitution from the history was possible.
+ */
+ public String handleHistory(String answer) {
+
+ // Normal command - just return it
+ if (!answer.startsWith("!")) {
+ history.add(answer);
+ return answer;
+ }
+
+ // History commands
+ if (answer.startsWith("!?")) {
+ for (int i = 0; i < history.size(); i++)
+ System.out.println("[" + i + "]: " + history.get(i));
+ } else if (answer.startsWith("!h")) {
+ System.out.println(HISTORY_HELP);
+ return "!";
+ } else if (answer.startsWith("!!")) {
+ String text = history.get(history.size() - 1);
+ System.out.println(text);
+ history.add(text);
+ return text;
+ } else if (answer.matches("![0-9]+")) {
+ String id = answer.substring(1);
+ Integer i;
+ try {
+ i = Integer.valueOf(id);
+ } catch (NumberFormatException nfe) {
+ System.err.println(id + " is no valid history position");
+ return "!";
+ }
+ if (i > history.size()) {
+ System.err.println(i + " is no valid history position");
+ return "!";
+ } else {
+ String text = history.get(i);
+ System.out.println(text);
+ history.add(text);
+ return text;
+ }
+ } else if (answer.startsWith("!w")) {
+ String[] tokens = answer.split(" ");
+ if (tokens.length < 2) {
+ System.err.println("Not enough parameters. You need to give a file name");
+ }
+ File file = new File(tokens[1]);
+ try {
+ file.createNewFile();
+ if (file.canWrite()) {
+ Writer writer = new FileWriter(file);
+ for (String item : history) {
+ writer.write(item);
+ writer.write("\n");
+ }
+ writer.flush();
+ writer.close();
+ } else {
+ System.err.println("Can not write to file " + file);
+ }
+ } catch (IOException ioe) {
+ System.err.println("Saving the history to file " + file + " failed: " + ioe.getMessage());
+ }
+ return "!";
+ } else if (answer.matches("!d[0-9]+")) {
+ String id = answer.substring(2);
+ Integer i;
+ try {
+ i = Integer.valueOf(id);
+ } catch (NumberFormatException nfe) {
+ System.err.println(id + " is no valid history position");
+ return "!";
+ }
+ if (i > history.size()) {
+ System.err.println(i + " is no valid history position");
+ return "!";
+ }
+ history.remove(i.intValue());
+ return "!";
+ } else {
+ System.err.println(answer + " is no valid history command");
+ return "!";
+ }
+ return "!";
+ }
+
+ public int size() {
+ return history.size();
+ }
+
+}
commit 8573843d27eac077950e9a54246e651897637f0c
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Wed Mar 30 21:13:34 2011 -0400
format col
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/recent/operations/OperationsPortlet.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/recent/operations/OperationsPortlet.java
index c839109..dad4578 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/recent/operations/OperationsPortlet.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/recent/operations/OperationsPortlet.java
@@ -43,6 +43,7 @@ import org.rhq.core.domain.configuration.definition.PropertyDefinitionSimple;
import org.rhq.core.domain.configuration.definition.PropertySimpleType;
import org.rhq.core.domain.dashboard.DashboardPortlet;
import org.rhq.enterprise.gui.coregui.client.LinkManager;
+import org.rhq.enterprise.gui.coregui.client.components.table.TimestampCellFormatter;
import org.rhq.enterprise.gui.coregui.client.dashboard.AutoRefreshPortlet;
import org.rhq.enterprise.gui.coregui.client.dashboard.AutoRefreshPortletUtil;
import org.rhq.enterprise.gui.coregui.client.dashboard.CustomSettingsPortlet;
@@ -186,6 +187,7 @@ public class OperationsPortlet extends LocatableVLayout implements CustomSetting
ListGridField timeRecent = new ListGridField(RecentOperationsDataSource.Field.TIME.propertyName(),
RecentOperationsDataSource.Field.TIME.title(), WIDTH_RECENT_TIME);
+ TimestampCellFormatter.prepareDateField(timeRecent);
ListGridField statusRecent = new ListGridField(RecentOperationsDataSource.Field.STATUS.propertyName(),
RecentOperationsDataSource.Field.STATUS.title(), WIDTH_RECENT_STATUS);
@@ -215,6 +217,7 @@ public class OperationsPortlet extends LocatableVLayout implements CustomSetting
ListGridField timeNext = new ListGridField(ScheduledOperationsDataSource.Field.TIME.propertyName(),
ScheduledOperationsDataSource.Field.TIME.title(), WIDTH_SCHEDULED_TIME);
+ TimestampCellFormatter.prepareDateField(timeNext);
scheduledOperationsGrid.setFields(resourceNext, ancestryNext, operationNext, timeNext);
}
commit eac8b15a961194621d8c2ce8e09f338feb895760
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Wed Mar 30 20:56:02 2011 -0400
format cols
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/common/detail/operation/history/AbstractOperationHistoryDetailsView.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/common/detail/operation/history/AbstractOperationHistoryDetailsView.java
index 40a826d..27b1040 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/common/detail/operation/history/AbstractOperationHistoryDetailsView.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/common/detail/operation/history/AbstractOperationHistoryDetailsView.java
@@ -18,6 +18,10 @@
*/
package org.rhq.enterprise.gui.coregui.client.inventory.common.detail.operation.history;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
import com.smartgwt.client.types.Overflow;
import com.smartgwt.client.widgets.Canvas;
import com.smartgwt.client.widgets.Label;
@@ -30,7 +34,7 @@ import com.smartgwt.client.widgets.form.fields.LinkItem;
import com.smartgwt.client.widgets.form.fields.StaticTextItem;
import com.smartgwt.client.widgets.form.fields.events.ClickEvent;
import com.smartgwt.client.widgets.form.fields.events.ClickHandler;
-import com.smartgwt.client.widgets.layout.VLayout;
+
import org.rhq.core.domain.configuration.definition.ConfigurationDefinition;
import org.rhq.core.domain.operation.OperationDefinition;
import org.rhq.core.domain.operation.OperationHistory;
@@ -39,20 +43,17 @@ import org.rhq.enterprise.gui.coregui.client.BookmarkableView;
import org.rhq.enterprise.gui.coregui.client.ImageManager;
import org.rhq.enterprise.gui.coregui.client.ViewPath;
import org.rhq.enterprise.gui.coregui.client.components.configuration.ConfigurationEditor;
+import org.rhq.enterprise.gui.coregui.client.components.table.TimestampCellFormatter;
import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableHTMLPane;
import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableVLayout;
import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableVStack;
import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableWindow;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-
/**
* @author Greg Hinkle
*/
-public abstract class AbstractOperationHistoryDetailsView<T extends OperationHistory> extends LocatableVStack
- implements BookmarkableView {
+public abstract class AbstractOperationHistoryDetailsView<T extends OperationHistory> extends LocatableVStack implements
+ BookmarkableView {
private T operationHistory;
@@ -110,11 +111,11 @@ public abstract class AbstractOperationHistoryDetailsView<T extends OperationHis
OperationDefinition operationDefinition = operationHistory.getOperationDefinition();
ConfigurationDefinition parametersConfigurationDefinition = operationDefinition
- .getParametersConfigurationDefinition();
- if (parametersConfigurationDefinition != null &&
- !parametersConfigurationDefinition.getPropertyDefinitions().isEmpty()) {
+ .getParametersConfigurationDefinition();
+ if (parametersConfigurationDefinition != null
+ && !parametersConfigurationDefinition.getPropertyDefinitions().isEmpty()) {
ConfigurationEditor editor = new ConfigurationEditor(extendLocatorId("params"),
- parametersConfigurationDefinition, operationHistory.getParameters());
+ parametersConfigurationDefinition, operationHistory.getParameters());
editor.setReadOnly(true);
parametersSection.addMember(editor);
} else {
@@ -150,7 +151,7 @@ public abstract class AbstractOperationHistoryDetailsView<T extends OperationHis
StaticTextItem submittedItem = new StaticTextItem(AbstractOperationHistoryDataSource.Field.STARTED_TIME, MSG
.view_operationHistoryDetails_dateSubmitted());
- submittedItem.setValue(new Date(operationHistory.getStartedTime()));
+ submittedItem.setValue(TimestampCellFormatter.format(operationHistory.getStartedTime()));
items.add(submittedItem);
StaticTextItem completedItem = new StaticTextItem("completed", MSG.view_operationHistoryDetails_dateCompleted());
@@ -159,7 +160,8 @@ public abstract class AbstractOperationHistoryDetailsView<T extends OperationHis
} else if (status == OperationRequestStatus.CANCELED) {
completedItem.setValue(MSG.common_val_never());
} else {
- completedItem.setValue(new Date(operationHistory.getStartedTime() + operationHistory.getDuration()));
+ completedItem.setValue(TimestampCellFormatter.format(new Date(operationHistory.getStartedTime()
+ + operationHistory.getDuration())));
}
items.add(completedItem);
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/common/detail/operation/history/AbstractOperationHistoryListView.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/common/detail/operation/history/AbstractOperationHistoryListView.java
index e058004..5433940 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/common/detail/operation/history/AbstractOperationHistoryListView.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/common/detail/operation/history/AbstractOperationHistoryListView.java
@@ -19,10 +19,8 @@
package org.rhq.enterprise.gui.coregui.client.inventory.common.detail.operation.history;
import java.util.ArrayList;
-import java.util.Date;
import java.util.List;
-import com.google.gwt.i18n.client.DateTimeFormat;
import com.smartgwt.client.data.Criteria;
import com.smartgwt.client.data.DSRequest;
import com.smartgwt.client.data.Record;
@@ -46,6 +44,7 @@ import org.rhq.enterprise.gui.coregui.client.ImageManager;
import org.rhq.enterprise.gui.coregui.client.LinkManager;
import org.rhq.enterprise.gui.coregui.client.components.table.TableAction;
import org.rhq.enterprise.gui.coregui.client.components.table.TableSection;
+import org.rhq.enterprise.gui.coregui.client.components.table.TimestampCellFormatter;
import org.rhq.enterprise.gui.coregui.client.inventory.resource.AncestryUtil;
import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableHTMLPane;
import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableWindow;
@@ -143,16 +142,19 @@ public abstract class AbstractOperationHistoryListView<T extends AbstractOperati
ListGridField startedTimeField = new ListGridField(AbstractOperationHistoryDataSource.Field.STARTED_TIME);
startedTimeField.setAlign(Alignment.LEFT);
startedTimeField.setCellAlign(Alignment.LEFT);
- startedTimeField.setCellFormatter(new CellFormatter() {
+ startedTimeField.setCellFormatter(new TimestampCellFormatter() {
public String format(Object value, ListGridRecord record, int rowNum, int colNum) {
if (value != null) {
- Date date = (Date) value;
- return DateTimeFormat.getMediumDateTimeFormat().format(date);
+ return super.format(value, record, rowNum, colNum);
} else {
return "<i>" + MSG.view_operationHistoryList_notYetStarted() + "</i>";
}
}
});
+ startedTimeField.setShowHover(true);
+ startedTimeField.setHoverCustomizer(TimestampCellFormatter
+ .getHoverCustomizer(AbstractOperationHistoryDataSource.Field.STARTED_TIME));
+
return startedTimeField;
}
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/common/detail/operation/schedule/AbstractOperationScheduleListView.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/common/detail/operation/schedule/AbstractOperationScheduleListView.java
index b2c80ba..60f9efc 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/common/detail/operation/schedule/AbstractOperationScheduleListView.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/common/detail/operation/schedule/AbstractOperationScheduleListView.java
@@ -25,6 +25,7 @@ import com.smartgwt.client.widgets.grid.ListGridRecord;
import org.rhq.enterprise.gui.coregui.client.components.table.SubjectRecordCellFormatter;
import org.rhq.enterprise.gui.coregui.client.components.table.TableAction;
import org.rhq.enterprise.gui.coregui.client.components.table.TableSection;
+import org.rhq.enterprise.gui.coregui.client.components.table.TimestampCellFormatter;
/**
* @author Ian Springer
@@ -51,7 +52,8 @@ public abstract class AbstractOperationScheduleListView extends TableSection<Abs
subjectField.setCellFormatter(new SubjectRecordCellFormatter());
ListGridField nextFireTimeField = new ListGridField(AbstractOperationScheduleDataSource.Field.NEXT_FIRE_TIME,
- 190);
+ 190);
+ TimestampCellFormatter.prepareDateField(nextFireTimeField);
ListGridField descriptionField = new ListGridField(AbstractOperationScheduleDataSource.Field.DESCRIPTION);
commit f48ccec96ccbafafb3d002dc9e7fa462b2ee75cb
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Wed Mar 30 20:14:31 2011 -0400
fix col format
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/configuration/AbstractConfigurationHistoryDataSource.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/configuration/AbstractConfigurationHistoryDataSource.java
index 3d41d42..75c4bc4 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/configuration/AbstractConfigurationHistoryDataSource.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/configuration/AbstractConfigurationHistoryDataSource.java
@@ -26,7 +26,6 @@ import com.smartgwt.client.data.DataSourceField;
import com.smartgwt.client.data.Record;
import com.smartgwt.client.data.fields.DataSourceIntegerField;
import com.smartgwt.client.types.Alignment;
-import com.smartgwt.client.types.DateDisplayFormat;
import com.smartgwt.client.types.ListGridFieldType;
import com.smartgwt.client.widgets.Canvas;
import com.smartgwt.client.widgets.grid.CellFormatter;
@@ -43,6 +42,7 @@ import org.rhq.core.domain.criteria.AbstractResourceConfigurationUpdateCriteria;
import org.rhq.core.domain.resource.Resource;
import org.rhq.enterprise.gui.coregui.client.ErrorMessageWindow;
import org.rhq.enterprise.gui.coregui.client.LinkManager;
+import org.rhq.enterprise.gui.coregui.client.components.table.TimestampCellFormatter;
import org.rhq.enterprise.gui.coregui.client.gwt.ConfigurationGWTServiceAsync;
import org.rhq.enterprise.gui.coregui.client.gwt.GWTServiceLookup;
import org.rhq.enterprise.gui.coregui.client.inventory.resource.AncestryUtil;
@@ -155,13 +155,13 @@ public abstract class AbstractConfigurationHistoryDataSource<T extends AbstractR
ListGridField submittedTimeField = new ListGridField(Field.CREATED_TIME, MSG
.dataSource_configurationHistory_dateSubmitted());
submittedTimeField.setType(ListGridFieldType.DATE);
- submittedTimeField.setDateFormatter(DateDisplayFormat.TOLOCALESTRING);
+ TimestampCellFormatter.prepareDateField(submittedTimeField);
fields.add(submittedTimeField);
ListGridField completedTimeField = new ListGridField(Field.MODIFIED_TIME, MSG
.dataSource_configurationHistory_dateCompleted());
completedTimeField.setType(ListGridFieldType.DATE);
- completedTimeField.setDateFormatter(DateDisplayFormat.TOLOCALESTRING);
+ TimestampCellFormatter.prepareDateField(completedTimeField);
fields.add(completedTimeField);
ListGridField statusField = new ListGridField(Field.STATUS, MSG.common_title_status());
commit 9da6973e664b288b3ad21a2521685594e1691e36
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Wed Mar 30 20:02:51 2011 -0400
fix col format and hover
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/detail/configuration/HistoryGroupResourceConfigurationMembers.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/detail/configuration/HistoryGroupResourceConfigurationMembers.java
index ae28218..31520bd 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/detail/configuration/HistoryGroupResourceConfigurationMembers.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/detail/configuration/HistoryGroupResourceConfigurationMembers.java
@@ -52,6 +52,7 @@ import org.rhq.enterprise.gui.coregui.client.ImageManager;
import org.rhq.enterprise.gui.coregui.client.LinkManager;
import org.rhq.enterprise.gui.coregui.client.components.buttons.BackButton;
import org.rhq.enterprise.gui.coregui.client.components.table.Table;
+import org.rhq.enterprise.gui.coregui.client.components.table.TimestampCellFormatter;
import org.rhq.enterprise.gui.coregui.client.gwt.ConfigurationGWTServiceAsync;
import org.rhq.enterprise.gui.coregui.client.gwt.GWTServiceLookup;
import org.rhq.enterprise.gui.coregui.client.inventory.resource.AncestryUtil;
@@ -121,8 +122,10 @@ public class HistoryGroupResourceConfigurationMembers extends LocatableVLayout {
ListGridField fieldAncestry = AncestryUtil.setupAncestryListGridField();
ListGridField fieldDateCreated = new ListGridField(DataSource.Field.DATECREATED, MSG
.common_title_dateCreated());
+ TimestampCellFormatter.prepareDateField(fieldDateCreated);
ListGridField fieldLastUpdated = new ListGridField(DataSource.Field.LASTUPDATED, MSG
.common_title_lastUpdated());
+ TimestampCellFormatter.prepareDateField(fieldLastUpdated);
ListGridField fieldStatus = new ListGridField(DataSource.Field.STATUS, MSG.common_title_status());
ListGridField fieldUser = new ListGridField(DataSource.Field.USER, MSG.common_title_user());
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/detail/configuration/HistoryGroupResourceConfigurationTable.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/detail/configuration/HistoryGroupResourceConfigurationTable.java
index d6da7d0..35be43c 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/detail/configuration/HistoryGroupResourceConfigurationTable.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/detail/configuration/HistoryGroupResourceConfigurationTable.java
@@ -50,6 +50,7 @@ import org.rhq.enterprise.gui.coregui.client.LinkManager;
import org.rhq.enterprise.gui.coregui.client.components.table.AbstractTableAction;
import org.rhq.enterprise.gui.coregui.client.components.table.Table;
import org.rhq.enterprise.gui.coregui.client.components.table.TableActionEnablement;
+import org.rhq.enterprise.gui.coregui.client.components.table.TimestampCellFormatter;
import org.rhq.enterprise.gui.coregui.client.gwt.ConfigurationGWTServiceAsync;
import org.rhq.enterprise.gui.coregui.client.gwt.GWTServiceLookup;
import org.rhq.enterprise.gui.coregui.client.util.RPCDataSource;
@@ -80,6 +81,9 @@ public class HistoryGroupResourceConfigurationTable extends Table<HistoryGroupRe
ListGridField fieldStatus = new ListGridField(DataSource.Field.STATUS, MSG.common_title_status());
ListGridField fieldUser = new ListGridField(DataSource.Field.USER, MSG.common_title_user());
+ TimestampCellFormatter.prepareDateField(fieldDateCreated);
+ TimestampCellFormatter.prepareDateField(fieldLastUpdated);
+
fieldId.setWidth("10%");
fieldDateCreated.setWidth("35%");
fieldLastUpdated.setWidth("35%");
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/detail/inventory/HistoryGroupPluginConfigurationMembers.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/detail/inventory/HistoryGroupPluginConfigurationMembers.java
index b2f923c..2699dff 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/detail/inventory/HistoryGroupPluginConfigurationMembers.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/detail/inventory/HistoryGroupPluginConfigurationMembers.java
@@ -52,6 +52,7 @@ import org.rhq.enterprise.gui.coregui.client.ImageManager;
import org.rhq.enterprise.gui.coregui.client.LinkManager;
import org.rhq.enterprise.gui.coregui.client.components.buttons.BackButton;
import org.rhq.enterprise.gui.coregui.client.components.table.Table;
+import org.rhq.enterprise.gui.coregui.client.components.table.TimestampCellFormatter;
import org.rhq.enterprise.gui.coregui.client.gwt.ConfigurationGWTServiceAsync;
import org.rhq.enterprise.gui.coregui.client.gwt.GWTServiceLookup;
import org.rhq.enterprise.gui.coregui.client.inventory.resource.AncestryUtil;
@@ -120,8 +121,10 @@ public class HistoryGroupPluginConfigurationMembers extends LocatableVLayout {
ListGridField fieldAncestry = AncestryUtil.setupAncestryListGridField();
ListGridField fieldDateCreated = new ListGridField(DataSource.Field.DATECREATED, MSG
.common_title_dateCreated());
+ TimestampCellFormatter.prepareDateField(fieldDateCreated);
ListGridField fieldLastUpdated = new ListGridField(DataSource.Field.LASTUPDATED, MSG
.common_title_lastUpdated());
+ TimestampCellFormatter.prepareDateField(fieldLastUpdated);
ListGridField fieldStatus = new ListGridField(DataSource.Field.STATUS, MSG.common_title_status());
ListGridField fieldUser = new ListGridField(DataSource.Field.USER, MSG.common_title_user());
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/detail/inventory/HistoryGroupPluginConfigurationTable.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/detail/inventory/HistoryGroupPluginConfigurationTable.java
index 1c36f7c..9dcd1c5 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/detail/inventory/HistoryGroupPluginConfigurationTable.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/detail/inventory/HistoryGroupPluginConfigurationTable.java
@@ -50,6 +50,7 @@ import org.rhq.enterprise.gui.coregui.client.LinkManager;
import org.rhq.enterprise.gui.coregui.client.components.table.AbstractTableAction;
import org.rhq.enterprise.gui.coregui.client.components.table.Table;
import org.rhq.enterprise.gui.coregui.client.components.table.TableActionEnablement;
+import org.rhq.enterprise.gui.coregui.client.components.table.TimestampCellFormatter;
import org.rhq.enterprise.gui.coregui.client.gwt.ConfigurationGWTServiceAsync;
import org.rhq.enterprise.gui.coregui.client.gwt.GWTServiceLookup;
import org.rhq.enterprise.gui.coregui.client.util.RPCDataSource;
@@ -80,6 +81,9 @@ public class HistoryGroupPluginConfigurationTable extends Table<HistoryGroupPlug
ListGridField fieldStatus = new ListGridField(DataSource.Field.STATUS, MSG.common_title_status());
ListGridField fieldUser = new ListGridField(DataSource.Field.USER, MSG.common_title_user());
+ TimestampCellFormatter.prepareDateField(fieldDateCreated);
+ TimestampCellFormatter.prepareDateField(fieldLastUpdated);
+
fieldId.setWidth("10%");
fieldDateCreated.setWidth("35%");
fieldLastUpdated.setWidth("35%");
commit 6bb2125a164e9dfbdddce5a32cfbf4dc93c6a7d4
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Wed Mar 30 19:49:13 2011 -0400
unsure if this does anything- but I still can't get the hover to work - no idea why
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/AlertDetailsView.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/AlertDetailsView.java
index 17dbb52..1d64d92 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/AlertDetailsView.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/AlertDetailsView.java
@@ -29,6 +29,7 @@ import com.google.gwt.user.client.rpc.AsyncCallback;
import com.smartgwt.client.core.DataClass;
import com.smartgwt.client.data.Record;
import com.smartgwt.client.types.Alignment;
+import com.smartgwt.client.types.ListGridFieldType;
import com.smartgwt.client.widgets.form.DynamicForm;
import com.smartgwt.client.widgets.form.fields.FormItem;
import com.smartgwt.client.widgets.form.fields.StaticTextItem;
@@ -209,6 +210,7 @@ public class AlertDetailsView extends LocatableVLayout implements BookmarkableVi
ListGridField status = new ListGridField("status", MSG.view_alert_common_tab_notifications_status());
status.setWidth("50");
status.setAlign(Alignment.CENTER);
+ status.setType(ListGridFieldType.IMAGE);
status.setCellFormatter(new CellFormatter() {
public String format(Object value, ListGridRecord record, int rowNum, int colNum) {
String statusStr = record.getAttribute("status");
commit d9c77b890c647450837fb876c74e2d66c01ff789
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Wed Mar 30 19:48:33 2011 -0400
fix notificaton log tab
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/ImageManager.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/ImageManager.java
index f30c23b..58346f0 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/ImageManager.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/ImageManager.java
@@ -1,6 +1,7 @@
package org.rhq.enterprise.gui.coregui.client;
import org.rhq.core.domain.alert.AlertPriority;
+import org.rhq.core.domain.alert.notification.ResultState;
import org.rhq.core.domain.configuration.ConfigurationUpdateStatus;
import org.rhq.core.domain.event.EventSeverity;
import org.rhq.core.domain.measurement.AvailabilityType;
@@ -405,6 +406,25 @@ public class ImageManager {
return "subsystems/event/Events" + icon + "_16.png";
}
+ public static String getAlertNotificationResultIcon(ResultState status) {
+ if (status == null) {
+ status = ResultState.UNKNOWN;
+ }
+ switch (status) {
+ case SUCCESS:
+ return ImageManager.getAvailabilityIcon(Boolean.TRUE);
+ case FAILURE:
+ return ImageManager.getAvailabilityIcon(Boolean.FALSE);
+ case PARTIAL:
+ return ImageManager.getAvailabilityYellowIcon();
+ case DEFERRED:
+ return "[skin]/actions/redo.png"; // for lack of a better icon
+ case UNKNOWN:
+ default:
+ return ImageManager.getAvailabilityIcon(null);
+ }
+ }
+
/**
* This returns an icon of the badge (e.g. the red X or the blue I) without the
* event icon. This is used if you have a table of events and the user knows they are
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/AlertDataSource.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/AlertDataSource.java
index 71a698a..262f7d0 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/AlertDataSource.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/AlertDataSource.java
@@ -398,7 +398,7 @@ public class AlertDataSource extends RPCDataSource<Alert, AlertCriteria> {
for (AlertNotificationLog log : from.getAlertNotificationLogs()) {
DataClass dc = new DataClass();
dc.setAttribute("sender", log.getSender());
- dc.setAttribute("status", log.getResultState());
+ dc.setAttribute("status", log.getResultState().name());
dc.setAttribute("message", log.getMessage());
notifications[i++] = dc;
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/AlertDetailsView.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/AlertDetailsView.java
index 14cfc8a..17dbb52 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/AlertDetailsView.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/AlertDetailsView.java
@@ -32,6 +32,8 @@ import com.smartgwt.client.types.Alignment;
import com.smartgwt.client.widgets.form.DynamicForm;
import com.smartgwt.client.widgets.form.fields.FormItem;
import com.smartgwt.client.widgets.form.fields.StaticTextItem;
+import com.smartgwt.client.widgets.grid.CellFormatter;
+import com.smartgwt.client.widgets.grid.HoverCustomizer;
import com.smartgwt.client.widgets.grid.ListGrid;
import com.smartgwt.client.widgets.grid.ListGridField;
import com.smartgwt.client.widgets.grid.ListGridRecord;
@@ -39,10 +41,12 @@ import com.smartgwt.client.widgets.tab.Tab;
import com.smartgwt.client.widgets.tab.TabSet;
import org.rhq.core.domain.alert.Alert;
+import org.rhq.core.domain.alert.notification.ResultState;
import org.rhq.core.domain.criteria.AlertCriteria;
import org.rhq.core.domain.util.PageList;
import org.rhq.enterprise.gui.coregui.client.BookmarkableView;
import org.rhq.enterprise.gui.coregui.client.CoreGUI;
+import org.rhq.enterprise.gui.coregui.client.ImageManager;
import org.rhq.enterprise.gui.coregui.client.ViewPath;
import org.rhq.enterprise.gui.coregui.client.components.tab.NamedTab;
import org.rhq.enterprise.gui.coregui.client.components.tab.NamedTabSet;
@@ -198,12 +202,43 @@ public class AlertDetailsView extends LocatableVLayout implements BookmarkableVi
DataClass[] input = record.getAttributeAsRecordArray("notificationLogs");
ListGrid grid = getListGrid();
grid.setData((Record[]) input);
+
ListGridField sender = new ListGridField("sender", MSG.view_alert_common_tab_notifications_sender());
sender.setWidth("33%");
+
ListGridField status = new ListGridField("status", MSG.view_alert_common_tab_notifications_status());
- status.setWidth("33%");
+ status.setWidth("50");
+ status.setAlign(Alignment.CENTER);
+ status.setCellFormatter(new CellFormatter() {
+ public String format(Object value, ListGridRecord record, int rowNum, int colNum) {
+ String statusStr = record.getAttribute("status");
+ ResultState statusEnum = (statusStr == null) ? ResultState.UNKNOWN : ResultState.valueOf(statusStr);
+ return imgHTML(ImageManager.getAlertNotificationResultIcon(statusEnum));
+ }
+ });
+ status.setShowHover(true);
+ status.setHoverCustomizer(new HoverCustomizer() {
+ public String hoverHTML(Object value, ListGridRecord record, int rowNum, int colNum) {
+ String statusStr = record.getAttribute("status");
+ ResultState statusEnum = (statusStr == null) ? ResultState.UNKNOWN : ResultState.valueOf(statusStr);
+ switch (statusEnum) {
+ case SUCCESS:
+ return MSG.common_status_success();
+ case FAILURE:
+ return MSG.common_status_failed();
+ case PARTIAL:
+ return MSG.common_status_partial();
+ case DEFERRED:
+ return MSG.common_status_deferred();
+ case UNKNOWN:
+ default:
+ return MSG.common_status_unknown();
+ }
+ }
+ });
+
ListGridField message = new ListGridField("message", MSG.view_alert_common_tab_notifications_message());
- message.setWidth("34%");
+ message.setWidth("*");
grid.setFields(sender, status, message);
}
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/bundle/deployment/BundleDeploymentView.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/bundle/deployment/BundleDeploymentView.java
index 1838e14..c00a454 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/bundle/deployment/BundleDeploymentView.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/bundle/deployment/BundleDeploymentView.java
@@ -23,14 +23,12 @@
package org.rhq.enterprise.gui.coregui.client.bundle.deployment;
import java.util.ArrayList;
-import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.smartgwt.client.types.AnimationEffect;
import com.smartgwt.client.types.AutoFitWidthApproach;
-import com.smartgwt.client.types.DateDisplayFormat;
import com.smartgwt.client.types.ListGridFieldType;
import com.smartgwt.client.util.BooleanCallback;
import com.smartgwt.client.util.SC;
@@ -74,6 +72,7 @@ import org.rhq.enterprise.gui.coregui.client.bundle.revert.BundleRevertWizard;
import org.rhq.enterprise.gui.coregui.client.components.HeaderLabel;
import org.rhq.enterprise.gui.coregui.client.components.buttons.BackButton;
import org.rhq.enterprise.gui.coregui.client.components.table.Table;
+import org.rhq.enterprise.gui.coregui.client.components.table.TimestampCellFormatter;
import org.rhq.enterprise.gui.coregui.client.components.tagging.TagEditorView;
import org.rhq.enterprise.gui.coregui.client.components.tagging.TagsChangedCallback;
import org.rhq.enterprise.gui.coregui.client.gwt.BundleGWTServiceAsync;
@@ -164,8 +163,8 @@ public class BundleDeploymentView extends LocatableVLayout implements Bookmarkab
bundleVersionName.setTarget("_self");
StaticTextItem deployed = new StaticTextItem("deployed", MSG.view_bundle_deployed());
- deployed.setDateFormatter(DateDisplayFormat.TOLOCALESTRING);
- deployed.setValue(new Date(deployment.getCtime()));
+ deployed.setValue(TimestampCellFormatter.format(deployment.getCtime(),
+ TimestampCellFormatter.DATE_TIME_FORMAT_FULL));
StaticTextItem deployedBy = new StaticTextItem("deployedBy", MSG.view_bundle_deploy_deployedBy());
deployedBy.setValue(deployment.getSubjectName());
diff --git a/modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages.properties b/modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages.properties
index c5f4d20..1867bf7 100644
--- a/modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages.properties
+++ b/modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages.properties
@@ -235,6 +235,8 @@ common_status_failed = Failed
common_status_inprogress = In Progress
common_status_canceled = Canceled
common_status_unknown = Unknown
+common_status_deferred = Deferred
+common_status_partial = Partial
# 1st, 2nd, 3rd, 4th, etc.
common_val_n1st = {0}st
commit caf6832295d8c0a44cfd77a251a530e28b53c0be
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Wed Mar 30 17:18:11 2011 -0400
fix fields
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/definitions/AbstractAlertDefinitionsDataSource.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/definitions/AbstractAlertDefinitionsDataSource.java
index afcb435..c221bd4 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/definitions/AbstractAlertDefinitionsDataSource.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/definitions/AbstractAlertDefinitionsDataSource.java
@@ -30,7 +30,6 @@ import com.smartgwt.client.data.Record;
import com.smartgwt.client.data.fields.DataSourceImageField;
import com.smartgwt.client.data.fields.DataSourceTextField;
import com.smartgwt.client.types.Alignment;
-import com.smartgwt.client.types.DateDisplayFormat;
import com.smartgwt.client.types.FieldType;
import com.smartgwt.client.types.ListGridFieldType;
import com.smartgwt.client.widgets.grid.HoverCustomizer;
@@ -42,6 +41,7 @@ import org.rhq.core.domain.criteria.AlertDefinitionCriteria;
import org.rhq.core.domain.util.PageList;
import org.rhq.enterprise.gui.coregui.client.CoreGUI;
import org.rhq.enterprise.gui.coregui.client.ImageManager;
+import org.rhq.enterprise.gui.coregui.client.components.table.TimestampCellFormatter;
import org.rhq.enterprise.gui.coregui.client.gwt.GWTServiceLookup;
import org.rhq.enterprise.gui.coregui.client.util.RPCDataSource;
@@ -87,13 +87,13 @@ public abstract class AbstractAlertDefinitionsDataSource extends
ListGridField ctimeField = new ListGridField(FIELD_CTIME, MSG.view_alerts_field_created_time());
ctimeField.setType(ListGridFieldType.DATE);
- ctimeField.setDateFormatter(DateDisplayFormat.TOLOCALESTRING);
+ TimestampCellFormatter.prepareDateField(ctimeField);
ctimeField.setWidth("15%");
fields.add(ctimeField);
ListGridField mtimeField = new ListGridField(FIELD_MTIME, MSG.view_alerts_field_modified_time());
mtimeField.setType(ListGridFieldType.DATE);
- mtimeField.setDateFormatter(DateDisplayFormat.TOLOCALESTRING);
+ TimestampCellFormatter.prepareDateField(mtimeField);
mtimeField.setWidth("15%");
fields.add(mtimeField);
commit e3ca14ca6588adbc11c58c1fffca0c93841fa88d
Author: Jay Shaughnessy <jshaughn(a)redhat.com>
Date: Wed Mar 30 17:46:34 2011 -0400
Fix an issue when performing direct navigation to bookmarkable subtab views.
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/common/detail/AbstractTwoLevelTabSetView.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/common/detail/AbstractTwoLevelTabSetView.java
index 04d6410..cac30b2 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/common/detail/AbstractTwoLevelTabSetView.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/common/detail/AbstractTwoLevelTabSetView.java
@@ -247,12 +247,19 @@ public abstract class AbstractTwoLevelTabSetView<T, U extends Layout> extends Lo
// select the subTab (this does not fire an event, just sets the subtab)
tab.getLayout().selectSubTab(subtab);
- // now that the tab/subtab is determined, if currently selected tab is not the desired tab, then
- // select it now (firing a new event).
+ // the target tab/subtab is now determined. if the currently selected tab is not the target tab then
+ // select it now.
if (!tab.equals(this.tabSet.getSelectedTab())) {
- this.tabSet.setIgnoreSelectEvents(false);
+
+ // Fire a tab selection event only if we're at the end of the path. If not then it is assumed that
+ // the subtab view is a BookmarkableView and the navigation will continue in that way, below.
+ if (viewPath.isEnd()) {
+ this.tabSet.setIgnoreSelectEvents(false);
+ this.tabSet.selectTab(tab);
+ return;
+ }
+
this.tabSet.selectTab(tab);
- return;
}
// if the desired tab/subtab are already selected, now we can render the subtab canvas
commit 7e2125b7c5e89bb921be4b0aa2ccb203401ec62e
Author: Jay Shaughnessy <jshaughn(a)redhat.com>
Date: Wed Mar 30 17:45:27 2011 -0400
Fix a null protection issue.
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/AlertHistoryView.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/AlertHistoryView.java
index e321819..2746c41 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/AlertHistoryView.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/AlertHistoryView.java
@@ -24,6 +24,7 @@ import java.util.Arrays;
import java.util.LinkedHashMap;
import com.google.gwt.user.client.rpc.AsyncCallback;
+import com.smartgwt.client.data.ResultSet;
import com.smartgwt.client.data.SortSpecifier;
import com.smartgwt.client.types.MultipleAppearance;
import com.smartgwt.client.types.SortDirection;
@@ -169,7 +170,8 @@ public class AlertHistoryView extends TableSection<AlertDataSource> {
new TableAction() {
public boolean isEnabled(ListGridRecord[] selection) {
ListGrid grid = getListGrid();
- return (hasWriteAccess && grid != null && !grid.getResultSet().isEmpty());
+ ResultSet resultSet = (null != grid) ? grid.getResultSet() : null;
+ return (hasWriteAccess && grid != null && resultSet != null && !resultSet.isEmpty());
}
public void executeAction(ListGridRecord[] selection, Object actionValue) {
@@ -180,7 +182,8 @@ public class AlertHistoryView extends TableSection<AlertDataSource> {
new TableAction() {
public boolean isEnabled(ListGridRecord[] selection) {
ListGrid grid = getListGrid();
- return (hasWriteAccess && grid != null && !grid.getResultSet().isEmpty());
+ ResultSet resultSet = (null != grid) ? grid.getResultSet() : null;
+ return (hasWriteAccess && grid != null && resultSet != null && !resultSet.isEmpty());
}
public void executeAction(ListGridRecord[] selection, Object actionValue) {
commit ed227f84f309a55d2e7fe06169cdb1b4cb2ab97d
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Wed Mar 30 16:59:02 2011 -0400
group def interval spinner should step every 1m
label it as (ms) so people know the units
fix some columns
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/table/TimestampCellFormatter.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/table/TimestampCellFormatter.java
index 53a0209..260ed01 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/table/TimestampCellFormatter.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/table/TimestampCellFormatter.java
@@ -23,7 +23,7 @@ public class TimestampCellFormatter implements CellFormatter {
private DateTimeFormat dateTimeFormat;
/**
- * Uses SHORT format.
+ * Uses MEDIUM format.
*/
public TimestampCellFormatter() {
this(DATE_TIME_FORMAT_MEDIUM);
@@ -40,7 +40,7 @@ public class TimestampCellFormatter implements CellFormatter {
/**
* @param value
- * @return SHORT format for value
+ * @return MEDIUM format for value
*/
public static String format(Object value) {
return format(value, DATE_TIME_FORMAT_MEDIUM);
@@ -94,15 +94,27 @@ public class TimestampCellFormatter implements CellFormatter {
return new HoverCustomizer() {
public String hoverHTML(Object value, ListGridRecord record, int rowNum, int colNum) {
Date attribValue = record.getAttributeAsDate(dateTimeAttributeName);
- if (attribValue != null) {
- StringBuilder sb = new StringBuilder("<p style='width:300px'>");
- sb.append(format(attribValue, DATE_TIME_FORMAT_FULL));
- sb.append("</p>");
- return sb.toString();
- } else {
- return null;
- }
+ return getHoverDateString(attribValue);
}
};
}
+
+ /**
+ * Returns an HTML string that can be used in as hover for a date field.
+ * It formats the date in the FULL format.
+ *
+ * @param date
+ * @return HTML string that shows the date in FULL format,
+ * or <code>null</code> if <code>date</code> is <code>null</code>
+ */
+ public static String getHoverDateString(Date date) {
+ if (date != null) {
+ StringBuilder sb = new StringBuilder("<p style='width:300px'>");
+ sb.append(format(date, DATE_TIME_FORMAT_FULL));
+ sb.append("</p>");
+ return sb.toString();
+ } else {
+ return null;
+ }
+ }
}
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/definitions/GroupDefinitionDataSource.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/definitions/GroupDefinitionDataSource.java
index cef860a..0207062 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/definitions/GroupDefinitionDataSource.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/definitions/GroupDefinitionDataSource.java
@@ -86,7 +86,7 @@ public class GroupDefinitionDataSource extends RPCDataSource<GroupDefinition, Re
// it is a Long, but there is no DataSourceLongField and I've seen problems trying to use anything other than text field
DataSourceTextField lastCalculationTimeIntervalField = new DataSourceTextField("lastCalculationTime", MSG
- .view_dynagroup_recalculationInterval());
+ .view_dynagroup_lastCalculationTime());
fields.add(lastCalculationTimeIntervalField);
// it is a Long, but there is no DataSourceLongField and I've seen problems trying to use anything other than text field
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/definitions/GroupDefinitionListView.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/definitions/GroupDefinitionListView.java
index 4a9106b..9106e60 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/definitions/GroupDefinitionListView.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/definitions/GroupDefinitionListView.java
@@ -18,6 +18,7 @@
*/
package org.rhq.enterprise.gui.coregui.client.inventory.groups.definitions;
+import java.util.Date;
import java.util.Set;
import com.google.gwt.user.client.History;
@@ -25,6 +26,7 @@ import com.google.gwt.user.client.rpc.AsyncCallback;
import com.smartgwt.client.types.ListGridFieldType;
import com.smartgwt.client.widgets.Canvas;
import com.smartgwt.client.widgets.grid.CellFormatter;
+import com.smartgwt.client.widgets.grid.HoverCustomizer;
import com.smartgwt.client.widgets.grid.ListGridField;
import com.smartgwt.client.widgets.grid.ListGridRecord;
@@ -47,7 +49,7 @@ import org.rhq.enterprise.gui.coregui.client.util.message.Message.Severity;
* @author Greg Hinkle
* @author Joseph Marques
*/
-public class GroupDefinitionListView extends TableSection {
+public class GroupDefinitionListView extends TableSection<GroupDefinitionDataSource> {
private static final String TITLE = MSG.view_dynagroup_definitions();
public GroupDefinitionListView(String locatorId, String headerIcon) {
@@ -84,6 +86,17 @@ public class GroupDefinitionListView extends TableSection {
return super.format(value, record, rowNum, colNum);
}
});
+ lastCalculationTimeField.setShowHover(true);
+ lastCalculationTimeField.setHoverCustomizer(new HoverCustomizer() {
+ public String hoverHTML(Object value, ListGridRecord record, int rowNum, int colNum) {
+ String attribValue = record.getAttribute("lastCalculationTime");
+ if (attribValue != null) {
+ return TimestampCellFormatter.getHoverDateString(new Date(Long.valueOf(attribValue).longValue()));
+ } else {
+ return null;
+ }
+ }
+ });
ListGridField nextCalculationTimeField = new ListGridField("nextCalculationTime", MSG
.view_dynagroup_nextCalculationTime(), 175);
@@ -95,6 +108,18 @@ public class GroupDefinitionListView extends TableSection {
return super.format(value, record, rowNum, colNum);
}
});
+ nextCalculationTimeField.setShowHover(true);
+ nextCalculationTimeField.setHoverCustomizer(new HoverCustomizer() {
+ public String hoverHTML(Object value, ListGridRecord record, int rowNum, int colNum) {
+ String attribValue = record.getAttribute("nextCalculationTime");
+ if (attribValue != null && !("0".equals(attribValue.toString()))) {
+ return TimestampCellFormatter.getHoverDateString(new Date(Long.valueOf(attribValue).longValue()));
+ } else {
+ return null;
+ }
+ }
+ });
+
setListGridFields(idField, nameField, descriptionField, expressionField, lastCalculationTimeField,
nextCalculationTimeField);
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/definitions/SingleGroupDefinitionView.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/definitions/SingleGroupDefinitionView.java
index 865e03b..a302455 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/definitions/SingleGroupDefinitionView.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/definitions/SingleGroupDefinitionView.java
@@ -397,6 +397,7 @@ public class SingleGroupDefinitionView extends LocatableVLayout implements Bookm
//recalculationInterval.setWrapTitle(false); // do not set this - it causes the form to grow abnormally width-wise for some reason
recalculationInterval.setMin(0);
recalculationInterval.setDefaultValue(0);
+ recalculationInterval.setStep(60000); // the recalc interval is in milliseconds, step up one minute at a time
}
public static LinkedHashMap<String, String> getTemplates() {
diff --git a/modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages.properties b/modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages.properties
index ae8ccbd..c5f4d20 100644
--- a/modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages.properties
+++ b/modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages.properties
@@ -1707,7 +1707,7 @@ view_titleBar_group_failInfo = Failed to get general info on group [{0}] with ID
view_titleBar_group_summary_collapsedTooltip = Click to show more details for this group
view_titleBar_group_summary_expandedTooltip = Click to hide details for this group
view_dynagroup_expressionSet = Expression Set
-view_dynagroup_recalculationInterval = Recalculation Interval
+view_dynagroup_recalculationInterval = Recalculation Interval (ms)
view_dynagroup_lastCalculationTime = Last Calculation Time
view_dynagroup_nextCalculationTime = Next Calculation Time
view_dynagroup_definitionCreated = You have successfully created a group definition named [{0}]
commit 9eaaf6b98d89a8756f12f5d8664e495ba11b91d3
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Wed Mar 30 16:24:44 2011 -0400
protect against null attribute value
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/table/TimestampCellFormatter.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/table/TimestampCellFormatter.java
index f17c62f..53a0209 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/table/TimestampCellFormatter.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/table/TimestampCellFormatter.java
@@ -92,12 +92,16 @@ public class TimestampCellFormatter implements CellFormatter {
public static HoverCustomizer getHoverCustomizer(final String dateTimeAttributeName) {
return new HoverCustomizer() {
-
public String hoverHTML(Object value, ListGridRecord record, int rowNum, int colNum) {
- StringBuilder sb = new StringBuilder("<p style='width:300px'>");
- sb.append(format(record.getAttributeAsDate(dateTimeAttributeName), DATE_TIME_FORMAT_FULL));
- sb.append("</p>");
- return sb.toString();
+ Date attribValue = record.getAttributeAsDate(dateTimeAttributeName);
+ if (attribValue != null) {
+ StringBuilder sb = new StringBuilder("<p style='width:300px'>");
+ sb.append(format(attribValue, DATE_TIME_FORMAT_FULL));
+ sb.append("</p>");
+ return sb.toString();
+ } else {
+ return null;
+ }
}
};
}
commit 4ca57bc786e2ce8772dce7fd0981f9e618d6b67e
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Wed Mar 30 16:09:31 2011 -0400
format more cols
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/recent/imported/RecentlyAddedResourceDS.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/recent/imported/RecentlyAddedResourceDS.java
index cde6b9e..a9c1dc7 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/recent/imported/RecentlyAddedResourceDS.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/recent/imported/RecentlyAddedResourceDS.java
@@ -28,7 +28,6 @@ import java.util.Date;
import java.util.List;
import com.allen_sauer.gwt.log.client.Log;
-import com.google.gwt.i18n.client.DateTimeFormat;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.smartgwt.client.data.DSRequest;
import com.smartgwt.client.data.DSResponse;
@@ -185,7 +184,7 @@ public class RecentlyAddedResourceDS extends DataSource {
setAttribute("id", id);
setAttribute("parentId", parentId);
setAttribute("name", recentlyAdded.getName());
- setAttribute("timestamp", DateTimeFormat.getMediumDateTimeFormat().format(dateAdded));
+ setAttribute("timestamp", dateAdded);
setIsFolder(recentlyAdded.getParentId() == 0);
}
}
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/recent/imported/RecentlyAddedResourcesPortlet.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/recent/imported/RecentlyAddedResourcesPortlet.java
index e570a04..c4685da 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/recent/imported/RecentlyAddedResourcesPortlet.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/recent/imported/RecentlyAddedResourcesPortlet.java
@@ -38,6 +38,7 @@ import com.smartgwt.client.widgets.tree.TreeGrid;
import org.rhq.core.domain.configuration.PropertySimple;
import org.rhq.core.domain.dashboard.DashboardPortlet;
import org.rhq.enterprise.gui.coregui.client.components.HeaderLabel;
+import org.rhq.enterprise.gui.coregui.client.components.table.TimestampCellFormatter;
import org.rhq.enterprise.gui.coregui.client.dashboard.AutoRefreshPortlet;
import org.rhq.enterprise.gui.coregui.client.dashboard.AutoRefreshPortletUtil;
import org.rhq.enterprise.gui.coregui.client.dashboard.CustomSettingsPortlet;
@@ -95,7 +96,7 @@ public class RecentlyAddedResourcesPortlet extends LocatableVLayout implements C
});
ListGridField timestampField = new ListGridField("timestamp", MSG.common_title_timestamp());
-
+ TimestampCellFormatter.prepareDateField(timestampField);
treeGrid.setFields(resourceNameField, timestampField);
if (!simple) {
commit 13609683074b17265180c9b704479989b2095d16
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Wed Mar 30 14:52:32 2011 -0400
quick fix some more columns and hovers
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/bundle/deployment/BundleDeploymentListView.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/bundle/deployment/BundleDeploymentListView.java
index b99ab75..42711b6 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/bundle/deployment/BundleDeploymentListView.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/bundle/deployment/BundleDeploymentListView.java
@@ -25,7 +25,6 @@ package org.rhq.enterprise.gui.coregui.client.bundle.deployment;
import java.util.HashMap;
import com.smartgwt.client.data.Criteria;
-import com.smartgwt.client.types.DateDisplayFormat;
import com.smartgwt.client.types.ListGridFieldType;
import com.smartgwt.client.widgets.events.DoubleClickEvent;
import com.smartgwt.client.widgets.events.DoubleClickHandler;
@@ -42,6 +41,7 @@ import org.rhq.enterprise.gui.coregui.client.ErrorMessageWindow;
import org.rhq.enterprise.gui.coregui.client.LinkManager;
import org.rhq.enterprise.gui.coregui.client.bundle.list.BundleVersionDataSource;
import org.rhq.enterprise.gui.coregui.client.components.table.Table;
+import org.rhq.enterprise.gui.coregui.client.components.table.TimestampCellFormatter;
/**
* @author Greg Hinkle
@@ -70,9 +70,8 @@ public class BundleDeploymentListView extends Table<BundleDeploymentDataSource>
.common_title_status());
ListGridField deployTimeField = new ListGridField(BundleDeploymentDataSource.FIELD_DEPLOY_TIME, MSG
.view_bundle_deploy_time());
-
+ TimestampCellFormatter.prepareDateField(deployTimeField);
deployTimeField.setType(ListGridFieldType.DATE);
- deployTimeField.setDateFormatter(DateDisplayFormat.TOLOCALESTRING);
// only users that are authorized can see deployments
if (canManageBundles) {
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/bundle/deployment/BundleResourceDeploymentHistoryListView.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/bundle/deployment/BundleResourceDeploymentHistoryListView.java
index f9dbe30..d1e5a74 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/bundle/deployment/BundleResourceDeploymentHistoryListView.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/bundle/deployment/BundleResourceDeploymentHistoryListView.java
@@ -50,6 +50,7 @@ import org.rhq.core.domain.bundle.BundleDeploymentStatus;
import org.rhq.core.domain.bundle.BundleResourceDeployment;
import org.rhq.core.domain.bundle.BundleResourceDeploymentHistory;
import org.rhq.enterprise.gui.coregui.client.ErrorMessageWindow;
+import org.rhq.enterprise.gui.coregui.client.components.table.TimestampCellFormatter;
import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableDynamicForm;
import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableListGrid;
import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableVLayout;
@@ -103,6 +104,7 @@ public class BundleResourceDeploymentHistoryListView extends LocatableVLayout {
user.setHidden(true);
ListGridField timestamp = new ListGridField("timestamp", MSG.common_title_timestamp());
+ TimestampCellFormatter.prepareDateField(timestamp);
timestamp.setWidth("40%");
ListGridField status = new ListGridField("status", MSG.common_title_status());
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/bundle/destination/BundleDestinationListView.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/bundle/destination/BundleDestinationListView.java
index e95626c..d3ca12c 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/bundle/destination/BundleDestinationListView.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/bundle/destination/BundleDestinationListView.java
@@ -25,7 +25,6 @@ package org.rhq.enterprise.gui.coregui.client.bundle.destination;
import java.util.HashMap;
import com.smartgwt.client.data.Criteria;
-import com.smartgwt.client.types.DateDisplayFormat;
import com.smartgwt.client.types.ListGridFieldType;
import com.smartgwt.client.widgets.events.DoubleClickEvent;
import com.smartgwt.client.widgets.events.DoubleClickHandler;
@@ -38,6 +37,7 @@ import org.rhq.core.domain.bundle.BundleDeploymentStatus;
import org.rhq.enterprise.gui.coregui.client.CoreGUI;
import org.rhq.enterprise.gui.coregui.client.LinkManager;
import org.rhq.enterprise.gui.coregui.client.components.table.Table;
+import org.rhq.enterprise.gui.coregui.client.components.table.TimestampCellFormatter;
/**
* @author Greg Hinkle
@@ -74,7 +74,7 @@ public class BundleDestinationListView extends Table<BundleDestinationDataSource
BundleDestinationDataSource.FIELD_LATEST_DEPLOY_STATUS, MSG.view_bundle_dest_lastDeploymentStatus());
latestDeploymentDateField.setType(ListGridFieldType.DATE);
- latestDeploymentDateField.setDateFormatter(DateDisplayFormat.TOLOCALESTRING);
+ TimestampCellFormatter.prepareDateField(latestDeploymentDateField);
nameField.setCellFormatter(new CellFormatter() {
public String format(Object o, ListGridRecord listGridRecord, int i, int i1) {
@@ -107,6 +107,7 @@ public class BundleDestinationListView extends Table<BundleDestinationDataSource
latestDeploymentStatusField.setValueIcons(statusIcons);
latestDeploymentStatusField.setValueIconHeight(11);
latestDeploymentStatusField.setValueIconWidth(11);
+ latestDeploymentStatusField.setShowValueIconOnly(true);
idField.setWidth(50);
nameField.setWidth("20%");
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/detail/GeneralProperties.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/detail/GeneralProperties.java
index dd7d3f3..ba62aa4 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/detail/GeneralProperties.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/detail/GeneralProperties.java
@@ -19,7 +19,6 @@
package org.rhq.enterprise.gui.coregui.client.inventory.groups.detail;
import java.util.ArrayList;
-import java.util.Date;
import java.util.List;
import com.google.gwt.user.client.rpc.AsyncCallback;
@@ -40,6 +39,7 @@ import org.rhq.enterprise.gui.coregui.client.components.form.EditableFormItem;
import org.rhq.enterprise.gui.coregui.client.components.form.EnhancedDynamicForm;
import org.rhq.enterprise.gui.coregui.client.components.form.StringLengthValidator;
import org.rhq.enterprise.gui.coregui.client.components.form.EditableFormItem.ValueEditedHandler;
+import org.rhq.enterprise.gui.coregui.client.components.table.TimestampCellFormatter;
import org.rhq.enterprise.gui.coregui.client.gwt.GWTServiceLookup;
import org.rhq.enterprise.gui.coregui.client.gwt.ResourceGroupGWTServiceAsync;
import org.rhq.enterprise.gui.coregui.client.util.message.Message;
@@ -199,11 +199,11 @@ public class GeneralProperties extends LocatableVLayout {
formItems.add(recursiveItem);
StaticTextItem createdItem = new StaticTextItem("created", MSG.common_title_dateCreated());
- createdItem.setValue(new Date(group.getCtime()));
+ createdItem.setValue(TimestampCellFormatter.format(group.getCtime()));
formItems.add(createdItem);
StaticTextItem lastModifiedItem = new StaticTextItem("lastModified", MSG.common_title_lastUpdated());
- lastModifiedItem.setValue(new Date(group.getMtime()));
+ lastModifiedItem.setValue(TimestampCellFormatter.format(group.getMtime()));
formItems.add(lastModifiedItem);
StaticTextItem lastModifiedByItem = new StaticTextItem("lastModifiedBy", MSG.common_title_lastUpdatedBy());
commit b73e1a2fdeca8cf1d1e5739e79807fe1ba8afcf7
Author: Ian Springer <ian.springer(a)redhat.com>
Date: Wed Mar 30 15:53:27 2011 -0400
remove unused http://www.dyn-web.com/ javascript code (https://bugzilla.redhat.com/show_bug.cgi?id=536549)
diff --git a/modules/enterprise/gui/portal-war/src/main/webapp/js/popup.js b/modules/enterprise/gui/portal-war/src/main/webapp/js/popup.js
index ca82a55..c9e6b2e 100644
--- a/modules/enterprise/gui/portal-war/src/main/webapp/js/popup.js
+++ b/modules/enterprise/gui/portal-war/src/main/webapp/js/popup.js
@@ -123,122 +123,3 @@ var overlay = {
WindowResizeTracker.addListener(function() {
overlay.refresh();
});
-
-/*************************************************************************
- This code is from Dynamic Web Coding at http://www.dyn-web.com/
- Copyright 2003 by Sharon Paine
- See Terms of Use at http://www.dyn-web.com/bus/terms.html
- regarding conditions under which you may use this code.
- This notice must be retained in the code as is!
-*************************************************************************/
-
-var viewport = {
- getWinWidth: function () {
- this.width = 0;
- if (window.innerWidth) this.width = window.innerWidth - 18;
- else if (document.documentElement && document.documentElement.clientWidth)
- this.width = document.documentElement.clientWidth;
- else if (document.body && document.body.clientWidth)
- this.width = document.body.clientWidth;
- },
-
- getWinHeight: function () {
- this.height = 0;
- if (window.innerHeight) this.height = window.innerHeight - 18;
- else if (document.documentElement && document.documentElement.clientHeight)
- this.height = document.documentElement.clientHeight;
- else if (document.body && document.body.clientHeight)
- this.height = document.body.clientHeight;
- },
-
- getScrollX: function () {
- this.scrollX = 0;
- if (typeof window.pageXOffset == "number") this.scrollX = window.pageXOffset
-;
- else if (document.documentElement && document.documentElement.scrollLeft)
- this.scrollX = document.documentElement.scrollLeft;
- else if (document.body && document.body.scrollLeft)
- this.scrollX = document.body.scrollLeft;
- else if (window.scrollX) this.scrollX = window.scrollX;
- },
-
- getScrollY: function () {
- this.scrollY = 0;
- if (typeof window.pageYOffset == "number") this.scrollY = window.pageYOffset
-;
- else if (document.documentElement && document.documentElement.scrollTop)
- this.scrollY = document.documentElement.scrollTop;
- else if (document.body && document.body.scrollTop)
- this.scrollY = document.body.scrollTop;
- else if (window.scrollY) this.scrollY = window.scrollY;
- },
-
- getAll: function () {
- this.getWinWidth(); this.getWinHeight();
- this.getScrollX(); this.getScrollY();
- }
-
-}
-
-var menuLayers = {
- timer: null,
- activeMenuID: null,
- offX: 3, // horizontal offset
- offY: 5, // vertical offset
-
- show: function(id, e) {
- var mnu = $? $(id): null;
- if (!mnu) return;
- this.activeMenuID = id;
- if ( mnu.onmouseout == null ) mnu.onmouseout = this.mouseoutCheck;
- if ( mnu.onmouseover == null ) mnu.onmouseover = this.clearTimer;
- viewport.getAll();
- this.position(mnu, e);
- },
-
- hide: function() {
- this.clearTimer();
- if (this.activeMenuID && $)
- this.timer = setTimeout("$('"+menuLayers.activeMenuID+"').style.visibility = 'hidden'", 200);
- },
-
- position: function(mnu, e) {
- var x = e.pageX? e.pageX: e.clientX + viewport.scrollX;
- var y = e.pageY? e.pageY: e.clientY + viewport.scrollY;
-
- if ( x + mnu.offsetWidth + this.offX > viewport.width + viewport.scrollX )
- x = x - mnu.offsetWidth - this.offX;
- else x = x + this.offX;
-
- if ( y + mnu.offsetHeight + this.offY >
- viewport.height + viewport.scrollY )
- y = ( y - mnu.offsetHeight - this.offY > viewport.scrollY )?
- y - mnu.offsetHeight - this.offY :
- viewport.height + viewport.scrollY - mnu.offsetHeight;
- else y = y + this.offY;
-
- this.timer = setTimeout("$('" + menuLayers.activeMenuID + "').style.visibility = 'visible'", 200);
- mnu.style.left = x + "px"; mnu.style.top = y + "px";
- },
-
- mouseoutCheck: function(e) {
- e = e? e: window.event;
- // is element moused into contained by menu? or is it menu (ul or li or a to menu div)?
- var mnu = $(menuLayers.activeMenuID);
- var toEl = e.relatedTarget? e.relatedTarget: e.toElement;
- if ( mnu != toEl && !menuLayers.contained(toEl, mnu) ) menuLayers.hide();
- },
-
- // returns true of oNode is contained by oCont (container)
- contained: function(oNode, oCont) {
- if (!oNode) return; // in case alt-tab away while hovering (prevent error)
- while ( oNode = oNode.parentNode )
- if ( oNode == oCont ) return true;
- return false;
- },
-
- clearTimer: function() {
- if (menuLayers.timer) clearTimeout(menuLayers.timer);
- }
-}
-
commit f38951d435424a8e601ffbf7060ed01afb7b4fde
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Wed Mar 30 14:24:07 2011 -0400
normally don't need to pass in the attrib name explicitly since the name of the field is normally the same as the attrib name
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/table/TimestampCellFormatter.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/table/TimestampCellFormatter.java
index 3cf8695..f17c62f 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/table/TimestampCellFormatter.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/table/TimestampCellFormatter.java
@@ -80,6 +80,10 @@ public class TimestampCellFormatter implements CellFormatter {
return (null == dateTimeFormat) ? DATE_TIME_FORMAT_MEDIUM.format(date) : dateTimeFormat.format(date);
}
+ public static void prepareDateField(final ListGridField field) {
+ prepareDateField(field, field.getName());
+ }
+
public static void prepareDateField(final ListGridField field, final String dateTimeAttributeName) {
field.setCellFormatter(new TimestampCellFormatter());
field.setShowHover(true);
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/summary/ResourceErrorsView.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/summary/ResourceErrorsView.java
index 3980125..e4e62e8 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/summary/ResourceErrorsView.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/summary/ResourceErrorsView.java
@@ -75,11 +75,9 @@ public class ResourceErrorsView extends Table<ResourceErrorsDataSource> {
ListGridField timeField = new ListGridField(Field.TIME_OCCURED, MSG
.dataSource_resourceErrors_field_timeOccured());
timeField.setType(ListGridFieldType.DATE);
- timeField.setCellFormatter(new TimestampCellFormatter());
timeField.setAlign(Alignment.CENTER);
timeField.setWidth("20%");
- timeField.setShowHover(true);
- timeField.setHoverCustomizer(TimestampCellFormatter.getHoverCustomizer(Field.TIME_OCCURED));
+ TimestampCellFormatter.prepareDateField(timeField);
ListGridField summaryField = new ListGridField(Field.SUMMARY, MSG.dataSource_resourceErrors_field_summary());
summaryField.setAlign(Alignment.CENTER);
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/discovery/ResourceAutodiscoveryView.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/discovery/ResourceAutodiscoveryView.java
index 6955700..31732c1 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/discovery/ResourceAutodiscoveryView.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/discovery/ResourceAutodiscoveryView.java
@@ -131,7 +131,7 @@ public class ResourceAutodiscoveryView extends LocatableVLayout {
description = new TreeGridField("description");
status = new TreeGridField("statusLabel");
ctime = new TreeGridField("ctime");
- TimestampCellFormatter.prepareDateField(ctime, "ctime");
+ TimestampCellFormatter.prepareDateField(ctime);
if (!simple) {
treeGrid.setFields(name, key, type, description, status, ctime);
commit e515acc7a0c083dd3969305d095f3a5274b6c8bd
Author: Jay Shaughnessy <jshaughn(a)redhat.com>
Date: Wed Mar 30 14:17:21 2011 -0400
Protect against NPE and improve hover text.
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/AlertDataSource.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/AlertDataSource.java
index 9fde105..71a698a 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/AlertDataSource.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/AlertDataSource.java
@@ -165,11 +165,17 @@ public class AlertDataSource extends RPCDataSource<Alert, AlertCriteria> {
statusField.setHoverCustomizer(new HoverCustomizer() {
public String hoverHTML(Object value, ListGridRecord record, int rowNum, int colNum) {
String ackSubject = record.getAttribute("acknowledgingSubject");
- Date ackTime = record.getAttributeAsDate("acknowledgeTime");
- String ackTimeString = TimestampCellFormatter.format(ackTime,
- TimestampCellFormatter.DATE_TIME_FORMAT_FULL);
- StringBuilder sb = new StringBuilder("<p style='width:500px'>");
- sb.append(MSG.view_alerts_field_ack_status_ackHover(ackSubject, ackTimeString));
+ StringBuilder sb = new StringBuilder("<p");
+ if (ackSubject == null) {
+ sb.append(" style='width:150px'>");
+ sb.append(MSG.view_alerts_field_ack_status_noAckHover());
+ } else {
+ sb.append(" style='width:500px'>");
+ Date ackTime = record.getAttributeAsDate("acknowledgeTime");
+ String ackTimeString = TimestampCellFormatter.format(ackTime,
+ TimestampCellFormatter.DATE_TIME_FORMAT_FULL);
+ sb.append(MSG.view_alerts_field_ack_status_ackHover(ackSubject, ackTimeString));
+ }
sb.append("</p>");
return sb.toString();
}
diff --git a/modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages.properties b/modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages.properties
index 7bc3ea4..ae8ccbd 100644
--- a/modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages.properties
+++ b/modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages.properties
@@ -881,6 +881,7 @@ view_alerts_field_ack_time = Acknowledge Time
view_alerts_field_ack_subject = Acknowledge Subject
view_alerts_field_ack_status = Status
view_alerts_field_ack_status_noAck = No Ack
+view_alerts_field_ack_status_noAckHover = Not yet Acknowledged
view_alerts_field_ack_status_ack = Ack ({0})
view_alerts_field_ack_status_ackHover = Acknowledged by {0} at {1}
view_alerts_field_name = Name
commit 4871543e3fd99c94efcb5b27f9039e25642244c3
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Wed Mar 30 14:17:01 2011 -0400
quick fix to ctime field
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/summary/ResourceErrorsView.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/summary/ResourceErrorsView.java
index 1c75bcc..3980125 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/summary/ResourceErrorsView.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/summary/ResourceErrorsView.java
@@ -22,7 +22,6 @@ import com.google.gwt.user.client.rpc.AsyncCallback;
import com.smartgwt.client.data.Criteria;
import com.smartgwt.client.types.Alignment;
import com.smartgwt.client.types.AutoFitWidthApproach;
-import com.smartgwt.client.types.DateDisplayFormat;
import com.smartgwt.client.types.ListGridFieldType;
import com.smartgwt.client.types.Overflow;
import com.smartgwt.client.types.SelectionStyle;
@@ -42,6 +41,7 @@ import org.rhq.enterprise.gui.coregui.client.CoreGUI;
import org.rhq.enterprise.gui.coregui.client.components.table.AbstractTableAction;
import org.rhq.enterprise.gui.coregui.client.components.table.Table;
import org.rhq.enterprise.gui.coregui.client.components.table.TableActionEnablement;
+import org.rhq.enterprise.gui.coregui.client.components.table.TimestampCellFormatter;
import org.rhq.enterprise.gui.coregui.client.gwt.GWTServiceLookup;
import org.rhq.enterprise.gui.coregui.client.inventory.resource.detail.summary.ResourceErrorsDataSource.Field;
import org.rhq.enterprise.gui.coregui.client.util.message.Message;
@@ -75,9 +75,11 @@ public class ResourceErrorsView extends Table<ResourceErrorsDataSource> {
ListGridField timeField = new ListGridField(Field.TIME_OCCURED, MSG
.dataSource_resourceErrors_field_timeOccured());
timeField.setType(ListGridFieldType.DATE);
- timeField.setDateFormatter(DateDisplayFormat.TOLOCALESTRING);
+ timeField.setCellFormatter(new TimestampCellFormatter());
timeField.setAlign(Alignment.CENTER);
timeField.setWidth("20%");
+ timeField.setShowHover(true);
+ timeField.setHoverCustomizer(TimestampCellFormatter.getHoverCustomizer(Field.TIME_OCCURED));
ListGridField summaryField = new ListGridField(Field.SUMMARY, MSG.dataSource_resourceErrors_field_summary());
summaryField.setAlign(Alignment.CENTER);
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/discovery/ResourceAutodiscoveryView.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/discovery/ResourceAutodiscoveryView.java
index c2b3748..6955700 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/discovery/ResourceAutodiscoveryView.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/discovery/ResourceAutodiscoveryView.java
@@ -50,6 +50,7 @@ import com.smartgwt.client.widgets.tree.TreeNode;
import org.rhq.core.domain.resource.InventoryStatus;
import org.rhq.enterprise.gui.coregui.client.CoreGUI;
+import org.rhq.enterprise.gui.coregui.client.components.table.TimestampCellFormatter;
import org.rhq.enterprise.gui.coregui.client.gwt.GWTServiceLookup;
import org.rhq.enterprise.gui.coregui.client.gwt.ResourceGWTServiceAsync;
import org.rhq.enterprise.gui.coregui.client.util.TableUtility;
@@ -130,6 +131,7 @@ public class ResourceAutodiscoveryView extends LocatableVLayout {
description = new TreeGridField("description");
status = new TreeGridField("statusLabel");
ctime = new TreeGridField("ctime");
+ TimestampCellFormatter.prepareDateField(ctime, "ctime");
if (!simple) {
treeGrid.setFields(name, key, type, description, status, ctime);
commit e7ec5cfe2a6da8ea2a0487e256e284cb9d03b8a8
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Wed Mar 30 14:13:20 2011 -0400
add a convienence method that prepares a list grid field as a data field, complete wiht a hover and a standard time format
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/table/TimestampCellFormatter.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/table/TimestampCellFormatter.java
index d8a86c7..3cf8695 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/table/TimestampCellFormatter.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/table/TimestampCellFormatter.java
@@ -5,6 +5,7 @@ import java.util.Date;
import com.google.gwt.i18n.client.DateTimeFormat;
import com.smartgwt.client.widgets.grid.CellFormatter;
import com.smartgwt.client.widgets.grid.HoverCustomizer;
+import com.smartgwt.client.widgets.grid.ListGridField;
import com.smartgwt.client.widgets.grid.ListGridRecord;
/**
@@ -79,6 +80,12 @@ public class TimestampCellFormatter implements CellFormatter {
return (null == dateTimeFormat) ? DATE_TIME_FORMAT_MEDIUM.format(date) : dateTimeFormat.format(date);
}
+ public static void prepareDateField(final ListGridField field, final String dateTimeAttributeName) {
+ field.setCellFormatter(new TimestampCellFormatter());
+ field.setShowHover(true);
+ field.setHoverCustomizer(getHoverCustomizer(dateTimeAttributeName));
+ }
+
public static HoverCustomizer getHoverCustomizer(final String dateTimeAttributeName) {
return new HoverCustomizer() {
commit 874fd083a82b0b42a39f3d1b001fed2c55312ace
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Wed Mar 30 13:50:45 2011 -0400
fix message center time
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/message/MessageCenterView.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/message/MessageCenterView.java
index b5907fd..f692f44 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/message/MessageCenterView.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/message/MessageCenterView.java
@@ -49,6 +49,7 @@ import org.rhq.enterprise.gui.coregui.client.CoreGUI;
import org.rhq.enterprise.gui.coregui.client.components.table.AbstractTableAction;
import org.rhq.enterprise.gui.coregui.client.components.table.Table;
import org.rhq.enterprise.gui.coregui.client.components.table.TableActionEnablement;
+import org.rhq.enterprise.gui.coregui.client.components.table.TimestampCellFormatter;
import org.rhq.enterprise.gui.coregui.client.util.message.Message.Severity;
import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableDynamicForm;
import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableWindow;
@@ -182,6 +183,8 @@ public class MessageCenterView extends Table implements MessageCenter.MessageLis
timeField.setType(ListGridFieldType.TIME);
timeField.setAttribute("displayFormat", TimeFormatter.TOPADDEDTIME);
timeField.setAlign(Alignment.LEFT);
+ timeField.setShowHover(true);
+ timeField.setHoverCustomizer(TimestampCellFormatter.getHoverCustomizer(FIELD_TIME));
ListGridField messageField = new ListGridField(FIELD_CONCISEMESSAGE, MSG.common_title_message());
@@ -339,7 +342,7 @@ public class MessageCenterView extends Table implements MessageCenter.MessageLis
severity.setValue(message.severity.name());
StaticTextItem date = new StaticTextItem("time", MSG.view_messageCenter_messageTime());
- date.setValue(message.fired);
+ date.setValue(TimestampCellFormatter.format(message.fired, TimestampCellFormatter.DATE_TIME_FORMAT_FULL));
StaticTextItem detail = new StaticTextItem("detail", MSG.view_messageCenter_messageDetail());
detail.setTitleVAlign(VerticalAlignment.TOP);
commit e558e9be8dd60a5e4478dc183a8fa1ba2937a8b8
Author: Ian Springer <ian.springer(a)redhat.com>
Date: Wed Mar 30 13:54:12 2011 -0400
fix a bunch of group config editor bugs including https://bugzilla.redhat.com/show_bug.cgi?id=680229
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/configuration/ConfigurationEditor.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/configuration/ConfigurationEditor.java
index d991515..ac2d132 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/configuration/ConfigurationEditor.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/configuration/ConfigurationEditor.java
@@ -65,6 +65,8 @@ import com.smartgwt.client.widgets.form.fields.SpacerItem;
import com.smartgwt.client.widgets.form.fields.StaticTextItem;
import com.smartgwt.client.widgets.form.fields.TextAreaItem;
import com.smartgwt.client.widgets.form.fields.TextItem;
+import com.smartgwt.client.widgets.form.fields.events.BlurEvent;
+import com.smartgwt.client.widgets.form.fields.events.BlurHandler;
import com.smartgwt.client.widgets.form.fields.events.ChangeEvent;
import com.smartgwt.client.widgets.form.fields.events.ChangeHandler;
import com.smartgwt.client.widgets.form.fields.events.ChangedEvent;
@@ -713,7 +715,6 @@ public class ConfigurationEditor extends LocatableVLayout {
}
protected void firePropertyChangedEvent(Property property, PropertyDefinition propertyDefinition, boolean isValid) {
- boolean wasValidBefore = this.invalidPropertyNameToDisplayNameMap.isEmpty();
PropertyDefinition topLevelPropertyDefinition = getTopLevelPropertyDefinition(propertyDefinition);
boolean invalidPropertySetChanged;
if (isValid) {
@@ -1404,14 +1405,13 @@ public class ConfigurationEditor extends LocatableVLayout {
final PropertySimple propertySimple, final FormItem valueItem) {
FormItem item;
if (!propertyDefinitionSimple.isRequired()) {
- final CheckboxItem unsetItem = new CheckboxItem();
+ final CheckboxItem unsetItem = new CheckboxItem("unset-" + valueItem.getName());
boolean unset = isUnset(propertyDefinitionSimple, propertySimple);
unsetItem.setValue(unset);
unsetItem.setDisabled(isReadOnly(propertyDefinitionSimple, propertySimple));
unsetItem.setShowLabel(false);
unsetItem.setShowTitle(false);
unsetItem.setLabelAsTitle(false);
- unsetItem.setColSpan(1);
unsetItem.addChangeHandler(new ChangeHandler() {
public void onChange(ChangeEvent changeEvent) {
@@ -1429,6 +1429,14 @@ public class ConfigurationEditor extends LocatableVLayout {
}
});
+ valueItem.addBlurHandler(new BlurHandler() {
+ public void onBlur(BlurEvent event) {
+ boolean isUnset = (event.getItem().getValue() == null);
+ unsetItem.setValue(isUnset);
+ valueItem.disable();
+ }
+ });
+
item = unsetItem;
} else {
item = new SpacerItem();
@@ -1441,7 +1449,7 @@ public class ConfigurationEditor extends LocatableVLayout {
return (!propertyDefinition.isRequired() && (propertySimple == null || propertySimple.getStringValue() == null));
}
- private boolean isReadOnly(PropertyDefinition propertyDefinition, Property property) {
+ protected boolean isReadOnly(PropertyDefinition propertyDefinition, Property property) {
if (this.readOnly) {
return true;
}
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/configuration/GroupConfigurationEditor.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/configuration/GroupConfigurationEditor.java
index eafbd15..c7b087c 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/configuration/GroupConfigurationEditor.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/configuration/GroupConfigurationEditor.java
@@ -1,6 +1,6 @@
/*
* RHQ Management Platform
- * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * Copyright 2010-2011, Red Hat Middleware LLC, and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
@@ -65,9 +65,11 @@ import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableVLayout;
* @author Ian Springer
*/
public class GroupConfigurationEditor extends ConfigurationEditor {
+
+ private static final String RHQ_STATIC_ITEM_NAME_ATTRIBUTE = "rhq:staticItemName";
+ private static final String RHQ_UNSET_ITEM_NAME_ATTRIBUTE = "rhq:unsetItemName";
+
private List<GroupMemberConfiguration> memberConfigurations;
- private Map<String, FormItem> valueItemNameToStaticItemMap = new HashMap<String, FormItem>();
- private Map<String, FormItem> valueItemNameToUnsetItemMap = new HashMap<String, FormItem>();
public GroupConfigurationEditor(String locatorId, ConfigurationDefinition configurationDefinition,
List<GroupMemberConfiguration> memberConfigurations) {
@@ -94,7 +96,7 @@ public class GroupConfigurationEditor extends ConfigurationEditor {
if (isAggregateProperty(propertySimple)) {
// Create the "MEMBER VALUES DIFFER" label that is displayed when member values are heterogeneous.
- final StaticTextItem staticItem = new StaticTextItem();
+ final StaticTextItem staticItem = new StaticTextItem("static-" + propertySimple.getName());
staticItem.setValue(MSG.view_groupConfigEdit_valsDiff());
staticItem.setTextBoxStyle("InlineNote");
staticItem.setShowTitle(false);
@@ -106,7 +108,7 @@ public class GroupConfigurationEditor extends ConfigurationEditor {
FormItemIcon icon = buildEditMemberValuesIcon(propertyDefinitionSimple, propertySimple, valueItem);
staticItem.setIcons(icon);
- this.valueItemNameToStaticItemMap.put(valueItem.getName(), staticItem);
+ valueItem.setAttribute(RHQ_STATIC_ITEM_NAME_ATTRIBUTE, staticItem.getName());
fields.add(3, staticItem);
}
@@ -147,7 +149,7 @@ public class GroupConfigurationEditor extends ConfigurationEditor {
item.addChangedHandler(new ChangedHandler() {
public void onChanged(ChangedEvent changedEvent) {
Object value = changedEvent.getValue();
- updateMemberProperties(propertyDefinitionSimple, propertySimple, value);
+ updateMemberProperties(propertySimple, value);
}
});
@@ -159,7 +161,7 @@ public class GroupConfigurationEditor extends ConfigurationEditor {
}
private FormItemIcon buildEditMemberValuesIcon(final PropertyDefinitionSimple propertyDefinitionSimple,
- final PropertySimple propertySimple, final FormItem dynamicItem) {
+ final PropertySimple propertySimple, final FormItem dynamicItem) {
FormItemIcon icon = new FormItemIcon();
icon.setSrc(ImageManager.getEditIcon());
@@ -178,8 +180,7 @@ public class GroupConfigurationEditor extends ConfigurationEditor {
return icon;
}
- private void updateMemberProperties(PropertyDefinitionSimple propertyDefinitionSimple,
- PropertySimple propertySimple, Object value) {
+ private void updateMemberProperties(PropertySimple propertySimple, Object value) {
for (GroupMemberConfiguration memberConfiguration : this.memberConfigurations) {
Configuration configuration = memberConfiguration.getConfiguration();
PropertySimple memberPropertySimple = (PropertySimple) getProperty(configuration, propertySimple, null);
@@ -196,12 +197,13 @@ public class GroupConfigurationEditor extends ConfigurationEditor {
unsetItem.setValue(false);
unsetItem.setDisabled(true);
}
- this.valueItemNameToUnsetItemMap.put(valueItem.getName(), unsetItem);
+ valueItem.setAttribute(RHQ_UNSET_ITEM_NAME_ATTRIBUTE, unsetItem.getName());
return unsetItem;
}
private void displayMemberValuesEditor(String locatorId, final PropertyDefinitionSimple propertyDefinitionSimple,
- final PropertySimple aggregatePropertySimple, Integer index, final FormItem aggregateValueItem) {
+ final PropertySimple aggregatePropertySimple, Integer index,
+ final FormItem aggregateValueItem) {
final Window popup = new Window();
popup.setTitle(MSG.view_groupConfigEdit_valsDiffForProp(propertyDefinitionSimple.getName()));
popup.setWidth(800);
@@ -215,101 +217,11 @@ public class GroupConfigurationEditor extends ConfigurationEditor {
layout.setHeight100();
layout.setMargin(11);
- final DynamicForm setAllForm = new DynamicForm();
- setAllForm.setNumCols(4);
- setAllForm.setColWidths(175, 25, 200, 100);
- setAllForm.setCellPadding(5);
-
- List<FormItem> setAllItems = new ArrayList<FormItem>();
-
- // Header Row
- SpacerItem spacerItem = new SpacerItem();
- setAllItems.add(spacerItem);
-
- StaticTextItem unsetAllHeader = new StaticTextItem();
- unsetAllHeader.setShowTitle(false);
- if (!propertyDefinitionSimple.isRequired()) {
- unsetAllHeader.setDefaultValue("<h4>" + MSG.view_groupConfigEdit_unset() + "</h4>");
- }
- setAllItems.add(unsetAllHeader);
-
- StaticTextItem valueAllHeader = new StaticTextItem();
- valueAllHeader.setShowTitle(false);
- valueAllHeader.setDefaultValue("<h4>" + MSG.common_title_value() + "</h4>");
-
- setAllItems.add(valueAllHeader);
-
- spacerItem = new SpacerItem();
- //spacerItem.setEndRow(true);
- setAllItems.add(spacerItem);
-
- // Input Row
- StaticTextItem setAllValuesToItem = new StaticTextItem();
- setAllValuesToItem.setShowTitle(false);
- setAllValuesToItem.setDefaultValue("<b>" + MSG.view_groupConfigEdit_setAll() + "</b>");
- setAllValuesToItem.setAlign(Alignment.RIGHT);
- setAllItems.add(setAllValuesToItem);
-
- PropertySimple masterPropertySimple = new PropertySimple(propertyDefinitionSimple.getName(), null);
- final FormItem masterValueItem = super.buildSimpleField(propertyDefinitionSimple, masterPropertySimple);
- masterValueItem.setDisabled(false);
-
- FormItem masterUnsetItem = buildUnsetItem(propertyDefinitionSimple, masterPropertySimple, masterValueItem);
- if (masterUnsetItem instanceof CheckboxItem) {
- masterUnsetItem.setValue(false);
- }
-
- setAllItems.add(masterUnsetItem);
- setAllItems.add(masterValueItem);
-
- //ButtonItem applyButtonItem = new ButtonItem();
- //applyButtonItem.setTitle("Apply");
- //applyButtonItem.setEndRow(true);
- //setAllItems.add(applyButtonItem);
-
- // NOTE (ips, 10/27/10): Using a ButtonItem didn't work out, because SmartGWT would always display it in a new
- // table row, rather than in the next column in the current row (most likely a bug). So
- // we use an IButton wrapped in a CanvasItem instead.
- CanvasItem canvasItem = new CanvasItem();
- canvasItem.setShowTitle(false);
- HLayout buttonCanvas = new HLayout();
- buttonCanvas.setWidth(90);
- buttonCanvas.setHeight100();
- buttonCanvas.setAlign(Alignment.LEFT);
- final IButton applyButton = new LocatableIButton(layout.extendLocatorId("Apply"), MSG.common_button_apply());
- applyButton.setDisabled(true);
- buttonCanvas.addMember(applyButton);
- canvasItem.setCanvas(buttonCanvas);
- canvasItem.setEndRow(true);
- setAllItems.add(canvasItem);
-
- masterValueItem.addChangedHandler(new ChangedHandler() {
- public void onChanged(ChangedEvent changedEvent) {
- applyButton.enable();
- //applyButton.focus();
- }
- });
-
- masterUnsetItem.addChangedHandler(new ChangedHandler() {
- public void onChanged(ChangedEvent changedEvent) {
- applyButton.enable();
- applyButton.focus();
- }
- });
-
- setAllForm.setFields(setAllItems.toArray(new FormItem[setAllItems.size()]));
- layout.addMember(setAllForm);
-
- VLayout spacerLayout = new VLayout();
- spacerLayout.setHeight(20);
- layout.addMember(spacerLayout);
-
final DynamicForm membersForm = new DynamicForm();
membersForm.setHeight100();
membersForm.setNumCols(3);
membersForm.setColWidths("52%", "8%", "40%");
membersForm.setHiliteRequiredFields(true);
- layout.addMember(membersForm);
// Add header row.
List<FormItem> items = new ArrayList<FormItem>();
@@ -362,57 +274,72 @@ public class GroupConfigurationEditor extends ConfigurationEditor {
valueItem.setDisabled(false);
}
+ // TODO: Anchor the button bar at the bottom of the modal window, so it's always visible.
+ HLayout buttonBar = new HLayout();
+ buttonBar.setAlign(Alignment.CENTER);
+ buttonBar.setMembersMargin(7);
+
final IButton okButton = new LocatableIButton(layout.extendLocatorId("OK"), MSG.common_button_ok());
- okButton.disable();
+ final boolean propertyIsReadOnly = isReadOnly(propertyDefinitionSimple, aggregatePropertySimple);
+ if (!propertyIsReadOnly) {
+ okButton.disable();
+ }
okButton.addClickHandler(new com.smartgwt.client.widgets.events.ClickHandler() {
public void onClick(ClickEvent clickEvent) {
- boolean valuesHomogeneous = true;
- boolean isValid = true;
-
- Object firstValue = valueItems.get(0).getValue();
- for (FormItem valueItem : valueItems) {
- Object value = valueItem.getValue();
- if ((value != null && !value.equals(firstValue)) || (value == null && firstValue != null)) {
- valuesHomogeneous = false;
+ if (!propertyIsReadOnly) {
+ boolean valuesHomogeneous = true;
+ boolean isValid = true;
+
+ Object firstValue = valueItems.get(0).getValue();
+ for (FormItem valueItem : valueItems) {
+ Object value = valueItem.getValue();
+ if ((value != null && !value.equals(firstValue)) || (value == null && firstValue != null)) {
+ valuesHomogeneous = false;
+ }
+ isValid = isValid && valueItem.validate();
+ PropertySimple memberPropertySimple = valueItemNameToPropertySimpleMap.get(valueItem.getName());
+ memberPropertySimple.setValue(value);
+ memberPropertySimple.setErrorMessage(null);
}
- isValid = isValid && valueItem.validate();
- PropertySimple memberPropertySimple = valueItemNameToPropertySimpleMap.get(valueItem.getName());
- memberPropertySimple.setValue(value);
- memberPropertySimple.setErrorMessage(null);
- }
- FormItem aggregateStaticItem = valueItemNameToStaticItemMap.get(aggregateValueItem.getName());
+ String aggregateStaticItemName = aggregateValueItem.getAttribute(RHQ_STATIC_ITEM_NAME_ATTRIBUTE);
+ FormItem aggregateStaticItem = aggregateValueItem.getForm().getField(aggregateStaticItemName);
- FormItem aggregateUnsetItem = valueItemNameToUnsetItemMap.get(aggregateValueItem.getName());
- aggregateUnsetItem.setDisabled(!valuesHomogeneous);
+ String aggregateUnsetItemName = aggregateValueItem.getAttribute(RHQ_UNSET_ITEM_NAME_ATTRIBUTE);
+ FormItem aggregateUnsetItem = aggregateValueItem.getForm().getField(aggregateUnsetItemName);
+ aggregateUnsetItem.setDisabled(!valuesHomogeneous);
- if (valuesHomogeneous) {
- // Update the value of the aggregate property and set its override flag to true.
- aggregatePropertySimple.setValue(firstValue);
- aggregatePropertySimple.setOverride(true);
+ if (valuesHomogeneous) {
+ // Update the value of the aggregate property and set its override flag to true.
+ aggregatePropertySimple.setValue(firstValue);
+ aggregatePropertySimple.setOverride(true);
- aggregateUnsetItem.setValue(firstValue == null);
+ boolean isUnset = (firstValue == null);
+ aggregateUnsetItem.setValue(isUnset);
- // Set the aggregate value item's value to the homogeneous value, unhide it, and enable it.
- setValue(aggregateValueItem, firstValue);
- aggregateValueItem.show();
- aggregateValueItem.setDisabled(false);
+ // Set the aggregate value item's value to the homogeneous value, unhide it, and enable it
+ // unless it's unset.
+ setValue(aggregateValueItem, firstValue);
+ aggregateValueItem.show();
+ aggregateValueItem.setDisabled(isUnset);
- aggregateStaticItem.hide();
- } else {
- aggregatePropertySimple.setValue(null);
- aggregatePropertySimple.setOverride(false);
+ aggregateStaticItem.hide();
+ } else {
+ aggregatePropertySimple.setValue(null);
+ aggregatePropertySimple.setOverride(false);
- aggregateValueItem.hide();
+ aggregateValueItem.hide();
- aggregateStaticItem.show();
- }
+ aggregateStaticItem.show();
+ }
- firePropertyChangedEvent(aggregatePropertySimple, propertyDefinitionSimple, isValid);
+ firePropertyChangedEvent(aggregatePropertySimple, propertyDefinitionSimple, isValid);
+ }
popup.destroy();
}
});
+ buttonBar.addMember(okButton);
// Only enable the OK button if all properties are valid.
membersForm.addItemChangedHandler(new ItemChangedHandler() {
@@ -421,42 +348,130 @@ public class GroupConfigurationEditor extends ConfigurationEditor {
}
});
- applyButton.addClickHandler(new com.smartgwt.client.widgets.events.ClickHandler() {
- @Override
- public void onClick(ClickEvent clickEvent) {
- Object value = masterValueItem.getValue();
- // Update the aggregate property.
- aggregatePropertySimple.setValue(value);
-
- // Update the member properties.
- for (FormItem valueItem : valueItems) {
- setValue(valueItem, value);
-
- FormItem unsetItem = valueItemNameToUnsetItemMap.get(valueItem.getName());
- if (unsetItem instanceof CheckboxItem) {
- unsetItem.setValue((value == null));
- valueItem.setDisabled((value == null));
- }
+ if (!propertyIsReadOnly) {
+ final DynamicForm setAllForm = new DynamicForm();
+ setAllForm.setNumCols(4);
+ setAllForm.setColWidths(175, 25, 200, 100);
+ setAllForm.setCellPadding(5);
- okButton.setDisabled(!membersForm.validate());
- }
+ List<FormItem> setAllItems = new ArrayList<FormItem>();
+
+ // Header Row
+ SpacerItem spacerItem = new SpacerItem();
+ setAllItems.add(spacerItem);
+
+ StaticTextItem unsetAllHeader = new StaticTextItem();
+ unsetAllHeader.setShowTitle(false);
+ if (!propertyDefinitionSimple.isRequired()) {
+ unsetAllHeader.setDefaultValue("<h4>" + MSG.view_groupConfigEdit_unset() + "</h4>");
}
- });
+ setAllItems.add(unsetAllHeader);
- final IButton cancelButton = new LocatableIButton(layout.extendLocatorId("Cancel"), MSG.common_button_cancel());
- cancelButton.focus();
- cancelButton.addClickHandler(new com.smartgwt.client.widgets.events.ClickHandler() {
- public void onClick(ClickEvent clickEvent) {
- popup.destroy();
+ StaticTextItem valueAllHeader = new StaticTextItem();
+ valueAllHeader.setShowTitle(false);
+ valueAllHeader.setDefaultValue("<h4>" + MSG.common_title_value() + "</h4>");
+
+ setAllItems.add(valueAllHeader);
+
+ spacerItem = new SpacerItem();
+ //spacerItem.setEndRow(true);
+ setAllItems.add(spacerItem);
+
+ // Input Row
+ StaticTextItem setAllValuesToItem = new StaticTextItem();
+ setAllValuesToItem.setShowTitle(false);
+ setAllValuesToItem.setDefaultValue("<b>" + MSG.view_groupConfigEdit_setAll() + "</b>");
+ setAllValuesToItem.setAlign(Alignment.RIGHT);
+ setAllItems.add(setAllValuesToItem);
+
+ PropertySimple masterPropertySimple = new PropertySimple(propertyDefinitionSimple.getName(), null);
+ final FormItem masterValueItem = super.buildSimpleField(propertyDefinitionSimple, masterPropertySimple);
+ masterValueItem.setName("master-" + masterValueItem.getName());
+ masterValueItem.setDisabled(false);
+
+ FormItem masterUnsetItem = buildUnsetItem(propertyDefinitionSimple, masterPropertySimple, masterValueItem);
+ if (masterUnsetItem instanceof CheckboxItem) {
+ masterUnsetItem.setValue(false);
}
- });
- // TODO: Anchor the button bar at the bottom of the modal window, so it's always visible.
- HLayout buttons = new HLayout();
- buttons.setAlign(Alignment.CENTER);
- buttons.setMembersMargin(7);
- buttons.setMembers(okButton, cancelButton);
- layout.addMember(buttons);
+ setAllItems.add(masterUnsetItem);
+ setAllItems.add(masterValueItem);
+
+ //ButtonItem applyButtonItem = new ButtonItem();
+ //applyButtonItem.setTitle("Apply");
+ //applyButtonItem.setEndRow(true);
+ //setAllItems.add(applyButtonItem);
+
+ // NOTE (ips, 10/27/10): Using a ButtonItem didn't work out, because SmartGWT would always display it in a new
+ // table row, rather than in the next column in the current row (most likely a bug). So
+ // we use an IButton wrapped in a CanvasItem instead.
+ CanvasItem canvasItem = new CanvasItem();
+ canvasItem.setShowTitle(false);
+ HLayout buttonCanvas = new HLayout();
+ buttonCanvas.setWidth(90);
+ buttonCanvas.setHeight100();
+ buttonCanvas.setAlign(Alignment.LEFT);
+ final IButton applyButton = new LocatableIButton(layout.extendLocatorId("Apply"), MSG.common_button_apply());
+ applyButton.setDisabled(true);
+
+ applyButton.addClickHandler(new com.smartgwt.client.widgets.events.ClickHandler() {
+ @Override
+ public void onClick(ClickEvent clickEvent) {
+ Object value = masterValueItem.getValue();
+
+ // Update the member property value items.
+ for (FormItem valueItem : valueItems) {
+ setValue(valueItem, value);
+
+ String unsetItemName = valueItem.getAttribute(RHQ_UNSET_ITEM_NAME_ATTRIBUTE);
+ FormItem unsetItem = valueItem.getForm().getField(unsetItemName);
+ if (unsetItem instanceof CheckboxItem) {
+ unsetItem.setValue((value == null));
+ valueItem.setDisabled((value == null));
+ }
+
+ okButton.setDisabled(!membersForm.validate());
+ }
+ }
+ });
+
+ buttonCanvas.addMember(applyButton);
+ canvasItem.setCanvas(buttonCanvas);
+ canvasItem.setEndRow(true);
+ setAllItems.add(canvasItem);
+
+ masterValueItem.addChangedHandler(new ChangedHandler() {
+ public void onChanged(ChangedEvent changedEvent) {
+ applyButton.enable();
+ }
+ });
+
+ masterUnsetItem.addChangedHandler(new ChangedHandler() {
+ public void onChanged(ChangedEvent changedEvent) {
+ applyButton.enable();
+ applyButton.focus();
+ }
+ });
+
+ setAllForm.setFields(setAllItems.toArray(new FormItem[setAllItems.size()]));
+ layout.addMember(setAllForm);
+
+ VLayout spacerLayout = new VLayout();
+ spacerLayout.setHeight(20);
+ layout.addMember(spacerLayout);
+
+ final IButton cancelButton = new LocatableIButton(layout.extendLocatorId("Cancel"), MSG.common_button_cancel());
+ cancelButton.focus();
+ cancelButton.addClickHandler(new com.smartgwt.client.widgets.events.ClickHandler() {
+ public void onClick(ClickEvent clickEvent) {
+ popup.destroy();
+ }
+ });
+ buttonBar.addMember(cancelButton);
+ }
+
+ layout.addMember(membersForm);
+ layout.addMember(buttonBar);
popup.addItem(layout);
popup.show();
@@ -472,16 +487,19 @@ public class GroupConfigurationEditor extends ConfigurationEditor {
@Override
protected void updatePropertySimpleValue(Object value, PropertySimple propertySimple,
PropertyDefinitionSimple propertyDefinitionSimple) {
- // Update the aggregate property
- super.updatePropertySimpleValue(value, propertySimple, propertyDefinitionSimple);
- propertySimple.setOverride(true);
-
- // Update all the member properties.
- for (GroupMemberConfiguration memberConfiguration : this.memberConfigurations) {
- Configuration configuration = memberConfiguration.getConfiguration();
- PropertySimple memberPropertySimple = (PropertySimple) getProperty(configuration, propertySimple, null);
- memberPropertySimple.setErrorMessage(null);
- memberPropertySimple.setValue(value);
+ if ((propertySimple.getConfiguration() != null) || (propertySimple.getParentMap() != null) ||
+ (propertySimple.getParentList() != null)) {
+ // Update the aggregate property.
+ super.updatePropertySimpleValue(value, propertySimple, propertyDefinitionSimple);
+ propertySimple.setOverride(true);
+
+ // Update all the member properties.
+ for (GroupMemberConfiguration memberConfiguration : this.memberConfigurations) {
+ Configuration configuration = memberConfiguration.getConfiguration();
+ PropertySimple memberPropertySimple = (PropertySimple) getProperty(configuration, propertySimple, null);
+ memberPropertySimple.setErrorMessage(null);
+ memberPropertySimple.setValue(value);
+ }
}
}
@@ -564,4 +582,5 @@ public class GroupConfigurationEditor extends ConfigurationEditor {
Property topLevelProperty = getTopLevelProperty(property);
return topLevelProperty.getConfiguration();
}
+
}
commit eca868ae89eed3a67cc0ea5fee4a7d0974a233a3
Author: Jay Shaughnessy <jshaughn(a)redhat.com>
Date: Wed Mar 30 12:45:20 2011 -0400
AlertHistoryView fixes
- fix bad link for create time field to alert detail
- consolidate timestamp formats for the createTime and status columns,
shortening value but adding verbose hover.
- replace "Ack" with "Acknowledge" where width is not an issue.
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/AlertDataSource.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/AlertDataSource.java
index d9d1eda..9fde105 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/AlertDataSource.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/AlertDataSource.java
@@ -111,6 +111,8 @@ public class AlertDataSource extends RPCDataSource<Alert, AlertCriteria> {
ListGridField ctimeField = new ListGridField(AlertCriteria.SORT_FIELD_CTIME, MSG
.view_alerts_field_created_time());
ctimeField.setCellFormatter(new TimestampCellFormatter());
+ ctimeField.setShowHover(true);
+ ctimeField.setHoverCustomizer(TimestampCellFormatter.getHoverCustomizer(AlertCriteria.SORT_FIELD_CTIME));
fields.add(ctimeField);
ListGridField nameField = new ListGridField("name", MSG.view_alerts_field_name());
@@ -153,14 +155,25 @@ public class AlertDataSource extends RPCDataSource<Alert, AlertCriteria> {
public String format(Object o, ListGridRecord listGridRecord, int i, int i1) {
String ackSubject = listGridRecord.getAttribute("acknowledgingSubject");
if (ackSubject == null) {
- return MSG.view_alerts_field_ack_status_empty();
+ return MSG.view_alerts_field_ack_status_noAck();
} else {
- Date ackTime = listGridRecord.getAttributeAsDate("acknowledgeTime");
- String formattedTime = TimestampCellFormatter.format(ackTime);
- return MSG.view_alerts_field_ack_status_filled(ackSubject, formattedTime);
+ return MSG.view_alerts_field_ack_status_ack(ackSubject);
}
}
});
+ statusField.setShowHover(true);
+ statusField.setHoverCustomizer(new HoverCustomizer() {
+ public String hoverHTML(Object value, ListGridRecord record, int rowNum, int colNum) {
+ String ackSubject = record.getAttribute("acknowledgingSubject");
+ Date ackTime = record.getAttributeAsDate("acknowledgeTime");
+ String ackTimeString = TimestampCellFormatter.format(ackTime,
+ TimestampCellFormatter.DATE_TIME_FORMAT_FULL);
+ StringBuilder sb = new StringBuilder("<p style='width:500px'>");
+ sb.append(MSG.view_alerts_field_ack_status_ackHover(ackSubject, ackTimeString));
+ sb.append("</p>");
+ return sb.toString();
+ }
+ });
fields.add(statusField);
if (this.entityContext.type != EntityContext.Type.Resource) {
@@ -184,17 +197,17 @@ public class AlertDataSource extends RPCDataSource<Alert, AlertCriteria> {
ListGridField ancestryField = AncestryUtil.setupAncestryListGridField();
fields.add(ancestryField);
- ctimeField.setWidth(125);
- nameField.setWidth("20%");
- conditionField.setWidth("30%");
+ ctimeField.setWidth(100);
+ nameField.setWidth("15%");
+ conditionField.setWidth("35%");
priorityField.setWidth(50);
- statusField.setWidth("80");
+ statusField.setWidth(100);
resourceNameField.setWidth("25%");
ancestryField.setWidth("25%");
} else {
- ctimeField.setWidth(125);
- nameField.setWidth("35%");
- conditionField.setWidth("40%");
+ ctimeField.setWidth(200);
+ nameField.setWidth("15%");
+ conditionField.setWidth("60%");
priorityField.setWidth(50);
statusField.setWidth("25%");
}
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/AlertDetailsView.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/AlertDetailsView.java
index 49b2484..14cfc8a 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/AlertDetailsView.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/AlertDetailsView.java
@@ -161,7 +161,7 @@ public class AlertDetailsView extends LocatableVLayout implements BookmarkableVi
if (record.getAttribute("acknowledgingSubject") != null) {
ackByItem.setValue(record.getAttribute("acknowledgingSubject"));
} else {
- ackByItem.setValue(MSG.view_alerts_field_ack_status_empty());
+ ackByItem.setValue(MSG.view_alerts_field_ack_status_noAck());
}
items.add(ackByItem);
@@ -170,7 +170,7 @@ public class AlertDetailsView extends LocatableVLayout implements BookmarkableVi
if (ack_time != null) {
ackTimeItem.setValue(TimestampCellFormatter.format(ack_time));
} else {
- ackTimeItem.setValue(MSG.view_alerts_field_ack_status_empty());
+ ackTimeItem.setValue(MSG.view_alerts_field_ack_status_noAck());
}
items.add(ackTimeItem);
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/AlertHistoryView.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/AlertHistoryView.java
index f5fd917..e321819 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/AlertHistoryView.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/AlertHistoryView.java
@@ -29,6 +29,7 @@ import com.smartgwt.client.types.MultipleAppearance;
import com.smartgwt.client.types.SortDirection;
import com.smartgwt.client.widgets.Canvas;
import com.smartgwt.client.widgets.form.fields.SelectItem;
+import com.smartgwt.client.widgets.grid.CellFormatter;
import com.smartgwt.client.widgets.grid.ListGrid;
import com.smartgwt.client.widgets.grid.ListGridField;
import com.smartgwt.client.widgets.grid.ListGridRecord;
@@ -38,13 +39,17 @@ import org.rhq.core.domain.common.EntityContext;
import org.rhq.core.domain.criteria.AlertCriteria;
import org.rhq.enterprise.gui.coregui.client.CoreGUI;
import org.rhq.enterprise.gui.coregui.client.ImageManager;
+import org.rhq.enterprise.gui.coregui.client.LinkManager;
import org.rhq.enterprise.gui.coregui.client.components.table.AbstractTableAction;
import org.rhq.enterprise.gui.coregui.client.components.table.TableAction;
import org.rhq.enterprise.gui.coregui.client.components.table.TableActionEnablement;
import org.rhq.enterprise.gui.coregui.client.components.table.TableSection;
+import org.rhq.enterprise.gui.coregui.client.components.table.TimestampCellFormatter;
import org.rhq.enterprise.gui.coregui.client.components.view.ViewName;
import org.rhq.enterprise.gui.coregui.client.gwt.GWTServiceLookup;
+import org.rhq.enterprise.gui.coregui.client.inventory.resource.AncestryUtil;
import org.rhq.enterprise.gui.coregui.client.util.message.Message;
+import org.rhq.enterprise.gui.coregui.client.util.selenium.SeleniumUtility;
/**
* A view that displays a paginated table of fired {@link org.rhq.core.domain.alert.Alert alert}s, along with the
@@ -131,6 +136,19 @@ public class AlertHistoryView extends TableSection<AlertDataSource> {
return AlertCriteria.SORT_FIELD_CTIME;
}
+ @Override
+ protected CellFormatter getDetailsLinkColumnCellFormatter() {
+ return new CellFormatter() {
+ public String format(Object value, ListGridRecord record, int i, int i1) {
+ Integer resourceId = record.getAttributeAsInt(AncestryUtil.RESOURCE_ID);
+ Integer alertHistoryId = getId(record);
+ String url = LinkManager.getSubsystemAlertHistoryLink(resourceId, alertHistoryId);
+ String formattedValue = TimestampCellFormatter.format(value);
+ return SeleniumUtility.getLocatableHref(url, formattedValue, null);
+ }
+ };
+ }
+
protected void setupTableInteractions(final boolean hasWriteAccess) {
TableActionEnablement singleTargetEnablement = hasWriteAccess ? TableActionEnablement.ANY
: TableActionEnablement.NEVER;
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/table/TimestampCellFormatter.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/table/TimestampCellFormatter.java
index b08c0ee..d8a86c7 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/table/TimestampCellFormatter.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/table/TimestampCellFormatter.java
@@ -4,6 +4,7 @@ import java.util.Date;
import com.google.gwt.i18n.client.DateTimeFormat;
import com.smartgwt.client.widgets.grid.CellFormatter;
+import com.smartgwt.client.widgets.grid.HoverCustomizer;
import com.smartgwt.client.widgets.grid.ListGridRecord;
/**
@@ -12,10 +13,36 @@ import com.smartgwt.client.widgets.grid.ListGridRecord;
* @author Ian Springer
*/
public class TimestampCellFormatter implements CellFormatter {
- public static final DateTimeFormat DATE_TIME_FORMAT = DateTimeFormat.getMediumDateTimeFormat();
+
+ public static final DateTimeFormat DATE_TIME_FORMAT_FULL = DateTimeFormat.getFullDateTimeFormat();
+ public static final DateTimeFormat DATE_TIME_FORMAT_LONG = DateTimeFormat.getLongDateTimeFormat();
+ public static final DateTimeFormat DATE_TIME_FORMAT_MEDIUM = DateTimeFormat.getMediumDateTimeFormat();
+ public static final DateTimeFormat DATE_TIME_FORMAT_SHORT = DateTimeFormat.getShortDateTimeFormat();
+
+ private DateTimeFormat dateTimeFormat;
+
+ /**
+ * Uses SHORT format.
+ */
+ public TimestampCellFormatter() {
+ this(DATE_TIME_FORMAT_MEDIUM);
+ }
+
+ public TimestampCellFormatter(DateTimeFormat dateTimeFormat) {
+ super();
+ this.dateTimeFormat = dateTimeFormat;
+ }
public String format(Object value, ListGridRecord record, int rowNum, int colNum) {
- return format(value);
+ return format(value, dateTimeFormat);
+ }
+
+ /**
+ * @param value
+ * @return SHORT format for value
+ */
+ public static String format(Object value) {
+ return format(value, DATE_TIME_FORMAT_MEDIUM);
}
/**
@@ -24,10 +51,11 @@ public class TimestampCellFormatter implements CellFormatter {
* consistent across the app, whether the data is in a cell or not.
*
* @param value the date to format as a Date, Long, Integer or a String
+ * @param dateTimeFormat the format to use. If null defaults to SHORT format
*
* @return the formatted date string
*/
- public static String format(Object value) {
+ public static String format(Object value, DateTimeFormat dateTimeFormat) {
if (value == null) {
return "";
}
@@ -47,6 +75,19 @@ public class TimestampCellFormatter implements CellFormatter {
}
date = new Date(longValue);
}
- return DATE_TIME_FORMAT.format(date);
+
+ return (null == dateTimeFormat) ? DATE_TIME_FORMAT_MEDIUM.format(date) : dateTimeFormat.format(date);
+ }
+
+ public static HoverCustomizer getHoverCustomizer(final String dateTimeAttributeName) {
+ return new HoverCustomizer() {
+
+ public String hoverHTML(Object value, ListGridRecord record, int rowNum, int colNum) {
+ StringBuilder sb = new StringBuilder("<p style='width:300px'>");
+ sb.append(format(record.getAttributeAsDate(dateTimeAttributeName), DATE_TIME_FORMAT_FULL));
+ sb.append("</p>");
+ return sb.toString();
+ }
+ };
}
}
diff --git a/modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages.properties b/modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages.properties
index a965934..7bc3ea4 100644
--- a/modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages.properties
+++ b/modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages.properties
@@ -13,8 +13,8 @@ common_buildInfo_gwtVersion = ${gwt.version}
# Button Labels
#--------------
-common_button_ack = Ack
-common_button_ack_all = Ack All
+common_button_ack = Acknowlege
+common_button_ack_all = Acknowledge All
common_button_add = Add
common_button_advanced = Advanced...
common_button_apply = Apply
@@ -877,11 +877,12 @@ view_alerts_table_filter_priority = Priority Filter
view_alerts_field_created_time = Creation Time
view_alerts_field_modified_time = Modified Time
view_alerts_field_enabled = Enabled
-view_alerts_field_ack_time = Ack Time
-view_alerts_field_ack_subject = Ack Subject
+view_alerts_field_ack_time = Acknowledge Time
+view_alerts_field_ack_subject = Acknowledge Subject
view_alerts_field_ack_status = Status
-view_alerts_field_ack_status_empty = Not Acknowledged
-view_alerts_field_ack_status_filled = {0} acknowledged on {1}
+view_alerts_field_ack_status_noAck = No Ack
+view_alerts_field_ack_status_ack = Ack ({0})
+view_alerts_field_ack_status_ackHover = Acknowledged by {0} at {1}
view_alerts_field_name = Name
view_alerts_field_condition_text = Condition Text
view_alerts_field_condition_text_none = No Conditions
@@ -897,8 +898,8 @@ view_alerts_delete_confirm_all = Delete all alerts from this source?
view_alerts_delete_success = Successfully deleted {0} alerts
view_alerts_delete_failure = Failed to delete alerts with id''s: {0}
view_alerts_delete_failure_all = Failed to delete all alerts from this source
-view_alerts_ack_confirm = Ack the selected alert(s)?
-view_alerts_ack_confirm_all = Ack all alerts from this source?
+view_alerts_ack_confirm = Acknowledge the selected alert(s)?
+view_alerts_ack_confirm_all = Acknowledge all alerts from this source?
view_alerts_ack_success = Successfully acknowledged {0} alerts
view_alerts_ack_failure = Failed to acknowledge alerts with id''s: {0}
view_alerts_ack_failure_all = Failed to acknowledge all alerts from this source
commit fe0030c1b3965b1a45e6374e40de3e243ea9af74
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Wed Mar 30 09:55:29 2011 -0400
fix selenium locator conflicts
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/report/tag/TaggedView.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/report/tag/TaggedView.java
index 36e2ff8..c84223e 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/report/tag/TaggedView.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/report/tag/TaggedView.java
@@ -113,14 +113,15 @@ public class TaggedView extends LocatableVLayout implements BookmarkableView {
Tab tab;
- BundlesListView bundlesView = new BundlesListView(getLocatorId(), criteria, null);
+ BundlesListView bundlesView = new BundlesListView(extendLocatorId("bundleListView"), criteria, null);
viewsWithTags.add(bundlesView);
tab = new LocatableTab(extendLocatorId("bundleList"), MSG.view_bundle_bundles());
tab.setIcon(ImageManager.getBundleIcon());
tab.setPane(bundlesView);
container.addTab(tab);
- BundleVersionListView bundleVersionListView = new BundleVersionListView(getLocatorId(), criteria);
+ BundleVersionListView bundleVersionListView = new BundleVersionListView(
+ extendLocatorId("bundleVersionListView"), criteria);
viewsWithTags.add(bundleVersionListView);
tab = new LocatableTab(extendLocatorId("bundleVersionList"), MSG.view_bundle_bundleVersions());
tab.setIcon("subsystems/bundle/BundleVersion_16.png");
@@ -128,23 +129,23 @@ public class TaggedView extends LocatableVLayout implements BookmarkableView {
container.addTab(tab);
// TODO: get manage_bundle perm, if user has it pass true
- BundleDeploymentListView bundleDeploymentListView = new BundleDeploymentListView(getLocatorId(), criteria,
- false);
+ BundleDeploymentListView bundleDeploymentListView = new BundleDeploymentListView(
+ extendLocatorId("bundleDeploymentListView"), criteria, false);
viewsWithTags.add(bundleDeploymentListView);
tab = new LocatableTab(extendLocatorId("bundleDeploymentsList"), MSG.view_bundle_bundleDeployments());
tab.setIcon("subsystems/bundle/BundleDeployment_16.png");
tab.setPane(bundleDeploymentListView);
container.addTab(tab);
- BundleDestinationListView bundleDestinationListView = new BundleDestinationListView(getLocatorId(),
- criteria);
+ BundleDestinationListView bundleDestinationListView = new BundleDestinationListView(
+ extendLocatorId("bundleDestinationListView"), criteria);
viewsWithTags.add(bundleDestinationListView);
tab = new LocatableTab(extendLocatorId("bundleDestinationsList"), MSG.view_bundle_bundleDestinations());
tab.setIcon("subsystems/bundle/BundleDestination_16.png");
tab.setPane(bundleDestinationListView);
container.addTab(tab);
- ResourceSearchView resourceView = new ResourceSearchView(getLocatorId(), criteria, MSG
+ ResourceSearchView resourceView = new ResourceSearchView(extendLocatorId("resourceView"), criteria, MSG
.view_taggedResources_title());
viewsWithTags.add(resourceView);
tab = new LocatableTab(extendLocatorId("resourceList"), MSG.view_taggedResources_title());
commit ccbc787a51ecd53ab364e43046b8b4f49147c81d
Author: Jay Shaughnessy <jshaughn(a)redhat.com>
Date: Wed Mar 30 09:27:30 2011 -0400
Fix several issues in Alerts Portlets
- refactor to share a common abstract base class to simplify the
concrete classes and conslidate fixes.
- Fixed issue causing retrieval of all alerts
- Fixed issue with ordering of alerts
- Fixed issues with button enablement (affected resource alert history view as well)
- Removed some obsolete classes
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/AlertDataSource.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/AlertDataSource.java
index 3e51b24..d9d1eda 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/AlertDataSource.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/AlertDataSource.java
@@ -225,56 +225,61 @@ public class AlertDataSource extends RPCDataSource<Alert, AlertCriteria> {
long fetchTime = System.currentTimeMillis() - start;
Log.info(result.size() + " alerts fetched in: " + fetchTime + "ms");
- if (entityContext.type != EntityContext.Type.Resource) {
- dataRetrieved(result, response, request);
- } else {
- response.setData(buildRecords(result));
- response.setTotalRows(result.getTotalSize()); // for paging to work we have to specify size of full result set
- processResponse(request.getRequestId(), response);
- }
+ dataRetrieved(result, response, request);
+ processResponse(request.getRequestId(), response);
}
});
}
/**
- * Additional processing to support a cross-resource view)
- * @param result
- * @param response
- * @param request
+ * Additional processing to support entity-specific or cross-resource views, and something that can be overidden.
*/
protected void dataRetrieved(final PageList<Alert> result, final DSResponse response, final DSRequest request) {
- HashSet<Integer> typesSet = new HashSet<Integer>();
- HashSet<String> ancestries = new HashSet<String>();
- for (Alert alert : result) {
- Resource resource = alert.getAlertDefinition().getResource();
- typesSet.add(resource.getResourceType().getId());
- ancestries.add(resource.getAncestry());
- }
-
- // In addition to the types of the result resources, get the types of their ancestry
- typesSet.addAll(AncestryUtil.getAncestryTypeIds(ancestries));
+ switch (entityContext.type) {
+
+ // no need to disambiguate, the alerts are for a singe resource
+ case Resource:
+ response.setData(buildRecords(result));
+ // for paging to work we have to specify size of full result set
+ response.setTotalRows(result.getTotalSize());
+ break;
+
+ // disambiguate as the results could be cross-resource
+ default:
+ HashSet<Integer> typesSet = new HashSet<Integer>();
+ HashSet<String> ancestries = new HashSet<String>();
+ for (Alert alert : result) {
+ Resource resource = alert.getAlertDefinition().getResource();
+ typesSet.add(resource.getResourceType().getId());
+ ancestries.add(resource.getAncestry());
+ }
- ResourceTypeRepository typeRepo = ResourceTypeRepository.Cache.getInstance();
- typeRepo.getResourceTypes(typesSet.toArray(new Integer[typesSet.size()]), new TypesLoadedCallback() {
- @Override
- public void onTypesLoaded(Map<Integer, ResourceType> types) {
- // Smartgwt has issues storing a Map as a ListGridRecord attribute. Wrap it in a pojo.
- AncestryUtil.MapWrapper typesWrapper = new AncestryUtil.MapWrapper(types);
-
- Record[] records = buildRecords(result);
- for (Record record : records) {
- // To avoid a lot of unnecessary String construction, be lazy about building ancestry hover text.
- // Store the types map off the records so we can build a detailed hover string as needed.
- record.setAttribute(AncestryUtil.RESOURCE_ANCESTRY_TYPES, typesWrapper);
-
- // Build the decoded ancestry Strings now for display
- record.setAttribute(AncestryUtil.RESOURCE_ANCESTRY_VALUE, AncestryUtil.getAncestryValue(record));
+ // In addition to the types of the result resources, get the types of their ancestry
+ typesSet.addAll(AncestryUtil.getAncestryTypeIds(ancestries));
+
+ ResourceTypeRepository typeRepo = ResourceTypeRepository.Cache.getInstance();
+ typeRepo.getResourceTypes(typesSet.toArray(new Integer[typesSet.size()]), new TypesLoadedCallback() {
+ @Override
+ public void onTypesLoaded(Map<Integer, ResourceType> types) {
+ // Smartgwt has issues storing a Map as a ListGridRecord attribute. Wrap it in a pojo.
+ AncestryUtil.MapWrapper typesWrapper = new AncestryUtil.MapWrapper(types);
+
+ Record[] records = buildRecords(result);
+ for (Record record : records) {
+ // To avoid a lot of unnecessary String construction, be lazy about building ancestry hover text.
+ // Store the types map off the records so we can build a detailed hover string as needed.
+ record.setAttribute(AncestryUtil.RESOURCE_ANCESTRY_TYPES, typesWrapper);
+
+ // Build the decoded ancestry Strings now for display
+ record
+ .setAttribute(AncestryUtil.RESOURCE_ANCESTRY_VALUE, AncestryUtil.getAncestryValue(record));
+ }
+ response.setData(records);
+ // for paging to work we have to specify size of full result set
+ response.setTotalRows(result.getTotalSize());
}
- response.setData(records);
- response.setTotalRows(result.getTotalSize()); // for paging to work we have to specify size of full result set
- processResponse(request.getRequestId(), response);
- }
- });
+ });
+ }
}
@Override
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/AlertHistoryView.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/AlertHistoryView.java
index 98e4b34..f5fd917 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/AlertHistoryView.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/AlertHistoryView.java
@@ -67,18 +67,31 @@ public class AlertHistoryView extends TableSection<AlertDataSource> {
SortDirection.DESCENDING);
EntityContext context;
boolean hasWriteAccess;
+ AlertDataSource dataSource;
// for subsystem views
public AlertHistoryView(String locatorId) {
this(locatorId, SUBSYSTEM_VIEW_ID.getTitle(), EntityContext.forSubsystemView(), false);
}
+ public AlertHistoryView(String locatorId, EntityContext entityContext) {
+ this(locatorId, SUBSYSTEM_VIEW_ID.getTitle(), entityContext, false);
+ }
+
protected AlertHistoryView(String locatorId, String tableTitle, EntityContext context, boolean hasWriteAccess) {
super(locatorId, tableTitle, new SortSpecifier[] { DEFAULT_SORT_SPECIFIER });
this.context = context;
this.hasWriteAccess = hasWriteAccess;
- setDataSource(new AlertDataSource(context));
+ setDataSource(getDataSource());
+ }
+
+ @Override
+ public AlertDataSource getDataSource() {
+ if (null == this.dataSource) {
+ this.dataSource = new AlertDataSource(context);
+ }
+ return this.dataSource;
}
@Override
@@ -128,28 +141,28 @@ public class AlertHistoryView extends TableSection<AlertDataSource> {
delete(selection);
}
});
+ addTableAction("AcknowledgeAlert", MSG.common_button_ack(), MSG.view_alerts_ack_confirm(),
+ new AbstractTableAction(singleTargetEnablement) {
+ public void executeAction(ListGridRecord[] selection, Object actionValue) {
+ acknowledge(selection);
+ }
+ });
addTableAction("DeleteAll", MSG.common_button_delete_all(), MSG.view_alerts_delete_confirm_all(),
new TableAction() {
public boolean isEnabled(ListGridRecord[] selection) {
ListGrid grid = getListGrid();
- return (hasWriteAccess && grid != null && (getListGrid().getRecords().length >= 1));
+ return (hasWriteAccess && grid != null && !grid.getResultSet().isEmpty());
}
public void executeAction(ListGridRecord[] selection, Object actionValue) {
deleteAll();
}
});
- addTableAction("AcknowledgeAlert", MSG.common_button_ack(), MSG.view_alerts_ack_confirm(),
- new AbstractTableAction(singleTargetEnablement) {
- public void executeAction(ListGridRecord[] selection, Object actionValue) {
- acknowledge(selection);
- }
- });
addTableAction("AcknowledgeAll", MSG.common_button_ack_all(), MSG.view_alerts_ack_confirm_all(),
new TableAction() {
public boolean isEnabled(ListGridRecord[] selection) {
ListGrid grid = getListGrid();
- return (hasWriteAccess && grid != null && (grid.getRecords().length >= 1));
+ return (hasWriteAccess && grid != null && !grid.getResultSet().isEmpty());
}
public void executeAction(ListGridRecord[] selection, Object actionValue) {
@@ -234,4 +247,7 @@ public class AlertHistoryView extends TableSection<AlertDataSource> {
return AlertDetailsView.getInstance();
}
+ public EntityContext getContext() {
+ return context;
+ }
}
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/AlertPortletConfigurationDataSource.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/AlertPortletConfigurationDataSource.java
index 2cb7f74..db1e4ef 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/AlertPortletConfigurationDataSource.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/AlertPortletConfigurationDataSource.java
@@ -41,7 +41,6 @@ import org.rhq.core.domain.util.PageOrdering;
import org.rhq.enterprise.gui.coregui.client.CoreGUI;
import org.rhq.enterprise.gui.coregui.client.dashboard.portlets.PortletConfigurationEditorComponent;
import org.rhq.enterprise.gui.coregui.client.dashboard.portlets.PortletConfigurationEditorComponent.Constant;
-import org.rhq.enterprise.gui.coregui.client.dashboard.portlets.recent.alerts.RecentAlertsPortlet;
import org.rhq.enterprise.gui.coregui.client.util.MeasurementUtility;
/** Customize the AlertDataSource to pull fetch criteria information from
@@ -221,8 +220,7 @@ public class AlertPortletConfigurationDataSource extends AlertDataSource {
}
public Integer[] extractFilterResourceIds(DashboardPortlet storedPortlet, Integer[] filterResourceIds) {
- PropertyList propertyList = storedPortlet.getConfiguration().getList(
- RecentAlertsPortlet.ALERT_RANGE_RESOURCE_IDS);
+ PropertyList propertyList = storedPortlet.getConfiguration().getList("alert-range-resource-ids");
if ((propertyList != null) && (propertyList.getList() != null) && (!propertyList.getList().isEmpty())
&& (propertyList.getList().get(0) != null)) {
Property container = propertyList.getList().get(0);
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/AlertPortletDataSource.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/AlertPortletDataSource.java
deleted file mode 100644
index a2d0aba..0000000
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/AlertPortletDataSource.java
+++ /dev/null
@@ -1,168 +0,0 @@
-package org.rhq.enterprise.gui.coregui.client.alert;
-
-import com.google.gwt.user.client.rpc.AsyncCallback;
-import com.smartgwt.client.data.DSRequest;
-import com.smartgwt.client.data.DSResponse;
-import com.smartgwt.client.rpc.RPCResponse;
-
-import org.rhq.core.domain.alert.Alert;
-import org.rhq.core.domain.alert.AlertPriority;
-import org.rhq.core.domain.configuration.Property;
-import org.rhq.core.domain.configuration.PropertyList;
-import org.rhq.core.domain.configuration.PropertySimple;
-import org.rhq.core.domain.criteria.AlertCriteria;
-import org.rhq.core.domain.dashboard.DashboardPortlet;
-import org.rhq.core.domain.util.PageControl;
-import org.rhq.core.domain.util.PageList;
-import org.rhq.enterprise.gui.coregui.client.CoreGUI;
-import org.rhq.enterprise.gui.coregui.client.dashboard.portlets.recent.alerts.RecentAlertsPortlet;
-
-public class AlertPortletDataSource extends AlertDataSource {
- //configuration attributes
- private int alertRangeCompleted = -1;
- private int alertPriorityIndex = -1;
- private long alertTimeRange = -1;
- private String alertResourcesToUse = "all";
- private Integer[] alertFilterResourceIds = {};
- private DashboardPortlet portlet = null;
-
- public AlertPortletDataSource() {
- super();
- }
-
- public AlertPortletDataSource(DashboardPortlet recentAlertsPortlet) {
- super();
- this.portlet = recentAlertsPortlet;
- }
-
- @Override
- protected AlertCriteria getFetchCriteria(DSRequest request) {
- //retrieve previous settings from portlet config
- if ((portlet != null) && (this.portlet instanceof DashboardPortlet)) {
- //must check for whether portlet config
- PropertySimple property = portlet.getConfiguration().getSimple(
- RecentAlertsPortlet.ALERT_RANGE_RESOURCES_VALUE);
- if ((property != null) && (property.getStringValue() != null)) {
- //retrieve and translate to int
- String retrieved = property.getStringValue();
- if (retrieved.trim().equalsIgnoreCase(RecentAlertsPortlet.RESOURCES_SELECTED)) {
- setAlertResourcesToUse(RecentAlertsPortlet.RESOURCES_SELECTED);
- } else {
- setAlertResourcesToUse(RecentAlertsPortlet.RESOURCES_ALL);
- }
- //if 'selected' then check for previously set resource ids to filter on
- if (getAlertResourcesToUse().equals(RecentAlertsPortlet.RESOURCES_SELECTED)) {
- Integer[] alertResourceFilterIds = null;
- alertResourceFilterIds = extractFilterResourceIds(portlet, alertResourceFilterIds);
- if (alertFilterResourceIds != null) {
- setAlertFilterResourceId(alertFilterResourceIds);
- }
- }
- } else {//create setting
- portlet.getConfiguration().put(
- new PropertySimple(RecentAlertsPortlet.ALERT_RANGE_RESOURCES_VALUE,
- RecentAlertsPortlet.defaultResourceValue));
- setAlertResourcesToUse(RecentAlertsPortlet.RESOURCES_ALL);
- }
- }
-
- AlertCriteria criteria = new AlertCriteria();
- criteria.fetchAlertDefinition(true);
- criteria.fetchRecoveryAlertDefinition(true);
- // TODO: Uncomment the below once the bad performance of it has been fixed.
- //criteria.fetchConditionLogs(true);
- PageControl pc = new PageControl(0, getAlertRangeCompleted());
- criteria.setPageControl(pc);//display per page
- criteria.addFilterStartTime(getAlertTimeRange());//alert age
- if ((getAlertResourcesToUse().equalsIgnoreCase(RecentAlertsPortlet.RESOURCES_SELECTED))
- && (getAlertFilterResourceIds().length > 0)) {
- //add resource ids to filter on
- criteria.addFilterResourceIds(getAlertFilterResourceIds());
- }
- if (getAlertPriorityIndex() > 0) {//add priority selection
- criteria.addFilterPriorities(AlertPriority.getByLegacyIndex(getAlertPriorityIndex()));
- }
-
- return criteria;
- }
-
- /** Override the executeFetch for AlertPortlet to allow specifying smaller than total
- * result displays.
- */
- @Override
- protected void executeFetch(final DSRequest request, final DSResponse response, final AlertCriteria criteria) {
- getAlertService().findAlertsByCriteria(criteria, new AsyncCallback<PageList<Alert>>() {
-
- public void onFailure(Throwable caught) {
- CoreGUI.getErrorHandler().handleError(MSG.view_alerts_loadFailed(), caught);
- response.setStatus(RPCResponse.STATUS_FAILURE);
- processResponse(request.getRequestId(), response);
- }
-
- public void onSuccess(PageList<Alert> result) {
- dataRetrieved(result, response, request);
- }
- });
- }
-
- public int getAlertRangeCompleted() {
- return alertRangeCompleted;
- }
-
- public void setAlertRangeCompleted(int alertRangeCompleted) {
- this.alertRangeCompleted = alertRangeCompleted;
- }
-
- public int getAlertPriorityIndex() {
- return alertPriorityIndex;
- }
-
- public void setAlertPriorityIndex(int alertPriorityIndex) {
- this.alertPriorityIndex = alertPriorityIndex;
- }
-
- public long getAlertTimeRange() {
- return alertTimeRange;
- }
-
- public void setAlertTimeRange(long alertTimeRange) {
- this.alertTimeRange = alertTimeRange;
- }
-
- public String getAlertResourcesToUse() {
- return alertResourcesToUse;
- }
-
- public void setAlertResourcesToUse(String resourcesToUse) {
- this.alertResourcesToUse = resourcesToUse;
- }
-
- public Integer[] getAlertFilterResourceIds() {
- return alertFilterResourceIds;
- }
-
- public void setAlertFilterResourceId(Integer[] alertFilterResourceId) {
- this.alertFilterResourceIds = alertFilterResourceId;
- }
-
- public Integer[] extractFilterResourceIds(DashboardPortlet storedPortlet, Integer[] filterResourceIds) {
- PropertyList propertyList = storedPortlet.getConfiguration().getList(
- RecentAlertsPortlet.ALERT_RANGE_RESOURCE_IDS);
- if ((propertyList != null) && (propertyList.getList() != null) && (!propertyList.getList().isEmpty())
- && (propertyList.getList().get(0) != null)) {
- Property container = propertyList.getList().get(0);
- if (container instanceof PropertyList) {
- PropertyList anotherList = (PropertyList) container;
- if (anotherList.getList() != null) {
- filterResourceIds = new Integer[anotherList.getList().size()];
- int index = 0;
- for (Property p : anotherList.getList()) {
- filterResourceIds[index++] = ((PropertySimple) p).getIntegerValue();
- }
- }
- }
- }
- return filterResourceIds;
- }
-
-}
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/DashboardView.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/DashboardView.java
index 4c19ac1..ba91415 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/DashboardView.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/DashboardView.java
@@ -889,4 +889,13 @@ public class DashboardView extends LocatableVLayout {
public Dashboard getStoredDashboard() {
return storedDashboard;
}
+
+ public ResourceGroupComposite getGroupComposite() {
+ return groupComposite;
+ }
+
+ public ResourceComposite getResourceComposite() {
+ return resourceComposite;
+ }
+
}
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/PortletWindow.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/PortletWindow.java
index 75710a8..e8d51d1 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/PortletWindow.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/PortletWindow.java
@@ -41,6 +41,7 @@ import com.smartgwt.client.widgets.events.MouseOverHandler;
import org.rhq.core.domain.authz.Permission;
import org.rhq.core.domain.dashboard.DashboardPortlet;
+import org.rhq.core.domain.resource.composite.ResourcePermission;
import org.rhq.enterprise.gui.coregui.client.components.table.Table;
import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableHeaderControl;
import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableWindow;
@@ -246,4 +247,17 @@ public class PortletWindow extends LocatableWindow {
return dashboardView.getGlobalPermissions();
}
+ public ResourcePermission getResourcePermissions() {
+
+ ResourcePermission result = null;
+
+ if (null != dashboardView.getResourceComposite()) {
+ result = dashboardView.getResourceComposite().getResourcePermission();
+ } else if (null != dashboardView.getGroupComposite()) {
+ result = dashboardView.getGroupComposite().getResourcePermission();
+ }
+
+ return result;
+ }
+
}
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/groups/GroupAlertsPortlet.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/groups/GroupAlertsPortlet.java
index 6ac9afe..337989b 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/groups/GroupAlertsPortlet.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/groups/GroupAlertsPortlet.java
@@ -18,363 +18,63 @@
*/
package org.rhq.enterprise.gui.coregui.client.dashboard.portlets.groups;
-import java.util.HashMap;
-import java.util.Set;
-
import com.google.gwt.user.client.History;
-import com.google.gwt.user.client.Timer;
-import com.smartgwt.client.types.Overflow;
-import com.smartgwt.client.widgets.Canvas;
-import com.smartgwt.client.widgets.HTMLFlow;
-import com.smartgwt.client.widgets.events.DoubleClickEvent;
-import com.smartgwt.client.widgets.events.DoubleClickHandler;
-import com.smartgwt.client.widgets.form.DynamicForm;
-import com.smartgwt.client.widgets.form.events.SubmitValuesEvent;
-import com.smartgwt.client.widgets.form.events.SubmitValuesHandler;
-import com.smartgwt.client.widgets.form.fields.SelectItem;
-import com.smartgwt.client.widgets.grid.CellFormatter;
-import com.smartgwt.client.widgets.grid.ListGrid;
-import com.smartgwt.client.widgets.grid.ListGridRecord;
-import org.rhq.core.domain.authz.Permission;
-import org.rhq.core.domain.configuration.Configuration;
-import org.rhq.core.domain.configuration.PropertySimple;
-import org.rhq.core.domain.dashboard.DashboardPortlet;
-import org.rhq.core.domain.resource.ResourceType;
-import org.rhq.enterprise.gui.coregui.client.CoreGUI;
-import org.rhq.enterprise.gui.coregui.client.LinkManager;
-import org.rhq.enterprise.gui.coregui.client.alert.AlertHistoryView;
-import org.rhq.enterprise.gui.coregui.client.alert.AlertPortletConfigurationDataSource;
-import org.rhq.enterprise.gui.coregui.client.components.measurement.CustomConfigMeasurementRangeEditor;
-import org.rhq.enterprise.gui.coregui.client.dashboard.AutoRefreshPortlet;
-import org.rhq.enterprise.gui.coregui.client.dashboard.AutoRefreshPortletUtil;
-import org.rhq.enterprise.gui.coregui.client.dashboard.CustomSettingsPortlet;
+import org.rhq.core.domain.common.EntityContext;
import org.rhq.enterprise.gui.coregui.client.dashboard.Portlet;
import org.rhq.enterprise.gui.coregui.client.dashboard.PortletViewFactory;
-import org.rhq.enterprise.gui.coregui.client.dashboard.PortletWindow;
-import org.rhq.enterprise.gui.coregui.client.dashboard.portlets.PortletConfigurationEditorComponent;
-import org.rhq.enterprise.gui.coregui.client.dashboard.portlets.recent.alerts.PortletAlertSelector;
-import org.rhq.enterprise.gui.coregui.client.inventory.common.detail.summary.AbstractActivityView;
-import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableDynamicForm;
-import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableVLayout;
-import org.rhq.enterprise.gui.coregui.client.util.selenium.SeleniumUtility;
+import org.rhq.enterprise.gui.coregui.client.dashboard.portlets.recent.alerts.AbstractRecentAlertsPortlet;
/**
+ * @author Jay Shaughnessy
* @author Simeon Pinder
*/
-public class GroupAlertsPortlet extends AlertHistoryView implements CustomSettingsPortlet, AutoRefreshPortlet {
+public class GroupAlertsPortlet extends AbstractRecentAlertsPortlet {
// A non-displayed, persisted identifier for the portlet
public static final String KEY = "GroupAlerts";
// A default displayed, persisted name for the portlet
public static final String NAME = MSG.view_portlet_defaultName_group_alerts();
- public static final String ALERT_RANGE_RESOURCES_VALUE = "alert-range-resource-value";
- public static final String ALERT_RANGE_RESOURCE_IDS = "alert-range-resource-ids";
- public static final String RESOURCES_ALL = MSG.common_label_all_resources();
- public static final String RESOURCES_SELECTED = MSG.common_label_selected_resources();
- public static final String defaultResourceValue = RESOURCES_ALL;
- public static final String ID = "id";
- private boolean currentlyRefreshing = false;
-
- // set on initial configuration, the window for this portlet view.
- protected PortletWindow portletWindow;
-
- //shared private UI elements
- protected AlertResourceSelectorRegion resourceSelector;
-
- protected AlertPortletConfigurationDataSource dataSource;
- //instance ui widgets
- protected Canvas containerCanvas;
-
- protected Timer refreshTimer;
- protected DashboardPortlet storedPortlet;
- protected Configuration portletConfig;
private int groupId;
- protected boolean portletConfigInitialized = false;
- protected static HashMap<String, String> updatedMapping = new HashMap<String, String>();
- static {
- updatedMapping.putAll(PortletConfigurationEditorComponent.CONFIG_PROPERTY_INITIALIZATION);
- //Key, default
- updatedMapping.put(ALERT_RANGE_RESOURCES_VALUE, RESOURCES_ALL);
- updatedMapping.put(ALERT_RANGE_RESOURCE_IDS, RESOURCES_ALL);
- }
+ public GroupAlertsPortlet(String locatorId, int groupId) {
- public GroupAlertsPortlet(String locatorId) {
- super(locatorId);
+ // Since the group id is only used for filtering I don't think it matters whether this is a
+ // standard group, autogroup, or autocluster, but if so, we'll have to provide more specific
+ // contexts and more specific context handling.
+ super(locatorId, EntityContext.forGroup(groupId));
- //override the shared datasource
- //figure out which page we're loading
- String currentPage = History.getToken();
- //get groupId
- int groupId = AbstractActivityView.groupIdLookup(currentPage);
this.groupId = groupId;
-
- setShowFilterForm(false); //disable filter form for portlet
- setOverflow(Overflow.VISIBLE);
- }
-
- /**Defines layout for the portlet page.
- */
- protected void initializeUi() {
- //initalize the datasource
- this.dataSource = new AlertPortletConfigurationDataSource(storedPortlet, portletConfig, this.groupId, null);
- setDataSource(this.dataSource);
-
- setShowHeader(false);
- setShowFooter(true);
- setShowFooterRefresh(false); //disable footer refresh
-
- getListGrid().setEmptyMessage(MSG.view_portlet_results_empty());
- }
-
- /** Responsible for initialization and lazy configuration of the portlet values
- */
- public void configure(PortletWindow portletWindow, DashboardPortlet storedPortlet) {
- //populate portlet configuration details
- if (null == this.portletWindow && null != portletWindow) {
- this.portletWindow = portletWindow;
- }
-
- if ((null == storedPortlet) || (null == storedPortlet.getConfiguration())) {
- return;
- }
- this.storedPortlet = storedPortlet;
- portletConfig = storedPortlet.getConfiguration();
-
- if (!portletConfigInitialized) {
- this.dataSource = new AlertPortletConfigurationDataSource(storedPortlet, portletConfig, this.groupId, null);
- setDataSource(this.dataSource);
- portletConfigInitialized = true;
- }
-
- //lazy init any elements not yet configured.
- for (String key : PortletConfigurationEditorComponent.CONFIG_PROPERTY_INITIALIZATION.keySet()) {
- if (portletConfig.getSimple(key) == null) {
- portletConfig.put(new PropertySimple(key,
- PortletConfigurationEditorComponent.CONFIG_PROPERTY_INITIALIZATION.get(key)));
- }
- }
-
- //resource ids to be conditionally included in the query
- Integer[] filterResourceIds = null;
- filterResourceIds = getDataSource().extractFilterResourceIds(storedPortlet, filterResourceIds);
- //no defaults
-
- if (filterResourceIds != null) {
- getDataSource().setAlertFilterResourceId(filterResourceIds);
- }
-
- //conditionally display the selected resources ui
- if (containerCanvas != null) {
- //empty out earlier canvas
- for (Canvas c : containerCanvas.getChildren()) {
- c.destroy();
- }
- if ((resourceSelector != null) && getDataSource().getAlertResourcesToUse().equals(RESOURCES_SELECTED)) {
- containerCanvas.addChild(resourceSelector.getCanvas());
- } else {
- containerCanvas.addChild(new Canvas());
- }
- }
-
- }
-
- public Canvas getHelpCanvas() {
- return new HTMLFlow(MSG.view_portlet_help_recentAlerts());
- }
-
- @Override
- public DynamicForm getCustomSettingsForm() {
- LocatableDynamicForm customSettings = new LocatableDynamicForm(extendLocatorId("customSettings"));
- LocatableVLayout page = new LocatableVLayout(customSettings.extendLocatorId("page"));
- //build editor form container
- final LocatableDynamicForm form = new LocatableDynamicForm(page.extendLocatorId("alert-filter"));
- form.setMargin(5);
-
- //add label about what configuration affects
-
- //add alert priority selector
- final SelectItem alertPrioritySelector = PortletConfigurationEditorComponent
- .getAlertPriorityEditor(portletConfig);
- //add sort priority selector
- // final SelectItem resultSortSelector = PortletConfigurationEditorComponent
- // .getResulSortOrderEditor(portletConfig);
- //add result count selector
- final SelectItem resultCountSelector = PortletConfigurationEditorComponent.getResultCountEditor(portletConfig);
-
- //add range selector
- final CustomConfigMeasurementRangeEditor measurementRangeEditor = PortletConfigurationEditorComponent
- .getMeasurementRangeEditor(portletConfig);
-
- form.setItems(alertPrioritySelector, resultCountSelector);
-
- //submit handler
- customSettings.addSubmitValuesHandler(new SubmitValuesHandler() {
-
- @Override
- public void onSubmitValues(SubmitValuesEvent event) {
- //alert severity
- portletConfig = AbstractActivityView.saveAlertPrioritySettings(alertPrioritySelector, portletConfig);
-
- // //result sort order
- // selectedValue = resultSortSelector.getValue().toString();
- // if ((selectedValue.trim().isEmpty()) || (selectedValue.equalsIgnoreCase(PageOrdering.DESC.name()))) {//then desc
- // portletConfig.put(new PropertySimple(Constant.RESULT_SORT_ORDER, PageOrdering.DESC));
- // } else {
- // portletConfig.put(new PropertySimple(Constant.RESULT_SORT_ORDER, PageOrdering.ASC));
- // }
- //result count
- portletConfig = AbstractActivityView.saveResultCounterSettings(resultCountSelector, portletConfig);
-
- //time range settings
- portletConfig = AbstractActivityView.saveMeasurementRangeEditorSettings(measurementRangeEditor,
- portletConfig);
-
- //persist and reload portlet
- storedPortlet.setConfiguration(portletConfig);
- configure(portletWindow, storedPortlet);
- refresh();
- }
- });
- form.markForRedraw();
- page.addMember(measurementRangeEditor);
- page.addMember(form);
- customSettings.addChild(page);
- return customSettings;
}
- public AlertPortletConfigurationDataSource getDataSource() {
- return dataSource;
+ public int getResourceId() {
+ return groupId;
}
public static final class Factory implements PortletViewFactory {
public static PortletViewFactory INSTANCE = new Factory();
+ /* (non-Javadoc)
+ * TODO: This factory ASSUMES the user is currently navigated to a group detail view, and generates a portlet
+ * for that group. It will fail in other scenarios. This mechanism should be improved such that the
+ * factory method can take an EntityContext explicitly indicating, in this case, the group.
+ * @see org.rhq.enterprise.gui.coregui.client.dashboard.PortletViewFactory#getInstance(java.lang.String)
+ */
public final Portlet getInstance(String locatorId) {
- return new GroupAlertsPortlet(locatorId);
- }
- }
-
- public void startRefreshCycle() {
- refreshTimer = AutoRefreshPortletUtil.startRefreshCycle(this, this, refreshTimer);
- }
-
- @Override
- protected void onDestroy() {
- AutoRefreshPortletUtil.onDestroy(this, refreshTimer);
-
- super.onDestroy();
- }
-
- public boolean isRefreshing() {
- return this.currentlyRefreshing;
- }
-
- @Override
- protected void setupTableInteractions(boolean hasWriteAccess) {
- // The portlet is a "subsystem" view. Meaning the alerts displayed can be from any accessible group for
- // the user. This means the user can have varying permissions on the underlying groups and/or resources,
- // which makes button enablement tricky. So, for the portlet don't even show the buttons unless the user
- // is inventory manager. Other users will just have to navigate to the alert in question in order to
- // manipulate it.
-
- //determine if the user is inventory manager and if so render the buttons
- Set<Permission> permissions = this.portletWindow.getGlobalPermissions();
- if ((null != permissions) && permissions.contains(Permission.MANAGE_INVENTORY)) {
- super.setupTableInteractions(true);
- }
- }
-
- protected CellFormatter getDetailsLinkColumnCellFormatter() {
- return new CellFormatter() {
- public String format(Object value, ListGridRecord record, int i, int i1) {
- Integer recordId = getId(record);
- Integer resourceId = record.getAttributeAsInt("resourceId");
- String detailsUrl = LinkManager.getSubsystemAlertHistoryLink(resourceId, recordId);
- return SeleniumUtility.getLocatableHref(detailsUrl, value.toString(), null);
- }
- };
- }
-
- @Override
- protected void configureTable() {
- super.configureTable();
-
- setListGridDoubleClickHandler(new DoubleClickHandler() {
- @Override
- public void onDoubleClick(DoubleClickEvent event) {
- ListGrid listGrid = (ListGrid) event.getSource();
- ListGridRecord[] selectedRows = listGrid.getSelection();
- if (selectedRows != null && selectedRows.length == 1) {
- Integer recordId = getId(selectedRows[0]);
- Integer resourceId = selectedRows[0].getAttributeAsInt("resourceId");
- CoreGUI.goToView(LinkManager.getSubsystemAlertHistoryLink(resourceId, recordId));
- }
+ String currentPage = History.getToken();
+ int groupId = -1;
+ String[] elements = currentPage.split("/");
+ // process for groups and auto groups Ex. ResourceGroup/10111 or ResourceGroup/AutoCluster/10321
+ try {
+ groupId = Integer.valueOf(elements[1]);
+ } catch (NumberFormatException nfe) {
+ groupId = Integer.valueOf(elements[2]);
}
- });
- }
-
- @Override
- protected void onInit() {
- super.onInit();
- initializeUi();
- }
-
- @Override
- protected void refreshTableInfo() {
- super.refreshTableInfo();
- if (getTableInfo() != null) {
- int count = getListGrid().getSelection().length;
- getTableInfo().setContents(
- MSG.view_table_matchingRows(String.valueOf(getListGrid().getTotalRows()), String.valueOf(count)));
- }
- }
-
- @Override
- public void redraw() {
- super.redraw();
- refresh();//is table so need to call this to reload
- }
-}
-
-/** Bundles a ResourceSelector instance with labeling in Canvas for display.
- * Also modifies the AssignedGrid to listen for AvailbleGrid completion and act accordingly.
- */
-//class AlertResourceSelectorRegion extends LocatableVLayout {
-final class AlertResourceSelectorRegion extends LocatableVLayout {
- public AlertResourceSelectorRegion(String locatorId, Integer[] assigned) {
- super(locatorId);
- this.currentlyAssignedIds = assigned;
- }
-
- private PortletAlertSelector selector = null;
-
- private Integer[] currentlyAssignedIds;
-
- public Integer[] getCurrentlyAssignedIds() {
- return currentlyAssignedIds;
- }
- public Integer[] getListGridValues() {
- Integer[] listGridValues = new Integer[0];
- if (null != selector) {
- listGridValues = selector.getAssignedListGridValues();
+ return new GroupAlertsPortlet(locatorId, groupId);
}
- return listGridValues;
}
- public Canvas getCanvas() {
- if (selector == null) {
- selector = new PortletAlertSelector(extendLocatorId("AlertSelector"), this.currentlyAssignedIds,
- ResourceType.ANY_PLATFORM_TYPE, false);
- }
- return selector;
- }
-
- public void setCurrentlyAssignedIds(Integer[] currentlyAssignedIds) {
- this.currentlyAssignedIds = currentlyAssignedIds;
- }
}
\ No newline at end of file
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/groups/GroupAlertsPortlet3.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/groups/GroupAlertsPortlet3.java
deleted file mode 100644
index 2a2b3ac..0000000
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/groups/GroupAlertsPortlet3.java
+++ /dev/null
@@ -1,378 +0,0 @@
-/*
- * RHQ Management Platform
- * Copyright (C) 2005-2010 Red Hat, Inc.
- * All rights reserved.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation version 2 of the License.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-package org.rhq.enterprise.gui.coregui.client.dashboard.portlets.groups;
-
-import java.util.List;
-
-import com.allen_sauer.gwt.log.client.Log;
-import com.google.gwt.user.client.History;
-import com.google.gwt.user.client.Timer;
-import com.google.gwt.user.client.rpc.AsyncCallback;
-import com.smartgwt.client.widgets.Canvas;
-import com.smartgwt.client.widgets.HTMLFlow;
-import com.smartgwt.client.widgets.form.DynamicForm;
-import com.smartgwt.client.widgets.form.events.SubmitValuesEvent;
-import com.smartgwt.client.widgets.form.events.SubmitValuesHandler;
-import com.smartgwt.client.widgets.form.fields.CheckboxItem;
-import com.smartgwt.client.widgets.form.fields.FormItem;
-import com.smartgwt.client.widgets.form.fields.LinkItem;
-import com.smartgwt.client.widgets.form.fields.SelectItem;
-import com.smartgwt.client.widgets.form.fields.StaticTextItem;
-import com.smartgwt.client.widgets.layout.VLayout;
-
-import org.rhq.core.domain.alert.Alert;
-import org.rhq.core.domain.alert.AlertPriority;
-import org.rhq.core.domain.configuration.Configuration;
-import org.rhq.core.domain.configuration.PropertySimple;
-import org.rhq.core.domain.criteria.AlertCriteria;
-import org.rhq.core.domain.dashboard.DashboardPortlet;
-import org.rhq.core.domain.util.PageControl;
-import org.rhq.core.domain.util.PageList;
-import org.rhq.core.domain.util.PageOrdering;
-import org.rhq.enterprise.gui.coregui.client.ImageManager;
-import org.rhq.enterprise.gui.coregui.client.components.measurement.CustomConfigMeasurementRangeEditor;
-import org.rhq.enterprise.gui.coregui.client.dashboard.AutoRefreshPortlet;
-import org.rhq.enterprise.gui.coregui.client.dashboard.AutoRefreshPortletUtil;
-import org.rhq.enterprise.gui.coregui.client.dashboard.CustomSettingsPortlet;
-import org.rhq.enterprise.gui.coregui.client.dashboard.Portlet;
-import org.rhq.enterprise.gui.coregui.client.dashboard.PortletViewFactory;
-import org.rhq.enterprise.gui.coregui.client.dashboard.PortletWindow;
-import org.rhq.enterprise.gui.coregui.client.dashboard.portlets.PortletConfigurationEditorComponent;
-import org.rhq.enterprise.gui.coregui.client.dashboard.portlets.PortletConfigurationEditorComponent.Constant;
-import org.rhq.enterprise.gui.coregui.client.gwt.AlertGWTServiceAsync;
-import org.rhq.enterprise.gui.coregui.client.gwt.GWTServiceLookup;
-import org.rhq.enterprise.gui.coregui.client.inventory.common.detail.summary.AbstractActivityView;
-import org.rhq.enterprise.gui.coregui.client.resource.disambiguation.ReportDecorator;
-import org.rhq.enterprise.gui.coregui.client.util.GwtRelativeDurationConverter;
-import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableCanvas;
-import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableDynamicForm;
-import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableVLayout;
-
-/**This portlet allows the end user to customize the:
- * i)range
- * ii)priority
- * iii)etc.
- * of alerts to display for the given group
- *
- * @author Simeon Pinder
- */
-public class GroupAlertsPortlet3 extends LocatableVLayout implements CustomSettingsPortlet, AutoRefreshPortlet {
- private int groupId = -1;
- protected LocatableCanvas recentAlertsContent = new LocatableCanvas(extendLocatorId("RecentAlerts"));
- private static AlertGWTServiceAsync alertService = GWTServiceLookup.getAlertService();
- private boolean currentlyLoading = false;
- private Configuration portletConfig = null;
- private DashboardPortlet storedPortlet;
-
- public GroupAlertsPortlet3(String locatorId) {
- super(locatorId);
- //figure out which page we're loading
- String currentPage = History.getToken();
- String[] elements = currentPage.split("/");
- int currentGroupIdentifier = Integer.valueOf(elements[1]);
- this.groupId = currentGroupIdentifier;
- initializeUi();
- }
-
- @Override
- protected void onInit() {
- super.onInit();
- loadData();
- }
-
- /**Defines layout for the Activity page.
- */
- protected void initializeUi() {
- setPadding(5);
- setMembersMargin(5);
- addMember(recentAlertsContent);
- }
-
- // A non-displayed, persisted identifier for the portlet
- public static final String KEY = "GroupAlerts";
- // A default displayed, persisted name for the portlet
- public static final String NAME = "Group: Alerts";
- public static final String ID = "id";
-
- // set on initial configuration, the window for this portlet view.
- private PortletWindow portletWindow;
- //instance ui widgets
-
- private Timer refreshTimer;
-
- /** Responsible for initialization and lazy configuration of the portlet values
- */
- public void configure(PortletWindow portletWindow, DashboardPortlet storedPortlet) {
- //populate portlet configuration details
- if (null == this.portletWindow && null != portletWindow) {
- this.portletWindow = portletWindow;
- }
-
- if ((null == storedPortlet) || (null == storedPortlet.getConfiguration())) {
- return;
- }
- this.storedPortlet = storedPortlet;
- portletConfig = storedPortlet.getConfiguration();
-
- //lazy init any elements not yet configured.
- for (String key : PortletConfigurationEditorComponent.CONFIG_PROPERTY_INITIALIZATION.keySet()) {
- if (portletConfig.getSimple(key) == null) {
- portletConfig.put(new PropertySimple(key,
- PortletConfigurationEditorComponent.CONFIG_PROPERTY_INITIALIZATION.get(key)));
- }
- }
- }
-
- public Canvas getHelpCanvas() {
- return new HTMLFlow(MSG.view_portlet_help_recentAlerts());
- }
-
- public static final class Factory implements PortletViewFactory {
- public static PortletViewFactory INSTANCE = new Factory();
-
- public final Portlet getInstance(String locatorId) {
- return new GroupAlertsPortlet3(locatorId);
- }
- }
-
- /** Fetches alerts and updates the DynamicForm instance with the latest
- * alert information.
- */
- private void getRecentAlerts() {
- final int groupId = this.groupId;
- currentlyLoading = false;
- //fetches last five alerts for this resource
- AlertCriteria criteria = new AlertCriteria();
- //filter priority
- PropertySimple property = portletConfig.getSimple(Constant.ALERT_PRIORITY);
- if (property != null) {
- String currentSetting = property.getStringValue();
- String[] parsedValues = currentSetting.trim().split(",");
- if (currentSetting.trim().isEmpty() || parsedValues.length == 3) {
- //all alert priorities assumed
- } else {
- AlertPriority[] filterPriorities = new AlertPriority[parsedValues.length];
- int indx = 0;
- for (String priority : parsedValues) {
- AlertPriority p = AlertPriority.valueOf(priority);
- filterPriorities[indx++] = p;
- }
- criteria.addFilterPriorities(filterPriorities);
- }
- }
- PageControl pc = new PageControl();
- //result sort order
- property = portletConfig.getSimple(Constant.RESULT_SORT_ORDER);
- if (property != null) {
- String currentSetting = property.getStringValue();
- if (currentSetting.trim().isEmpty() || currentSetting.equalsIgnoreCase(PageOrdering.DESC.name())) {
- criteria.addSortCtime(PageOrdering.DESC);
- pc.setPrimarySortOrder(PageOrdering.DESC);
- } else {
- criteria.addSortCtime(PageOrdering.ASC);
- pc.setPrimarySortOrder(PageOrdering.ASC);
- }
- }
- //result timeframe if enabled
- property = portletConfig.getSimple(Constant.METRIC_RANGE_ENABLE);
- if (Boolean.valueOf(property.getBooleanValue())) {//then proceed setting
- property = portletConfig.getSimple(Constant.METRIC_RANGE);
- if (property != null) {
- String currentSetting = property.getStringValue();
- String[] range = currentSetting.split(",");
- criteria.addFilterStartTime(Long.valueOf(range[0]));
- criteria.addFilterEndTime(Long.valueOf(range[1]));
- }
- }
-
- //result count
- property = portletConfig.getSimple(Constant.RESULT_COUNT);
- if (property != null) {
- String currentSetting = property.getStringValue();
- if (currentSetting.trim().isEmpty() || currentSetting.equalsIgnoreCase("5")) {
- //PageControl pageControl = new PageControl(0, 5);
- pc.setPageSize(5);
- } else {
- //PageControl pageControl = new PageControl(0, Integer.valueOf(currentSetting));
- pc.setPageSize(Integer.valueOf(currentSetting));
- }
- }
- criteria.setPageControl(pc);
- criteria.addFilterResourceGroupIds(groupId);
- alertService.findAlertsByCriteria(criteria, new AsyncCallback<PageList<Alert>>() {
- @Override
- public void onSuccess(PageList<Alert> result) {
- VLayout column = new VLayout();
- column.setHeight(10);
- if (!result.isEmpty()) {
- int rowNum = 0;
- for (Alert alert : result) {
- // alert history records do not have a usable locatorId, we'll use rownum, which is unique and
- // may be repeatable.
- LocatableDynamicForm row = new LocatableDynamicForm(recentAlertsContent.extendLocatorId(String
- .valueOf(rowNum++)));
- row.setNumCols(3);
-
- StaticTextItem iconItem = AbstractActivityView.newTextItemIcon(ImageManager.getAlertIcon(alert
- .getAlertDefinition().getPriority()), alert.getAlertDefinition().getPriority()
- .getDisplayName());
- LinkItem link = AbstractActivityView.newLinkItem(alert.getAlertDefinition().getName() + ": ",
- ReportDecorator.GWT_GROUP_URL + groupId + "/Alerts/History/" + alert.getId());
- StaticTextItem time = AbstractActivityView.newTextItem(GwtRelativeDurationConverter
- .format(alert.getCtime()));
- row.setItems(iconItem, link, time);
-
- column.addMember(row);
- }
- //link to more details
- LocatableDynamicForm row = new LocatableDynamicForm(recentAlertsContent.extendLocatorId(String
- .valueOf(rowNum++)));
- AbstractActivityView.addSeeMoreLink(row, ReportDecorator.GWT_GROUP_URL + groupId
- + "/Alerts/History/", column);
- } else {
- LocatableDynamicForm row = AbstractActivityView.createEmptyDisplayRow(recentAlertsContent
- // .extendLocatorId("None"), AbstractActivityView.RECENT_ALERTS_NONE);
- .extendLocatorId("None"), "No results found using criteria specified.");
- column.addMember(row);
- }
- for (Canvas child : recentAlertsContent.getChildren()) {
- child.destroy();
- }
- recentAlertsContent.addChild(column);
- recentAlertsContent.markForRedraw();
- }
-
- @Override
- public void onFailure(Throwable caught) {
- Log.debug("Error retrieving recent alerts for group [" + groupId + "]:" + caught.getMessage());
- }
- });
- }
-
- protected void loadData() {
- currentlyLoading = true;
- getRecentAlerts();
- }
-
- @Override
- public DynamicForm getCustomSettingsForm() {
- LocatableDynamicForm customSettings = new LocatableDynamicForm(extendLocatorId("customSettings"));
- LocatableVLayout page = new LocatableVLayout(customSettings.extendLocatorId("page"));
- //build editor form container
- final LocatableDynamicForm form = new LocatableDynamicForm(page.extendLocatorId("alert-filter"));
- form.setMargin(5);
-
- //add label about what configuration affects
-
- //add alert priority selector
- final SelectItem alertPrioritySelector = PortletConfigurationEditorComponent
- .getAlertPriorityEditor(portletConfig);
- //add sort priority selector
- // final SelectItem resultSortSelector = PortletConfigurationEditorComponent
- // .getResulSortOrderEditor(portletConfig);
- //add result count selector
- final SelectItem resultCountSelector = PortletConfigurationEditorComponent.getResultCountEditor(portletConfig);
- //add range selector
- final CustomConfigMeasurementRangeEditor measurementRangeEditor = PortletConfigurationEditorComponent
- .getMeasurementRangeEditor(portletConfig);
- //TODO: spinder 3/10/11 renable sort selector once it's working in criteria
- // form.setItems(alertPrioritySelector, resultSortSelector, resultCountSelector);
- form.setItems(alertPrioritySelector, resultCountSelector);
-
- //submit handler
- customSettings.addSubmitValuesHandler(new SubmitValuesHandler() {
-
- @Override
- public void onSubmitValues(SubmitValuesEvent event) {
- //alert severity
- String selectedValue = alertPrioritySelector.getValue().toString();
- if ((selectedValue.trim().isEmpty()) || (selectedValue.split(",").length == 3)) {//then no alertPriority specified
- portletConfig.put(new PropertySimple(Constant.ALERT_PRIORITY, ""));
- } else {//some subset of available alertPriorities will be used
- portletConfig.put(new PropertySimple(Constant.ALERT_PRIORITY, selectedValue));
- }
- // //result sort order
- // selectedValue = resultSortSelector.getValue().toString();
- // if ((selectedValue.trim().isEmpty()) || (selectedValue.equalsIgnoreCase(PageOrdering.DESC.name()))) {//then desc
- // portletConfig.put(new PropertySimple(Constant.RESULT_SORT_ORDER, PageOrdering.DESC));
- // } else {
- // portletConfig.put(new PropertySimple(Constant.RESULT_SORT_ORDER, PageOrdering.ASC));
- // }
- //result count
- selectedValue = resultCountSelector.getValue().toString();
- if ((selectedValue.trim().isEmpty()) || (selectedValue.equalsIgnoreCase(Constant.RESULT_COUNT_DEFAULT))) {//then 5
- portletConfig.put(new PropertySimple(Constant.RESULT_COUNT, Constant.RESULT_COUNT_DEFAULT));
- } else {
- portletConfig.put(new PropertySimple(Constant.RESULT_COUNT, selectedValue));
- }
-
- //alert time range filter. Check for enabled and then persist property. Dealing with compound widget.
- FormItem item = measurementRangeEditor.getItem(CustomConfigMeasurementRangeEditor.ENABLE_RANGE_ITEM);
- CheckboxItem itemC = (CheckboxItem) item;
- selectedValue = String.valueOf(itemC.getValueAsBoolean());
- if (!selectedValue.trim().isEmpty()) {//then call
- portletConfig.put(new PropertySimple(Constant.METRIC_RANGE_ENABLE, selectedValue));
- }
-
- //alert time advanced time filter enabled.
- selectedValue = String.valueOf(measurementRangeEditor.isAdvanced());
- if ((selectedValue != null) && (!selectedValue.trim().isEmpty())) {
- portletConfig.put(new PropertySimple(Constant.METRIC_RANGE_BEGIN_END_FLAG, selectedValue));
- }
-
- //alert time frame
- List<Long> begEnd = measurementRangeEditor.getBeginEndTimes();
- if (begEnd.get(0) != 0) {//advanced settings
- portletConfig.put(new PropertySimple(Constant.METRIC_RANGE, (begEnd.get(0) + "," + begEnd.get(1))));
- }
-
- //persist
- storedPortlet.setConfiguration(portletConfig);
- configure(portletWindow, storedPortlet);
- loadData();
- }
- });
- form.markForRedraw();
- page.addMember(measurementRangeEditor);
- page.addMember(form);
- customSettings.addChild(page);
- return customSettings;
- }
-
- public void startRefreshCycle() {
- refreshTimer = AutoRefreshPortletUtil.startRefreshCycle(this, this, refreshTimer);
- }
-
- @Override
- protected void onDestroy() {
- AutoRefreshPortletUtil.onDestroy(this, refreshTimer);
-
- super.onDestroy();
- }
-
- public boolean isRefreshing() {
- return this.currentlyLoading;
- }
-
- @Override
- public void redraw() {
- super.redraw();
- loadData();
- }
-}
\ No newline at end of file
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/recent/alerts/AbstractRecentAlertsPortlet.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/recent/alerts/AbstractRecentAlertsPortlet.java
new file mode 100644
index 0000000..013e5be
--- /dev/null
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/recent/alerts/AbstractRecentAlertsPortlet.java
@@ -0,0 +1,376 @@
+package org.rhq.enterprise.gui.coregui.client.dashboard.portlets.recent.alerts;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+
+import com.google.gwt.user.client.Timer;
+import com.smartgwt.client.data.DSRequest;
+import com.smartgwt.client.data.DSResponse;
+import com.smartgwt.client.types.Overflow;
+import com.smartgwt.client.widgets.Canvas;
+import com.smartgwt.client.widgets.HTMLFlow;
+import com.smartgwt.client.widgets.form.DynamicForm;
+import com.smartgwt.client.widgets.form.events.SubmitValuesEvent;
+import com.smartgwt.client.widgets.form.events.SubmitValuesHandler;
+import com.smartgwt.client.widgets.form.fields.CheckboxItem;
+import com.smartgwt.client.widgets.form.fields.FormItem;
+import com.smartgwt.client.widgets.form.fields.SelectItem;
+
+import org.rhq.core.domain.alert.Alert;
+import org.rhq.core.domain.alert.AlertPriority;
+import org.rhq.core.domain.authz.Permission;
+import org.rhq.core.domain.common.EntityContext;
+import org.rhq.core.domain.configuration.Configuration;
+import org.rhq.core.domain.configuration.PropertySimple;
+import org.rhq.core.domain.criteria.AlertCriteria;
+import org.rhq.core.domain.dashboard.DashboardPortlet;
+import org.rhq.core.domain.resource.composite.ResourcePermission;
+import org.rhq.core.domain.util.OrderingField;
+import org.rhq.core.domain.util.PageControl;
+import org.rhq.core.domain.util.PageList;
+import org.rhq.core.domain.util.PageOrdering;
+import org.rhq.enterprise.gui.coregui.client.alert.AlertDataSource;
+import org.rhq.enterprise.gui.coregui.client.alert.AlertHistoryView;
+import org.rhq.enterprise.gui.coregui.client.components.measurement.CustomConfigMeasurementRangeEditor;
+import org.rhq.enterprise.gui.coregui.client.dashboard.AutoRefreshPortlet;
+import org.rhq.enterprise.gui.coregui.client.dashboard.AutoRefreshPortletUtil;
+import org.rhq.enterprise.gui.coregui.client.dashboard.CustomSettingsPortlet;
+import org.rhq.enterprise.gui.coregui.client.dashboard.PortletWindow;
+import org.rhq.enterprise.gui.coregui.client.dashboard.portlets.PortletConfigurationEditorComponent;
+import org.rhq.enterprise.gui.coregui.client.dashboard.portlets.PortletConfigurationEditorComponent.Constant;
+import org.rhq.enterprise.gui.coregui.client.util.MeasurementUtility;
+import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableDynamicForm;
+import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableVLayout;
+
+/**
+ * A base class for deriving recent alerts portlets for different entity contexts. In this way the
+ * basic plumbing is shared, giving a consistent behavior and configuration for the concrete portlets.
+ *
+ * @author Jay Shaughnessy
+ * @author Simeon Pinder
+ */
+public abstract class AbstractRecentAlertsPortlet extends AlertHistoryView implements CustomSettingsPortlet,
+ AutoRefreshPortlet {
+
+ // set on initial configuration, the window for this portlet view.
+ private PortletWindow portletWindow;
+
+ private AlertsPortletDataSource dataSource;
+
+ // autorefresh timer
+ private Timer refreshTimer;
+
+ public AbstractRecentAlertsPortlet(String locatorId, EntityContext entityContext) {
+ super(locatorId, entityContext);
+
+ setShowFilterForm(false); //disable filter form for portlet
+ setOverflow(Overflow.VISIBLE);
+ }
+
+ public Timer getRefreshTimer() {
+ return refreshTimer;
+ }
+
+ public void setRefreshTimer(Timer refreshTimer) {
+ this.refreshTimer = refreshTimer;
+ }
+
+ public PortletWindow getPortletWindow() {
+ return portletWindow;
+ }
+
+ @Override
+ public AlertsPortletDataSource getDataSource() {
+ if (null == this.dataSource) {
+ this.dataSource = new AlertsPortletDataSource(getContext());
+ }
+ return this.dataSource;
+ }
+
+ @Override
+ public Canvas getHelpCanvas() {
+ return new HTMLFlow(MSG.view_portlet_help_recentAlerts());
+ }
+
+ @Override
+ public void configure(PortletWindow portletWindow, DashboardPortlet storedPortlet) {
+
+ // the portletWindow does not change, so we can hold onto it locally
+ if (null == this.portletWindow && null != portletWindow) {
+ this.portletWindow = portletWindow;
+ }
+
+ // if there is no configuration there is nothing to set
+ if ((null == storedPortlet) || (null == storedPortlet.getConfiguration())) {
+ return;
+ }
+
+ Configuration config = storedPortlet.getConfiguration();
+
+ // not sure I love the fact that this common portlet config assigns some irrelevant/unused config props,
+ // may be better to prune the common set and add the specific properties locally in this method
+ for (String key : PortletConfigurationEditorComponent.CONFIG_PROPERTY_INITIALIZATION.keySet()) {
+ if (config.getSimple(key) == null) {
+ config.put(new PropertySimple(key, PortletConfigurationEditorComponent.CONFIG_PROPERTY_INITIALIZATION
+ .get(key)));
+ }
+ }
+
+ getDataSource().setConfiguration(config);
+ }
+
+ @Override
+ public DynamicForm getCustomSettingsForm() {
+
+ LocatableDynamicForm customSettingsForm = new LocatableDynamicForm(extendLocatorId("CustomSettings"));
+ LocatableVLayout page = new LocatableVLayout(customSettingsForm.extendLocatorId("Page"));
+ LocatableDynamicForm filterForm = new LocatableDynamicForm(page.extendLocatorId("Filter"));
+ filterForm.setMargin(5);
+
+ final DashboardPortlet storedPortlet = this.portletWindow.getStoredPortlet();
+ final Configuration portletConfig = storedPortlet.getConfiguration();
+
+ // alert priority selector
+ final SelectItem alertPrioritySelector = PortletConfigurationEditorComponent
+ .getAlertPriorityEditor(portletConfig);
+
+ // result count selector
+ final SelectItem resultCountSelector = PortletConfigurationEditorComponent.getResultCountEditor(portletConfig);
+
+ // range selector
+ final CustomConfigMeasurementRangeEditor measurementRangeEditor = PortletConfigurationEditorComponent
+ .getMeasurementRangeEditor(portletConfig);
+
+ filterForm.setItems(alertPrioritySelector, resultCountSelector);
+
+ //submit handler
+ customSettingsForm.addSubmitValuesHandler(new SubmitValuesHandler() {
+
+ @Override
+ public void onSubmitValues(SubmitValuesEvent event) {
+ // alert severity
+ String selectedValue = alertPrioritySelector.getValue().toString();
+ if ((selectedValue.trim().isEmpty())
+ || (selectedValue.split(",").length == AlertPriority.values().length)) {
+ // no severity filter
+ selectedValue = Constant.ALERT_PRIORITY_DEFAULT;
+ }
+ portletConfig.put(new PropertySimple(Constant.ALERT_PRIORITY, selectedValue));
+
+ // result count
+ selectedValue = resultCountSelector.getValue().toString();
+ if (selectedValue.trim().isEmpty()) {
+ selectedValue = Constant.RESULT_COUNT_DEFAULT;
+ }
+ portletConfig.put(new PropertySimple(Constant.RESULT_COUNT, selectedValue));
+
+ // time range settings
+ saveMeasurementRangeEditorSettings(measurementRangeEditor, portletConfig);
+
+ // persist and reload portlet
+ storedPortlet.setConfiguration(portletConfig);
+ configure(portletWindow, storedPortlet);
+ }
+ });
+
+ page.addMember(measurementRangeEditor);
+ page.addMember(filterForm);
+ customSettingsForm.addChild(page);
+
+ return customSettingsForm;
+ }
+
+ /**
+ * Takes the current value of the widget and persists it into the configuration object passed in.
+ *
+ * @param measurementRangeEditor
+ * @param portletConfig
+ * returns populated configuration object.
+ */
+ private void saveMeasurementRangeEditorSettings(final CustomConfigMeasurementRangeEditor measurementRangeEditor,
+ Configuration portletConfig) {
+ String selectedValue = null;
+ if ((measurementRangeEditor != null) && (portletConfig != null)) {
+ //time range filter. Check for enabled and then persist property. Dealing with compound widget.
+ FormItem item = measurementRangeEditor.getItem(CustomConfigMeasurementRangeEditor.ENABLE_RANGE_ITEM);
+ CheckboxItem itemC = (CheckboxItem) item;
+ boolean persistTimeRangeSettings = itemC.getValueAsBoolean();
+ if (persistTimeRangeSettings) {//retrieve values and persist
+ selectedValue = String.valueOf(itemC.getValueAsBoolean());
+ if (!selectedValue.trim().isEmpty()) {//then call
+ portletConfig.put(new PropertySimple(Constant.METRIC_RANGE_ENABLE, selectedValue));
+ }
+
+ //time advanced time filter enabled.
+ boolean isAdvanceTimeSetting = false;
+ selectedValue = String.valueOf(measurementRangeEditor.isAdvanced());
+ if ((selectedValue != null) && (!selectedValue.trim().isEmpty())) {
+ portletConfig.put(new PropertySimple(Constant.METRIC_RANGE_BEGIN_END_FLAG, selectedValue));
+ isAdvanceTimeSetting = Boolean.valueOf(selectedValue);
+ }
+
+ //time frame
+ List<Long> begEnd = measurementRangeEditor.getBeginEndTimes();
+ if (isAdvanceTimeSetting) {//advanced settings
+ portletConfig.put(new PropertySimple(Constant.METRIC_RANGE, (begEnd.get(0) + "," + begEnd.get(1))));
+ } else {
+ //save not advanced time range
+ portletConfig.put(new PropertySimple(Constant.METRIC_RANGE_LASTN, measurementRangeEditor
+ .getMetricRangePreferences().lastN));
+ portletConfig.put(new PropertySimple(Constant.METRIC_RANGE_UNIT, measurementRangeEditor
+ .getMetricRangePreferences().unit));
+ }
+ } else {//if disabled, reset time defaults
+ portletConfig.put(new PropertySimple(Constant.METRIC_RANGE_ENABLE, false));
+ portletConfig.put(new PropertySimple(Constant.METRIC_RANGE_BEGIN_END_FLAG, false));
+ List<Long> rangeArray = MeasurementUtility.calculateTimeFrame(Integer
+ .valueOf(Constant.METRIC_RANGE_LASTN_DEFAULT), Integer.valueOf(Constant.METRIC_RANGE_UNIT_DEFAULT));
+ // String[] range = {String.valueOf(rangeArray.get(0)),String.valueOf(rangeArray.get(1))};
+ portletConfig.put(new PropertySimple(Constant.METRIC_RANGE,
+ (String.valueOf(rangeArray.get(0)) + "," + String.valueOf(rangeArray.get(1)))));
+ }
+ }
+ }
+
+ @Override
+ protected void setupTableInteractions(boolean hasWriteAccess) {
+ if (!hasWriteAccess) {
+ Set<Permission> globalPerm = this.getPortletWindow().getGlobalPermissions();
+ ResourcePermission resPerm = this.getPortletWindow().getResourcePermissions();
+ hasWriteAccess = (globalPerm.contains(Permission.MANAGE_INVENTORY) || (null != resPerm && resPerm.isAlert()));
+ }
+ super.setupTableInteractions(hasWriteAccess);
+ }
+
+ public void startRefreshCycle() {
+ refreshTimer = AutoRefreshPortletUtil.startRefreshCycle(this, this, refreshTimer);
+ }
+
+ public boolean isRefreshing() {
+ // TODO: actually keep track of when the portlet is refreshing data
+ return false;
+ }
+
+ @Override
+ protected void onDestroy() {
+ AutoRefreshPortletUtil.onDestroy(this, refreshTimer);
+
+ super.onDestroy();
+ }
+
+ static public class AlertsPortletDataSource extends AlertDataSource {
+ private Configuration configuration;
+
+ public AlertsPortletDataSource(EntityContext entityContext) {
+ this(entityContext, null);
+ }
+
+ public AlertsPortletDataSource(EntityContext entityContext, Configuration configuration) {
+ super(entityContext);
+ this.configuration = configuration;
+ }
+
+ public Configuration getConfiguration() {
+ return configuration;
+ }
+
+ public void setConfiguration(Configuration configuration) {
+ this.configuration = configuration;
+ }
+
+ /* (non-Javadoc)
+ * This override allows us to set the total rows to the number of recent alerts configured for
+ * the portlet. This sets the counter appropriately and stops further queries to the server.
+ *
+ * @see org.rhq.enterprise.gui.coregui.client.alert.AlertDataSource#dataRetrieved(org.rhq.core.domain.util.PageList, com.smartgwt.client.data.DSResponse, com.smartgwt.client.data.DSRequest)
+ */
+ @Override
+ protected void dataRetrieved(PageList<Alert> result, DSResponse response, DSRequest request) {
+ super.dataRetrieved(result, response, request);
+
+ response.setTotalRows(result.size());
+ }
+
+ @Override
+ protected AlertCriteria getFetchCriteria(DSRequest request) {
+ AlertCriteria criteria = new AlertCriteria();
+
+ // result count
+ String currentSetting = this.configuration.getSimpleValue(Constant.RESULT_COUNT,
+ Constant.RESULT_COUNT_DEFAULT);
+
+ // We have to set a PageControl override here, or RPCDataSource will apply default paging based on the
+ // request. But, once setting a paging override the CriteriaQueryGenerator will use it for
+ // paging *and* sorting, so we need to also ensure our desired sorting is included in the override. So,
+ // to get the most recent alerts, apply a descending ordering on create time.
+ int pageNumber = 0;
+ int pageSize = Integer.valueOf(currentSetting);
+ OrderingField orderingField = new OrderingField("ctime", PageOrdering.DESC);
+ criteria.setPageControl(new PageControl(pageNumber, pageSize, orderingField));
+
+ // filter priority
+ currentSetting = this.configuration
+ .getSimpleValue(Constant.ALERT_PRIORITY, Constant.ALERT_PRIORITY_DEFAULT);
+ String[] parsedValues = currentSetting.trim().split(",");
+ if (!(currentSetting.trim().isEmpty() || parsedValues.length == 3)) {
+ AlertPriority[] filterPriorities = new AlertPriority[parsedValues.length];
+ int indx = 0;
+ for (String priority : parsedValues) {
+ AlertPriority p = AlertPriority.valueOf(priority);
+ filterPriorities[indx++] = p;
+ }
+ criteria.addFilterPriorities(filterPriorities);
+ }
+
+ //result timeframe if enabled
+ currentSetting = this.configuration.getSimpleValue(Constant.METRIC_RANGE_ENABLE, null);
+ if (Boolean.valueOf(currentSetting)) {//then proceed setting
+
+ boolean isAdvanced = false;
+ //detect type of widget[Simple|Advanced]
+ PropertySimple property = this.configuration.getSimple(Constant.METRIC_RANGE_BEGIN_END_FLAG);
+ if (property != null) {
+ isAdvanced = property.getBooleanValue();
+ }
+ if (isAdvanced) {
+ //Advanced time settings
+ property = this.configuration.getSimple(Constant.METRIC_RANGE);
+ if (property != null) {
+ currentSetting = property.getStringValue();
+ String[] range = currentSetting.split(",");
+ criteria.addFilterStartTime(Long.valueOf(range[0]));
+ criteria.addFilterEndTime(Long.valueOf(range[1]));
+ }
+ } else {
+ //Simple time settings
+ property = this.configuration.getSimple(Constant.METRIC_RANGE_LASTN);
+ if (property != null) {
+ int lastN = property.getIntegerValue();
+ property = this.configuration.getSimple(Constant.METRIC_RANGE_UNIT);
+ int lastUnits = property.getIntegerValue();
+ ArrayList<Long> beginEnd = MeasurementUtility.calculateTimeFrame(lastN, Integer
+ .valueOf(lastUnits));
+ criteria.addFilterStartTime(Long.valueOf(beginEnd.get(0)));
+ criteria.addFilterEndTime(Long.valueOf(beginEnd.get(1)));
+ }
+ }
+ }
+
+ // add any context related filters
+ switch (getEntityContext().type) {
+ case Resource:
+ criteria.addFilterResourceIds(getEntityContext().getResourceId());
+ break;
+
+ case ResourceGroup:
+ criteria.addFilterResourceGroupIds(getEntityContext().getGroupId());
+ }
+
+ criteria.fetchAlertDefinition(true);
+ criteria.fetchRecoveryAlertDefinition(true);
+
+ return criteria;
+ }
+ }
+}
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/recent/alerts/PortletAlertSelector.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/recent/alerts/PortletAlertSelector.java
deleted file mode 100644
index dae36c2..0000000
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/recent/alerts/PortletAlertSelector.java
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
- * RHQ Management Platform
- * Copyright (C) 2005-2010 Red Hat, Inc.
- * All rights reserved.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 2, as
- * published by the Free Software Foundation, and/or the GNU Lesser
- * General Public License, version 2.1, also as published by the Free
- * Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License and the GNU Lesser General Public License
- * for more details.
- *
- * You should have received a copy of the GNU General Public License
- * and the GNU Lesser General Public License along with this program;
- * if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.rhq.enterprise.gui.coregui.client.dashboard.portlets.recent.alerts;
-
-import com.google.gwt.user.client.rpc.AsyncCallback;
-import com.smartgwt.client.data.Record;
-import com.smartgwt.client.data.RecordList;
-import com.smartgwt.client.types.ListGridFieldType;
-import com.smartgwt.client.widgets.grid.ListGridField;
-import com.smartgwt.client.widgets.grid.ListGridRecord;
-
-import org.rhq.core.domain.criteria.ResourceCriteria;
-import org.rhq.core.domain.resource.Resource;
-import org.rhq.core.domain.resource.ResourceType;
-import org.rhq.core.domain.util.PageList;
-import org.rhq.enterprise.gui.coregui.client.CoreGUI;
-import org.rhq.enterprise.gui.coregui.client.gwt.GWTServiceLookup;
-import org.rhq.enterprise.gui.coregui.client.inventory.resource.ResourceDatasource;
-import org.rhq.enterprise.gui.coregui.client.inventory.resource.selection.ResourceSelector;
-
-/**
- * @author Simeon Pinder
- */
-public class PortletAlertSelector extends ResourceSelector {
-
- public PortletAlertSelector(String locatorId, Integer[] currentlyAssignedIds, ResourceType resourceTypeFilter,
- boolean forceResourceTypeFilter) {
- super(locatorId, resourceTypeFilter, forceResourceTypeFilter);
-
- //populate fields for grid.
- ListGridField nameField = new ListGridField("name", MSG.common_title_name());
- ListGridField iconField = new ListGridField("icon", MSG.common_title_icon(), 50);
- iconField.setType(ListGridFieldType.ICON);
- assignedGrid.setFields(iconField, nameField);
-
- setWidth(RecentAlertsPortlet.ALERT_RESOURCE_SELECTION_WIDTH);
-
- //retrieve the previously assigned resource ids
- if ((currentlyAssignedIds != null) && currentlyAssignedIds.length > 0) {
- //build listgrid records
- ResourceCriteria criteria = new ResourceCriteria();
- criteria.addFilterIds(currentlyAssignedIds);
-
- GWTServiceLookup.getResourceService().findResourcesByCriteria(criteria,
- new AsyncCallback<PageList<Resource>>() {
- @Override
- public void onSuccess(PageList<Resource> result) {
- if (result.size() > 0) {
- ListGridRecord[] data = (new ResourceDatasource()).buildRecords(result);
- assignedGrid.setData(data);
- }
- }
-
- @Override
- public void onFailure(Throwable caught) {
- CoreGUI.getErrorHandler().handleError(MSG.view_portlet_recentAlerts_fail_msg(), caught);
- }
- });
- }
- }
-
- public Integer[] getAssignedListGridValues() {
- Integer[] listGridValues = new Integer[0];
- if ((null != assignedGrid)) {
- RecordList allRecords = assignedGrid.getDataAsRecordList();
- if (allRecords.getLength() > 0) {
- listGridValues = new Integer[allRecords.getLength()];
- for (int i = 0; i < allRecords.getLength(); i++) {
- Record record = allRecords.get(i);
- listGridValues[i] = record.getAttributeAsInt(RecentAlertsPortlet.ID);
- }
- }
- }
- return listGridValues;
- }
-}
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/recent/alerts/RecentAlertsPortlet.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/recent/alerts/RecentAlertsPortlet.java
index fed9070..51e12b6 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/recent/alerts/RecentAlertsPortlet.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/recent/alerts/RecentAlertsPortlet.java
@@ -18,542 +18,22 @@
*/
package org.rhq.enterprise.gui.coregui.client.dashboard.portlets.recent.alerts;
-import java.util.Set;
-
-import com.google.gwt.user.client.Timer;
-import com.smartgwt.client.types.Overflow;
-import com.smartgwt.client.widgets.Canvas;
-import com.smartgwt.client.widgets.HTMLFlow;
-import com.smartgwt.client.widgets.events.DoubleClickEvent;
-import com.smartgwt.client.widgets.events.DoubleClickHandler;
-import com.smartgwt.client.widgets.form.DynamicForm;
-import com.smartgwt.client.widgets.form.events.SubmitValuesEvent;
-import com.smartgwt.client.widgets.form.events.SubmitValuesHandler;
-import com.smartgwt.client.widgets.form.fields.SelectItem;
-import com.smartgwt.client.widgets.form.fields.SpacerItem;
-import com.smartgwt.client.widgets.form.fields.events.ChangeEvent;
-import com.smartgwt.client.widgets.form.fields.events.ChangeHandler;
-import com.smartgwt.client.widgets.grid.CellFormatter;
-import com.smartgwt.client.widgets.grid.ListGrid;
-import com.smartgwt.client.widgets.grid.ListGridRecord;
-import com.smartgwt.client.widgets.layout.VLayout;
-
-import org.rhq.core.domain.alert.AlertPriority;
-import org.rhq.core.domain.authz.Permission;
-import org.rhq.core.domain.configuration.PropertyList;
-import org.rhq.core.domain.configuration.PropertySimple;
-import org.rhq.core.domain.dashboard.DashboardPortlet;
-import org.rhq.core.domain.resource.ResourceType;
-import org.rhq.enterprise.gui.coregui.client.CoreGUI;
-import org.rhq.enterprise.gui.coregui.client.LinkManager;
-import org.rhq.enterprise.gui.coregui.client.alert.AlertHistoryView;
-import org.rhq.enterprise.gui.coregui.client.alert.AlertPortletDataSource;
-import org.rhq.enterprise.gui.coregui.client.dashboard.AutoRefreshPortlet;
-import org.rhq.enterprise.gui.coregui.client.dashboard.AutoRefreshPortletUtil;
-import org.rhq.enterprise.gui.coregui.client.dashboard.CustomSettingsPortlet;
+import org.rhq.core.domain.common.EntityContext;
import org.rhq.enterprise.gui.coregui.client.dashboard.Portlet;
import org.rhq.enterprise.gui.coregui.client.dashboard.PortletViewFactory;
-import org.rhq.enterprise.gui.coregui.client.dashboard.PortletWindow;
-import org.rhq.enterprise.gui.coregui.client.util.MeasurementUtility;
-import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableDynamicForm;
-import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableHLayout;
-import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableLabel;
-import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableVLayout;
-import org.rhq.enterprise.gui.coregui.client.util.selenium.SeleniumUtility;
/**
- * @author Simeon Pinder
- * @author Greg Hinkle
+ * @author Jay Shaughnessy
*/
-public class RecentAlertsPortlet extends AlertHistoryView implements CustomSettingsPortlet, AutoRefreshPortlet {
+public class RecentAlertsPortlet extends AbstractRecentAlertsPortlet {
// A non-displayed, persisted identifier for the portlet
public static final String KEY = "RecentAlerts";
// A default displayed, persisted name for the portlet
public static final String NAME = MSG.view_portlet_defaultName_recentAlerts();
- //widget keys also used in form population
- public static final String ALERT_RANGE_DISPLAY_AMOUNT_VALUE = "alert-range-display-amount-value";
- public static final String ALERT_RANGE_PRIORITY_VALUE = "alert-range-priority-value";
- public static final String ALERT_RANGE_TIME_VALUE = "alert-range-time-value";
- public static final String ALERT_RANGE_RESOURCES_VALUE = "alert-range-resource-value";
- public static final String ALERT_RANGE_RESOURCE_IDS = "alert-range-resource-ids";
- //configuration default information
- private static final String defaultAlertCountValue = "5";
- private static final String PRIORITY_ALL = MSG.common_label_all();
- private static final String PRIORITY_HIGH = AlertPriority.HIGH.getDisplayName();
- private static final String PRIORITY_MEDIUM = AlertPriority.MEDIUM.getDisplayName();
- private static final String PRIORITY_LOW = AlertPriority.LOW.getDisplayName();
- private static final String defaultPriorityValue = PRIORITY_ALL;
- private static final String TIME_30_MINS = "30 " + MSG.common_label_minutes();
- private static final String TIME_HOUR = MSG.common_label_hour();
- private static final String TIME_12_HRS = "12 " + MSG.common_label_hours();
- private static final String TIME_DAY = MSG.common_label_day();
- private static final String TIME_WEEK = MSG.common_label_week();
- private static final String TIME_MONTH = MSG.common_label_month();
- private static final String defaultTimeValue = TIME_DAY;
- public static final String RESOURCES_ALL = MSG.common_label_all_resources();
- public static final String RESOURCES_SELECTED = MSG.common_label_selected_resources();
- public static final String defaultResourceValue = RESOURCES_ALL;
- private static final String unlimited = MSG.common_label_unlimited();
- //alert resource labels
- public static final String ALERT_LABEL_SELECTED_RESOURCES = MSG.common_title_selected_resources();
- public static final String ALERT_LABEL_AVAILABLE_RESOURCES = MSG.common_title_available_resources();
- public static final String ALERT_LABEL_RESOURCE_INVENTORY = MSG.common_title_resource_inventory();
- public static final int ALERT_RESOURCE_SELECTION_WIDTH = 800;
- public static final String ID = "id";
-
- // set on initial configuration, the window for this portlet view.
- private PortletWindow portletWindow;
-
- //shared private UI elements
- private AlertResourceSelectorRegion resourceSelector;
-
- private AlertPortletDataSource dataSource;
- //instance ui widgets
- private Canvas containerCanvas;
-
- private Timer refreshTimer;
-
public RecentAlertsPortlet(String locatorId) {
- super(locatorId);
-
- //override the shared datasource
- this.dataSource = new AlertPortletDataSource();
- setDataSource(this.dataSource);
-
- setShowHeader(false);
- setShowFooter(true);
- setShowFooterRefresh(false); //disable footer refresh
- setShowFilterForm(false); //disable filter form for portlet
-
- setOverflow(Overflow.VISIBLE);
- }
-
- public void configure(PortletWindow portletWindow, DashboardPortlet storedPortlet) {
-
- if (null == this.portletWindow && null != portletWindow) {
- this.portletWindow = portletWindow;
- }
-
- if ((null == storedPortlet) || (null == storedPortlet.getConfiguration())) {
- return;
- }
-
- //Operation range property - retrieve existing value
- PropertySimple property = storedPortlet.getConfiguration().getSimple(ALERT_RANGE_DISPLAY_AMOUNT_VALUE);
- if ((property != null) && (property.getStringValue() != null)) {
- //retrieve and translate to int
- String retrieved = property.getStringValue();
- int translatedAlertRangeSelection = translatedAlertRangeSelection(retrieved);
- getDataSource().setAlertRangeCompleted(translatedAlertRangeSelection);
- } else {//create setting
- storedPortlet.getConfiguration().put(
- new PropertySimple(ALERT_RANGE_DISPLAY_AMOUNT_VALUE, defaultAlertCountValue));
- getDataSource().setAlertRangeCompleted(Integer.parseInt(defaultAlertCountValue));
- }
- //Operation priority property setting
- property = storedPortlet.getConfiguration().getSimple(ALERT_RANGE_PRIORITY_VALUE);
- if ((property != null) && (property.getStringValue() != null)) {
- //retrieve and translate to int
- String retrieved = property.getStringValue();
- int translatedPriorityIndex = translatedPriorityToValidIndex(retrieved);
- getDataSource().setAlertPriorityIndex(translatedPriorityIndex);
- } else {//create setting
- storedPortlet.getConfiguration().put(new PropertySimple(ALERT_RANGE_PRIORITY_VALUE, defaultPriorityValue));
- getDataSource().setAlertPriorityIndex(translatedPriorityToValidIndex(PRIORITY_ALL));
- }
-
- //Range to time that alerts will be shown for
- property = storedPortlet.getConfiguration().getSimple(ALERT_RANGE_TIME_VALUE);
- if ((property != null) && (property.getStringValue() != null)) {
- //retrieve and translate to int
- String retrieved = property.getStringValue();
- long translatedRange = translateTimeToValidRange(retrieved);
- getDataSource().setAlertTimeRange(translatedRange);
- } else {//create setting
- storedPortlet.getConfiguration().put(new PropertySimple(ALERT_RANGE_TIME_VALUE, defaultTimeValue));
- getDataSource().setAlertTimeRange(translateTimeToValidRange(defaultTimeValue));
- }
-
- //Range of resources to be included in the query
- property = storedPortlet.getConfiguration().getSimple(ALERT_RANGE_RESOURCES_VALUE);
- if ((property != null) && (property.getStringValue() != null)) {
- //retrieve and translate to int
- String retrieved = property.getStringValue();
- if (retrieved.trim().equalsIgnoreCase(RESOURCES_SELECTED)) {
- getDataSource().setAlertResourcesToUse(RESOURCES_SELECTED);
- } else {
- getDataSource().setAlertResourcesToUse(RESOURCES_ALL);
- }
- } else {//create setting
- storedPortlet.getConfiguration().put(new PropertySimple(ALERT_RANGE_RESOURCES_VALUE, defaultResourceValue));
- getDataSource().setAlertResourcesToUse(RESOURCES_ALL);
- }
-
- //resource ids to be conditionally included in the query
- Integer[] filterResourceIds = null;
- filterResourceIds = getDataSource().extractFilterResourceIds(storedPortlet, filterResourceIds);
- //no defaults
-
- if (filterResourceIds != null) {
- getDataSource().setAlertFilterResourceId(filterResourceIds);
- }
-
- //conditionally display the selected resources ui
- if (containerCanvas != null) {
- //empty out earlier canvas
- for (Canvas c : containerCanvas.getChildren()) {
- c.destroy();
- }
- if ((resourceSelector != null) && getDataSource().getAlertResourcesToUse().equals(RESOURCES_SELECTED)) {
- containerCanvas.addChild(resourceSelector.getCanvas());
- } else {
- containerCanvas.addChild(new Canvas());
- }
- }
- }
-
- private int translatedAlertRangeSelection(String retrieved) {
- int translated = -1;
- if ((retrieved != null) && (!retrieved.trim().isEmpty())) {
- if (retrieved.equalsIgnoreCase(unlimited)) {
- translated = -1;
- } else {
- translated = Integer.parseInt(retrieved);//default to all
- }
- } else {//default to defaultValue
- if (defaultAlertCountValue.equalsIgnoreCase(unlimited)) {
- translated = -1;
- } else {
- translated = Integer.parseInt(defaultAlertCountValue);
- }
- }
- return translated;
- }
-
- private int translatedPriorityToValidIndex(String retrieved) {
- int translatedPriority = 0;//default to all
- if ((retrieved != null) && (!retrieved.trim().isEmpty())) {
- if (retrieved.equalsIgnoreCase(PRIORITY_HIGH)) {
- translatedPriority = 3;
- } else if (retrieved.equalsIgnoreCase(PRIORITY_MEDIUM)) {
- translatedPriority = 2;
- } else if (retrieved.equalsIgnoreCase(PRIORITY_LOW)) {
- translatedPriority = 1;
- } else {
- translatedPriority = 0;//default to all
- }
- }
- return translatedPriority;
- }
-
- /**Translates the UI selection options into time values for alert query.
- *
- * @param retrieved
- * @return long value mapping to string passed in.
- */
- private long translateTimeToValidRange(String retrieved) {
- long translated = 0;//default to ALL
- if ((retrieved != null) && (!retrieved.trim().isEmpty())) {
- if (retrieved.equalsIgnoreCase(TIME_30_MINS)) {
- translated = MeasurementUtility.MINUTES * 30;
- } else if (retrieved.equalsIgnoreCase(TIME_HOUR)) {
- translated = MeasurementUtility.HOURS;
- } else if (retrieved.equalsIgnoreCase(TIME_12_HRS)) {
- translated = MeasurementUtility.HOURS * 12;
- } else if (retrieved.equalsIgnoreCase(TIME_DAY)) {
- translated = MeasurementUtility.DAYS;
- } else if (retrieved.equalsIgnoreCase(TIME_WEEK)) {
- translated = MeasurementUtility.WEEKS;
- } else if (retrieved.equalsIgnoreCase(TIME_MONTH)) {
- translated = MeasurementUtility.DAYS * 28;//replicated from old struts def.
- } else {
- translated = MeasurementUtility.DAYS;//default to day otherwise.
- }
- }
- return translated;
- }
-
- public Canvas getHelpCanvas() {
- return new HTMLFlow(MSG.view_portlet_help_recentAlerts());
- }
-
- public DynamicForm getCustomSettingsForm() {
- //root dynamic form instance
- final LocatableDynamicForm form = new LocatableDynamicForm(extendLocatorId("custom-settings"));
- form.setWidth(RecentAlertsPortlet.ALERT_RESOURCE_SELECTION_WIDTH + 40);//largest widget display + 40 for buttons
- form.setHeight(400);
- form.setMargin(5);
-
- final DashboardPortlet storedPortlet = portletWindow.getStoredPortlet();
-
- //vertical container
- VLayout column = new VLayout();
-
- //label
- LocatableLabel alertRangeLabel = new LocatableLabel(extendLocatorId("DynamicForm_Label_Alert_Range"), "<b>"
- + MSG.common_title_alert_range() + "</b>");
-
- //horizontal layout
- LocatableHLayout row = new LocatableHLayout(extendLocatorId("alert-range-settings-row-1"));
- row.setMembersMargin(10);
-
- //-------------combobox for number of completed scheduled ops to display on the dashboard
- final SelectItem alertRangeLastComboBox = new SelectItem(ALERT_RANGE_DISPLAY_AMOUNT_VALUE);
- alertRangeLastComboBox.setTitle(MSG.view_measureRange_last());
- alertRangeLastComboBox.setType("selection");
- alertRangeLastComboBox.setWrapTitle(false);
- //define acceptable values for display amount
- String[] acceptableDisplayValues = { "5", "10", MSG.common_label_unlimited() };
- alertRangeLastComboBox.setValueMap(acceptableDisplayValues);
- //set width of dropdown display region
- alertRangeLastComboBox.setWidth(100);
- alertRangeLastComboBox.addChangeHandler(new ChangeHandler() {
- public void onChange(ChangeEvent event) {
- String selectedItem = "" + event.getValue();
- //stuff into the master form for retrieval
- form.setValue(ALERT_RANGE_DISPLAY_AMOUNT_VALUE, selectedItem);
- }
- });
-
- //default selected value to 'unlimited'(live lists) and check both combobox settings here.
- String selectedValue = defaultAlertCountValue;
- if (storedPortlet != null) {
- //if property exists retrieve it
- if (storedPortlet.getConfiguration().getSimple(ALERT_RANGE_DISPLAY_AMOUNT_VALUE) != null) {
- selectedValue = storedPortlet.getConfiguration().getSimple(ALERT_RANGE_DISPLAY_AMOUNT_VALUE)
- .getStringValue();
- } else {//insert default value
- storedPortlet.getConfiguration().put(
- new PropertySimple(ALERT_RANGE_DISPLAY_AMOUNT_VALUE, defaultAlertCountValue));
- }
- }
- //prepopulate the combobox with the previously stored selection
- alertRangeLastComboBox.setDefaultValue(selectedValue);
-
- //-------------combobox for number of completed scheduled ops to display on the dashboard
- final SelectItem alertRangePriorityComboBox = new SelectItem(ALERT_RANGE_PRIORITY_VALUE);
- alertRangePriorityComboBox.setTitle("");
- alertRangePriorityComboBox.setHint("<nobr> <b> " + MSG.view_portlet_recentAlerts_config_priority_label()
- + "</b></nobr>");
- alertRangePriorityComboBox.setType("selection");
- //define acceptable values for display amount
- String[] acceptablePriorityDisplayValues = { PRIORITY_ALL, PRIORITY_HIGH, PRIORITY_MEDIUM, PRIORITY_LOW };
- alertRangePriorityComboBox.setValueMap(acceptablePriorityDisplayValues);
- //set width of dropdown display region
- alertRangePriorityComboBox.setWidth(100);
- alertRangePriorityComboBox.addChangeHandler(new ChangeHandler() {
- public void onChange(ChangeEvent event) {
- String selectedItem = "" + event.getValue();
- //stuff into the master form for retrieval
- form.setValue(ALERT_RANGE_PRIORITY_VALUE, selectedItem);
- }
- });
-
- //default selected value to 'unlimited'(live lists) and check both combobox settings here.
- selectedValue = defaultPriorityValue;
- if (storedPortlet != null) {
- //if property exists retrieve it
- if (storedPortlet.getConfiguration().getSimple(ALERT_RANGE_PRIORITY_VALUE) != null) {
- selectedValue = storedPortlet.getConfiguration().getSimple(ALERT_RANGE_PRIORITY_VALUE).getStringValue();
- } else {//insert default value
- storedPortlet.getConfiguration().put(
- new PropertySimple(ALERT_RANGE_PRIORITY_VALUE, defaultPriorityValue));
- }
- }
- //prepopulate the combobox with the previously stored selection
- alertRangePriorityComboBox.setDefaultValue(selectedValue);
- row.addMember(alertRangeLabel);
- DynamicForm wrappedRange = new DynamicForm();
- wrappedRange.setFields(alertRangeLastComboBox);
- row.addMember(wrappedRange);
-
- DynamicForm wrappedPriority = new DynamicForm();
- wrappedPriority.setFields(alertRangePriorityComboBox);
- row.addMember(wrappedPriority);
-
- //horizontal layout
- LocatableHLayout row2 = new LocatableHLayout(extendLocatorId("alert-range-settings-row-2"));
-
- LocatableLabel alertRangeSpanLabel = new LocatableLabel(extendLocatorId("range-span-label"), "<b>"
- + MSG.view_portlet_recentAlerts_config_when() + "<b>");
- //------------- Build second combobox for timeframe for problem resources search.
- final SelectItem alertRangeTimeComboBox = new SelectItem(ALERT_RANGE_TIME_VALUE);
- alertRangeTimeComboBox.setTitle("");
- alertRangeTimeComboBox.setHint("");
- alertRangeTimeComboBox.setType("selection");
- String[] acceptableTimeDisplayValues = { TIME_30_MINS, TIME_HOUR, TIME_12_HRS, TIME_DAY, TIME_WEEK, TIME_MONTH };
- alertRangeTimeComboBox.setValueMap(acceptableTimeDisplayValues);
- alertRangeTimeComboBox.setWidth(100);
- alertRangeTimeComboBox.addChangeHandler(new ChangeHandler() {
- public void onChange(ChangeEvent event) {
- String selectedItem = "" + event.getValue();
- //stuff into the master form for retrieval
- form.setValue(ALERT_RANGE_TIME_VALUE, selectedItem);
- }
- });
-
- //set to default
- selectedValue = defaultTimeValue;
- if (storedPortlet != null) {
- //if property exists retrieve it
- if (storedPortlet.getConfiguration().getSimple(ALERT_RANGE_TIME_VALUE) != null) {
- selectedValue = storedPortlet.getConfiguration().getSimple(ALERT_RANGE_TIME_VALUE).getStringValue();
- } else {//insert default value
- storedPortlet.getConfiguration().put(new PropertySimple(ALERT_RANGE_TIME_VALUE, defaultTimeValue));
- }
- }
- //prepopulate the combobox with the previously stored selection
- alertRangeTimeComboBox.setDefaultValue(selectedValue);
- DynamicForm timeSelectionWrapper = new DynamicForm();
- timeSelectionWrapper.setFields(alertRangeTimeComboBox);
-
- // build resource selection drop down
- //------------- Build second combobox for timeframe for problem resources search.
- final SelectItem alertResourcesComboBox = new SelectItem(ALERT_RANGE_RESOURCES_VALUE);
- alertResourcesComboBox.setTitle(MSG.common_val_for());
- alertResourcesComboBox.setHint("");
- alertResourcesComboBox.setType("selection");
- String[] acceptableResourceDisplayValues = { RESOURCES_ALL, RESOURCES_SELECTED };
- alertResourcesComboBox.setValueMap(acceptableResourceDisplayValues);
- alertResourcesComboBox.setWidth(150);
- alertResourcesComboBox.addChangeHandler(new ChangeHandler() {
- public void onChange(ChangeEvent event) {
- String selectedItem = "" + event.getValue();
- //stuff into the master form for retrieval
- form.setValue(ALERT_RANGE_RESOURCES_VALUE, selectedItem);
- //empty out earlier canvas
- for (Canvas c : containerCanvas.getChildren()) {
- c.destroy();
- }
- if (selectedItem.equals(RESOURCES_SELECTED)) {
- containerCanvas.addChild(resourceSelector.getCanvas());
- } else {
- containerCanvas.addChild(new Canvas());
- }
- }
- });
-
- //set to default
- selectedValue = defaultResourceValue;
- if (storedPortlet != null) {
- //if property exists retrieve it
- if (storedPortlet.getConfiguration().getSimple(ALERT_RANGE_RESOURCES_VALUE) != null) {
- selectedValue = storedPortlet.getConfiguration().getSimple(ALERT_RANGE_RESOURCES_VALUE)
- .getStringValue();
- } else {//insert default value
- storedPortlet.getConfiguration().put(
- new PropertySimple(ALERT_RANGE_RESOURCES_VALUE, defaultResourceValue));
- }
- }
- //prepopulate the combobox with the previously stored selection
- alertResourcesComboBox.setDefaultValue(selectedValue);
- DynamicForm resourceSelectionWrapper = new DynamicForm();
- resourceSelectionWrapper.setFields(alertResourcesComboBox);
-
- alertRangeSpanLabel.setWrap(false);
- alertRangeSpanLabel.setWidth(150);
- row2.addMember(alertRangeSpanLabel);
- row2.addMember(timeSelectionWrapper);
- row2.addMember(resourceSelectionWrapper);
-
- //if portlet config setting exist, then retrieve
- Integer[] alertFilterResourceIds = null;
- alertFilterResourceIds = getDataSource().extractFilterResourceIds(storedPortlet, alertFilterResourceIds);
-
- LocatableHLayout resourceSelectionRegion = new LocatableHLayout(extendLocatorId("selection-canvas"));
- resourceSelector = new AlertResourceSelectorRegion(extendLocatorId("ResourcesWithAlerts"),
- alertFilterResourceIds);
- resourceSelectionRegion.setWidth100();
-
- if (alertFilterResourceIds != null) {
- getDataSource().setAlertFilterResourceId(alertFilterResourceIds);
- resourceSelector.setCurrentlyAssignedIds(alertFilterResourceIds);
- }
-
- //instantiate canvas area to display empty or rich resource selection based on dropdown selection
- containerCanvas = new Canvas();
- String previousAlertFilterChoice = storedPortlet.getConfiguration().getSimple(ALERT_RANGE_RESOURCES_VALUE)
- .getStringValue();
-
- //reload the ResourceSelectionRegion if user has chosen to focus on specific resources with alerts
- if (previousAlertFilterChoice.equals(RESOURCES_SELECTED)) {
- containerCanvas.addChild(resourceSelector.getCanvas());
- } else {// define empty canvas
- containerCanvas.addChild(new Canvas());
- }
-
- //add contain resource selection region.
- resourceSelectionRegion.addMember(containerCanvas);
-
- //finish construction of the layout
- column.addMember(row);
- column.addMember(row2);
- SpacerItem verticalSpace = new SpacerItem();
- verticalSpace.setHeight(20);
- DynamicForm spacerWrapper = new DynamicForm();
- spacerWrapper.setItems(verticalSpace);
- column.addMember(spacerWrapper);
- column.addMember(resourceSelectionRegion);
- form.addChild(column);
-
- //submit handler
- form.addSubmitValuesHandler(new SubmitValuesHandler() {
- @Override
- public void onSubmitValues(SubmitValuesEvent event) {
- //no need to insert validation here as user not allowed to enter values
- parseFormAndPopulateConfiguration(form, storedPortlet, ALERT_RANGE_DISPLAY_AMOUNT_VALUE,
- ALERT_RANGE_PRIORITY_VALUE, ALERT_RANGE_RESOURCES_VALUE, ALERT_RANGE_TIME_VALUE);
-
- //retrieve alert-resource-selection property
- PropertySimple prop = storedPortlet.getConfiguration().getSimple(ALERT_RANGE_RESOURCES_VALUE);
-
- //check to see if "Selected Resources" or "All Resources"
- if (prop != null && RESOURCES_SELECTED.equals(prop.getStringValue())) {
- //retrieve currentlyAssignedIds
- Integer[] valuesToPersist = resourceSelector.getListGridValues();
- resourceSelector.setCurrentlyAssignedIds(valuesToPersist);
-
- //build property list of ids to persist
- PropertyList list = new PropertyList(ALERT_RANGE_RESOURCE_IDS);
- for (int rid : resourceSelector.getCurrentlyAssignedIds()) {
- list.add(new PropertySimple(ALERT_RANGE_RESOURCE_IDS, rid));
- }
- storedPortlet.getConfiguration().put(new PropertyList(ALERT_RANGE_RESOURCE_IDS, list));
- getDataSource().setAlertFilterResourceId(resourceSelector.getCurrentlyAssignedIds());
- }
-
- configure(portletWindow, storedPortlet);
-
- refresh();//reload form with new data selections
- markForRedraw();
- }
- });
-
- return form;
- }
-
- /**Iterates over DynamicForm instance to check for properties passed in and if they have been set
- * to put that property into the DashboardPortlet configuration.
- *
- * @param form Dynamic form storing user selections
- * @param portlet Container for configuration changes
- * @param properties Variable list of keys used to verify or populate properties.
- */
- private void parseFormAndPopulateConfiguration(final DynamicForm form, DashboardPortlet storedPortlet,
- String... properties) {
- if ((form != null) && (storedPortlet != null)) {
- for (String property : properties) {
- if (form.getValue(property) != null) {//if new value supplied
- storedPortlet.getConfiguration().put(new PropertySimple(property, form.getValue(property)));
- }
- }
- }
- }
-
- public AlertPortletDataSource getDataSource() {
- return dataSource;
+ super(locatorId, EntityContext.forSubsystemView());
}
public static final class Factory implements PortletViewFactory {
@@ -565,102 +45,4 @@ public class RecentAlertsPortlet extends AlertHistoryView implements CustomSetti
}
}
- public void startRefreshCycle() {
- refreshTimer = AutoRefreshPortletUtil.startRefreshCycle(this, this, refreshTimer);
- }
-
- @Override
- protected void onDestroy() {
- AutoRefreshPortletUtil.onDestroy(this, refreshTimer);
-
- super.onDestroy();
- }
-
- public boolean isRefreshing() {
- return false;
- }
-
- @Override
- protected void setupTableInteractions(boolean hasWriteAccess) {
- // The portlet is a "subsystem" view. Meaning the alerts displayed can be from any accessible group for
- // the user. This means the user can have varying permissions on the underlying groups and/or resources,
- // which makes button enablement tricky. So, for the portlet don't even show the buttons unless the user
- // is inventory manager. Other users will just have to navigate to the alert in question in order to
- // manipulate it.
-
- //determine if the user is inventory manager and if so render the buttons
- Set<Permission> permissions = this.portletWindow.getGlobalPermissions();
- if ((null != permissions) && permissions.contains(Permission.MANAGE_INVENTORY)) {
- super.setupTableInteractions(true);
- }
- }
-
- protected CellFormatter getDetailsLinkColumnCellFormatter() {
- return new CellFormatter() {
- public String format(Object value, ListGridRecord record, int i, int i1) {
- Integer recordId = getId(record);
- Integer resourceId = record.getAttributeAsInt("resourceId");
- String detailsUrl = LinkManager.getSubsystemAlertHistoryLink(resourceId, recordId);
- return SeleniumUtility.getLocatableHref(detailsUrl, value.toString(), null);
- }
- };
- }
-
- @Override
- protected void configureTable() {
- // TODO Auto-generated method stub
- super.configureTable();
-
- setListGridDoubleClickHandler(new DoubleClickHandler() {
- @Override
- public void onDoubleClick(DoubleClickEvent event) {
- ListGrid listGrid = (ListGrid) event.getSource();
- ListGridRecord[] selectedRows = listGrid.getSelection();
- if (selectedRows != null && selectedRows.length == 1) {
- Integer recordId = getId(selectedRows[0]);
- Integer resourceId = selectedRows[0].getAttributeAsInt("resourceId");
- CoreGUI.goToView(LinkManager.getSubsystemAlertHistoryLink(resourceId, recordId));
- }
- }
- });
- }
-
-}
-
-/** Bundles a ResourceSelector instance with labelling in Canvas for display.
- * Also modifies the AssignedGrid to listen for AvailbleGrid completion and act accordingly.
- */
-class AlertResourceSelectorRegion extends LocatableVLayout {
- public AlertResourceSelectorRegion(String locatorId, Integer[] assigned) {
- super(locatorId);
- this.currentlyAssignedIds = assigned;
- }
-
- private PortletAlertSelector selector = null;
-
- private Integer[] currentlyAssignedIds;
-
- public Integer[] getCurrentlyAssignedIds() {
- return currentlyAssignedIds;
- }
-
- public Integer[] getListGridValues() {
- Integer[] listGridValues = new Integer[0];
- if (null != selector) {
- listGridValues = selector.getAssignedListGridValues();
- }
- return listGridValues;
- }
-
- public Canvas getCanvas() {
- if (selector == null) {
- selector = new PortletAlertSelector(extendLocatorId("AlertSelector"), this.currentlyAssignedIds,
- ResourceType.ANY_PLATFORM_TYPE, false);
- }
- return selector;
- }
-
- public void setCurrentlyAssignedIds(Integer[] currentlyAssignedIds) {
- this.currentlyAssignedIds = currentlyAssignedIds;
- }
}
\ No newline at end of file
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/resource/ResourceAlertsPortlet.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/resource/ResourceAlertsPortlet.java
index ff3a9939..c43068f 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/resource/ResourceAlertsPortlet.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/resource/ResourceAlertsPortlet.java
@@ -19,26 +19,17 @@
package org.rhq.enterprise.gui.coregui.client.dashboard.portlets.resource;
import com.google.gwt.user.client.History;
-import com.smartgwt.client.widgets.Canvas;
-import org.rhq.core.domain.configuration.PropertySimple;
-import org.rhq.core.domain.dashboard.DashboardPortlet;
-import org.rhq.core.domain.resource.ResourceType;
-import org.rhq.enterprise.gui.coregui.client.CoreGUI;
-import org.rhq.enterprise.gui.coregui.client.Messages;
-import org.rhq.enterprise.gui.coregui.client.alert.AlertPortletConfigurationDataSource;
+import org.rhq.core.domain.common.EntityContext;
import org.rhq.enterprise.gui.coregui.client.dashboard.Portlet;
import org.rhq.enterprise.gui.coregui.client.dashboard.PortletViewFactory;
-import org.rhq.enterprise.gui.coregui.client.dashboard.PortletWindow;
-import org.rhq.enterprise.gui.coregui.client.dashboard.portlets.PortletConfigurationEditorComponent;
-import org.rhq.enterprise.gui.coregui.client.dashboard.portlets.groups.GroupAlertsPortlet;
-import org.rhq.enterprise.gui.coregui.client.dashboard.portlets.recent.alerts.PortletAlertSelector;
-import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableVLayout;
+import org.rhq.enterprise.gui.coregui.client.dashboard.portlets.recent.alerts.AbstractRecentAlertsPortlet;
/**
+ * @author Jay Shaughnessy
* @author Simeon Pinder
*/
-public class ResourceAlertsPortlet extends GroupAlertsPortlet {
+public class ResourceAlertsPortlet extends AbstractRecentAlertsPortlet {
// A non-displayed, persisted identifier for the portlet
public static final String KEY = "ResourceAlerts";
@@ -47,138 +38,34 @@ public class ResourceAlertsPortlet extends GroupAlertsPortlet {
private int resourceId;
- public ResourceAlertsPortlet(String locatorId) {
- super(locatorId);
+ public ResourceAlertsPortlet(String locatorId, int resourceId) {
- //override the shared datasource
- //figure out which page we're loading
- String currentPage = History.getToken();
- String[] elements = currentPage.split("/");
- this.resourceId = Integer.valueOf(elements[1]);
- }
-
- /**Defines layout for the portlet page.
- */
- protected void initializeUi() {
- //initalize the datasource
- Integer[] resourceIds = new Integer[1];
- resourceIds[0] = this.resourceId;
- this.dataSource = new AlertPortletConfigurationDataSource(storedPortlet, portletConfig, null, resourceIds);
- setDataSource(this.dataSource);
-
- setShowHeader(false);
- setShowFooter(true);
- setShowFooterRefresh(false); //disable footer refresh
- setShowFilterForm(false); //disable filter form for portlet
-
- getListGrid().setEmptyMessage(MSG.view_portlet_results_empty());
- }
+ super(locatorId, EntityContext.forResource(resourceId));
- @Override
- protected void onInit() {
- super.onInit();
- initializeUi();
+ this.resourceId = resourceId;
}
- /** Responsible for initialization and lazy configuration of the portlet values
- */
- public void configure(PortletWindow portletWindow, DashboardPortlet storedPortlet) {
- //populate portlet configuration details
- if (null == this.portletWindow && null != portletWindow) {
- this.portletWindow = portletWindow;
- }
-
- if ((null == storedPortlet) || (null == storedPortlet.getConfiguration())) {
- return;
- }
- this.storedPortlet = storedPortlet;
- portletConfig = storedPortlet.getConfiguration();
-
- if (!portletConfigInitialized) {
- Integer[] resourceIds = new Integer[1];
- resourceIds[0] = this.resourceId;
- this.dataSource = new AlertPortletConfigurationDataSource(storedPortlet, portletConfig, null, resourceIds);
- setDataSource(this.dataSource);
- portletConfigInitialized = true;
- }
-
- //lazy init any elements not yet configured.
- for (String key : PortletConfigurationEditorComponent.CONFIG_PROPERTY_INITIALIZATION.keySet()) {
- if (portletConfig.getSimple(key) == null) {
- portletConfig.put(new PropertySimple(key,
- PortletConfigurationEditorComponent.CONFIG_PROPERTY_INITIALIZATION.get(key)));
- }
- }
-
- //resource ids to be conditionally included in the query
- Integer[] filterResourceIds = null;
- filterResourceIds = getDataSource().extractFilterResourceIds(storedPortlet, filterResourceIds);
- //no defaults
-
- if (filterResourceIds != null) {
- getDataSource().setAlertFilterResourceId(filterResourceIds);
- }
-
- // //conditionally display the selected resources ui
- // if (containerCanvas != null) {
- // //empty out earlier canvas
- // for (Canvas c : containerCanvas.getChildren()) {
- // c.destroy();
- // }
- // if ((resourceSelector != null) && getDataSource().getAlertResourcesToUse().equals(RESOURCES_SELECTED)) {
- // containerCanvas.addChild(resourceSelector.getCanvas());
- // } else {
- // containerCanvas.addChild(new Canvas());
- // }
- // }
-
+ public int getResourceId() {
+ return resourceId;
}
public static final class Factory implements PortletViewFactory {
public static PortletViewFactory INSTANCE = new Factory();
+ /* (non-Javadoc)
+ * TODO: This factory ASSUMES the user is currently navigated to a resource detail view, and generates a portlet
+ * for that resource. It will fail in other scenarios. This mechanism should be improved such that the
+ * factory method can take an EntityContext explicitly indicating, in this case, the resource.
+ * @see org.rhq.enterprise.gui.coregui.client.dashboard.PortletViewFactory#getInstance(java.lang.String)
+ */
public final Portlet getInstance(String locatorId) {
- return new ResourceAlertsPortlet(locatorId);
- }
- }
-}
-
-/** Bundles a ResourceSelector instance with labeling in Canvas for display.
- * Also modifies the AssignedGrid to listen for AvailbleGrid completion and act accordingly.
- */
-class AlertResourceSelectorRegion extends LocatableVLayout {
- public AlertResourceSelectorRegion(String locatorId, Integer[] assigned) {
- super(locatorId);
- this.currentlyAssignedIds = assigned;
- }
-
- private static final Messages MSG = CoreGUI.getMessages();
- private PortletAlertSelector selector = null;
+ String currentPage = History.getToken();
+ String[] elements = currentPage.split("/");
+ int resourceId = Integer.valueOf(elements[1]);
- private Integer[] currentlyAssignedIds;
-
- public Integer[] getCurrentlyAssignedIds() {
- return currentlyAssignedIds;
- }
-
- public Integer[] getListGridValues() {
- Integer[] listGridValues = new Integer[0];
- if (null != selector) {
- listGridValues = selector.getAssignedListGridValues();
+ return new ResourceAlertsPortlet(locatorId, resourceId);
}
- return listGridValues;
}
- public Canvas getCanvas() {
- if (selector == null) {
- selector = new PortletAlertSelector(extendLocatorId("AlertSelector"), this.currentlyAssignedIds,
- ResourceType.ANY_PLATFORM_TYPE, false);
- }
- return selector;
- }
-
- public void setCurrentlyAssignedIds(Integer[] currentlyAssignedIds) {
- this.currentlyAssignedIds = currentlyAssignedIds;
- }
}
\ No newline at end of file
commit ba0c90686a14b3dd6058bcf707de2d66360fc285
Author: Heiko W. Rupp <hwr(a)redhat.com>
Date: Wed Mar 30 13:00:39 2011 +0200
Fix an exception, add an alias for 'set res', rename 'src' to 'rcs', implement 'pcs'.
diff --git a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/StandaloneContainer.java b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/StandaloneContainer.java
index 4e4e103..74ccf48 100644
--- a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/StandaloneContainer.java
+++ b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/StandaloneContainer.java
@@ -42,7 +42,6 @@ import org.rhq.core.domain.configuration.PropertySimple;
import org.rhq.core.domain.configuration.definition.ConfigurationDefinition;
import org.rhq.core.domain.configuration.definition.PropertyDefinition;
import org.rhq.core.domain.discovery.AvailabilityReport;
-import org.rhq.core.clientapi.server.discovery.InventoryReport;
import org.rhq.core.domain.measurement.Availability;
import org.rhq.core.domain.measurement.DataType;
import org.rhq.core.domain.measurement.MeasurementData;
@@ -56,8 +55,6 @@ import org.rhq.core.pc.inventory.InventoryManager;
import org.rhq.core.pc.inventory.ResourceContainer;
import org.rhq.core.pc.measurement.MeasurementManager;
import org.rhq.core.pc.operation.OperationContextImpl;
-import org.rhq.core.pc.operation.OperationManager;
-import org.rhq.core.pc.operation.OperationServicesAdapter;
import org.rhq.core.pc.plugin.FileSystemPluginFinder;
import org.rhq.core.pluginapi.operation.OperationContext;
import org.rhq.core.pluginapi.operation.OperationServices;
@@ -369,7 +366,10 @@ public class StandaloneContainer {
showResourceConfig();
break;
case SR_CONFIG:
- setResourceConfig(tokens);
+ setResourcePluginConfig(tokens, false);
+ break;
+ case SP_CONFIG:
+ setResourcePluginConfig(tokens,true);
break;
}
@@ -431,7 +431,7 @@ public class StandaloneContainer {
}
- private void setResourceConfig(String[] tokens) {
+ private void setResourcePluginConfig(String[] tokens,boolean pluginConfig) {
if (resourceId == 0) {
System.err.println("No resource set");
return;
@@ -450,7 +450,10 @@ public class StandaloneContainer {
ConfigurationManager cm = pc.getConfigurationManager();
- cm.updateResourceConfiguration(request);
+ if (pluginConfig) {
+ pc.getInventoryManager().getResourceContainer(resourceId).getResource().setPluginConfiguration(config);
+ } else
+ cm.updateResourceConfiguration(request);
@@ -534,7 +537,12 @@ public class StandaloneContainer {
* @param tokens tokenized command line tokens[0] is the command itself
*/
private void children(String[] tokens) {
- int id = Integer.valueOf(tokens[1]);
+
+ int id;
+ if (tokens.length>1)
+ id = Integer.valueOf(tokens[1]);
+ else
+ id = resourceId;
ResourceContainer resourceContainer = inventoryManager.getResourceContainer(id);
if (resourceContainer != null) {
Resource r = resourceContainer.getResource();
@@ -623,7 +631,7 @@ public class StandaloneContainer {
if (comm.startsWith("plu")) {
//pluginName = arg;
- } else if (comm.startsWith("r")) {
+ } else if (comm.startsWith("r") || comm.equals("id")) {
try {
if (arg.equals("$r")) {
resourceId = dollarR;
@@ -654,7 +662,6 @@ public class StandaloneContainer {
private void discover(String[] tokens) {
Set<Resource> existing = getResources();
- InventoryReport report;
String what = tokens[1];
long t1 = System.currentTimeMillis();
if (what.startsWith("s"))
@@ -755,10 +762,10 @@ public class StandaloneContainer {
/**
* Creates a configuration object from the passed String. The string must consist
- * of individual key-value pairs, that are spearated by || keys and values are separated by
+ * of individual key-value pairs, that are separated by || keys and values are separated by
* =. Only simple properties are supported for the configuration.
* @param input The input string, may be null
- * @return a Configuration object or null if input was null
+ * @return a Configuration object or null if input was null or if one of the pairs was invalid.
*/
private Configuration createConfigurationFromString(String input) {
if (input == null)
@@ -768,6 +775,10 @@ public class StandaloneContainer {
String[] pairs = input.split("\\|\\|");
for (String pair : pairs) {
String[] kv = pair.split("=");
+ if (kv.length %2 ==1 ) {
+ System.err.println("Token " + pair + " is invalid as it contains no '='");
+ return null;
+ }
PropertySimple ps = new PropertySimple(kv[0], kv[1]);
config.put(ps);
}
@@ -805,7 +816,7 @@ public class StandaloneContainer {
ASCAN("as", "", 0, "Triggers an availability scan"), //
AVAIL("a", " ( id )", 0,
"Shows an availability report. If id is given, only shows availability for resource with id id"), //
- CHILDREN("chi", "id", 1, "Shows the direct children of the resource with the passed id"), //
+ CHILDREN("chi", "[id]", 0, "Shows the direct children of the resource with the passed id, or if no id passed of the current resource"), //
DISCOVER("disc", " s | i | all", 1, "Triggers a discovery scan for (s)erver, serv(i)ce or all resources"), //
// EVENT("e", "", 0, "Pull events"), // TODO needs to be defined
FIND("find", "r | t | rt <name>", 2,
@@ -817,12 +828,13 @@ public class StandaloneContainer {
QUIT("quit", "", 0, "Terminates the application"), //
RESOURCES("res", "", 0, "Shows the discovered resources"), //
SET("set", "'resource' N", 2,
- "Sets the resource id to work with. N can be a number or '$r' as result of last find resource call"), //
+ "Sets the resource id to work with. N can be a number or '$r' as result of last find resource call. 'id' is an alias for 'res'"), //
STDIN("stdin","",0, "Stop reading the batch file and wait for commands on stdin"), //
WAIT("w", "milliseconds", 1, "Waits the given amount of time"),
P_CONFIG("pc", "", 0, "Shows the plugin configuration of the current resource."),
R_CONFIG("rc", "", 0, "Shows the resource configuration of the current resource."),
- SR_CONFIG("src", "", 0, "[parameters] set resource config ")
+ SR_CONFIG("rcs", "", 0, "[parameters] set resource config "),
+ SP_CONFIG("pcs", "", 0, "[parameters] set plugin config ")
;
private String abbrev;
commit 8337b34c8a757821de0c22f4c30f9f32b55265f2
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Wed Mar 30 00:57:02 2011 -0400
BZ 691978 - fix tag cloud view - you can now delete tags. prettied up the UI as well
diff --git a/modules/core/domain/src/main/java/org/rhq/core/domain/tagging/compsite/TagReportComposite.java b/modules/core/domain/src/main/java/org/rhq/core/domain/tagging/compsite/TagReportComposite.java
index 57084e2..d5bcceb 100644
--- a/modules/core/domain/src/main/java/org/rhq/core/domain/tagging/compsite/TagReportComposite.java
+++ b/modules/core/domain/src/main/java/org/rhq/core/domain/tagging/compsite/TagReportComposite.java
@@ -31,7 +31,6 @@ public class TagReportComposite extends Tag {
private static final long serialVersionUID = 1L;
- private Tag tag;
private long total;
private long resourceCount;
private long resourceGroupCount;
@@ -46,8 +45,8 @@ public class TagReportComposite extends Tag {
public TagReportComposite(int id, String namespace, String semantic, String name, long total, long resourceCount,
long resourceGroupCount, long bundleCount, long bundleVersionCount, long bundleDeploymentCount,
long bundleDestinationCount) {
- this.tag = new Tag(namespace, semantic, name);
- this.tag.setId(id);
+ super(namespace, semantic, name);
+ setId(id);
this.total = total;
this.resourceCount = resourceCount;
this.resourceGroupCount = resourceGroupCount;
@@ -58,7 +57,7 @@ public class TagReportComposite extends Tag {
}
public Tag getTag() {
- return tag;
+ return this;
}
public long getTotal() {
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/LinkManager.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/LinkManager.java
index 61bfede..2a6beeb 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/LinkManager.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/LinkManager.java
@@ -383,7 +383,11 @@ public class LinkManager {
}
public static String getTagLink(String tag) {
- return "#Reports/Subsystems/Tags/" + tag;
+ if (tag == null) {
+ return "#Reports/Subsystems/Tags";
+ } else {
+ return "#Reports/Subsystems/Tags/" + tag;
+ }
}
public static String getBundleLink(int bundleId) {
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/report/tag/TagCloudView.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/report/tag/TagCloudView.java
index 61164f3..b2ce6bc 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/report/tag/TagCloudView.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/report/tag/TagCloudView.java
@@ -24,26 +24,42 @@ package org.rhq.enterprise.gui.coregui.client.report.tag;
import java.util.Collections;
import java.util.Comparator;
+import java.util.HashSet;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.smartgwt.client.widgets.HTMLFlow;
+import com.smartgwt.client.widgets.IButton;
+import com.smartgwt.client.widgets.events.ClickEvent;
+import com.smartgwt.client.widgets.events.ClickHandler;
import org.rhq.core.domain.criteria.TagCriteria;
+import org.rhq.core.domain.tagging.Tag;
import org.rhq.core.domain.tagging.compsite.TagReportComposite;
+import org.rhq.core.domain.util.PageControl;
import org.rhq.core.domain.util.PageList;
import org.rhq.enterprise.gui.coregui.client.CoreGUI;
import org.rhq.enterprise.gui.coregui.client.LinkManager;
import org.rhq.enterprise.gui.coregui.client.gwt.GWTServiceLookup;
+import org.rhq.enterprise.gui.coregui.client.util.message.Message;
+import org.rhq.enterprise.gui.coregui.client.util.message.Message.Severity;
+import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableIButton;
import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableVLayout;
/**
+ * Shows the tags in a large HTML block, where the most used tags are shown in bigger fonts.
+ *
* @author Greg Hinkle
+ * @author John Mazzitelli
*/
public class TagCloudView extends LocatableVLayout {
- private PageList<TagReportComposite> tags;
+ private static final String REMOVE_ICON = "[skin]/images/actions/remove.png";
+ private static final int MIN_FONTSIZE = 8;
+ private static final int MAX_FONTSIZE = 22;
+ private PageList<TagReportComposite> tags;
private String selectedTag;
+ private IButton deleteButton;
public TagCloudView(String locatorId) {
super(locatorId);
@@ -52,10 +68,16 @@ public class TagCloudView extends LocatableVLayout {
@Override
protected void onDraw() {
super.onDraw();
+ refresh();
+ }
+ private void refresh() {
removeMembers(getMembers());
- GWTServiceLookup.getTagService().findTagReportCompositesByCriteria(new TagCriteria(),
+ TagCriteria tagCriteria = new TagCriteria();
+ tagCriteria.setPageControl(PageControl.getUnlimitedInstance());
+
+ GWTServiceLookup.getTagService().findTagReportCompositesByCriteria(tagCriteria,
new AsyncCallback<PageList<TagReportComposite>>() {
public void onFailure(Throwable caught) {
CoreGUI.getErrorHandler().handleError(MSG.view_tagCloud_error_fetchFailure(), caught);
@@ -68,36 +90,34 @@ public class TagCloudView extends LocatableVLayout {
}
private void drawTags(PageList<TagReportComposite> tags) {
-
if (tags == null) {
- return; // Tags still loading
+ return; // tags are still loading
}
this.tags = tags;
+ // determine the maximum number of times any single tag is used
long max = 0;
- long total = 0;
for (TagReportComposite tag : tags) {
if (tag.getTotal() > max) {
max = tag.getTotal();
}
- total += tag.getTotal();
}
+ // sort the tags so they appear alphabetically
Collections.sort(tags, new Comparator<TagReportComposite>() {
public int compare(TagReportComposite o1, TagReportComposite o2) {
return o1.getTag().toString().compareTo(o2.getTag().toString());
}
});
+ // build the HTML block that contains all the tags with variable font sizes
+ // where the font size represents the relative number of times the tag is used
StringBuilder buf = new StringBuilder();
-
- int minFont = 8;
- int maxFont = 22;
-
for (TagReportComposite tag : tags) {
- int font = (int) ((((double) tag.getTotal()) / (double) max) * (maxFont - minFont)) + minFont;
+ int font = (int) ((((double) tag.getTotal()) / (double) max) * (MAX_FONTSIZE - MIN_FONTSIZE))
+ + MIN_FONTSIZE;
buf.append("<a href=\"").append(LinkManager.getTagLink(tag.getTag().toString())).append(
"\" style=\"font-size: ").append(font).append("pt; margin: 8px;\"");
@@ -111,16 +131,93 @@ public class TagCloudView extends LocatableVLayout {
buf.append(">").append(tag.getTag()).append("</a> ");
}
-
HTMLFlow flow = new HTMLFlow(buf.toString());
-
addMember(flow);
}
+ public String getSelectedTag() {
+ return this.selectedTag;
+ }
+
+ /**
+ * Determines which, if any, tag is currently selected.
+ *
+ * @param selectedTag the full tag name, or <code>null</code> if nothing is selected
+ */
public void setSelectedTag(String selectedTag) {
this.selectedTag = selectedTag;
+ TagReportComposite selected = getSelectedTagReportComposite();
+ getDeleteButton().setDisabled(selected == null || selected.getTotal() > 0); // don't be able to delete non-existent tag or tag that is used
removeMembers(getMembers());
- drawTags(tags);
+ drawTags(this.tags);
}
+ /**
+ * This view can provide a delete button that, when clicked, will delete the currently
+ * selected tag. This view doesn't put this delete button anywhere, the caller can place
+ * this button where ever it deems appropriate.
+ *
+ * @return a delete button component that can be placed as a member of a canvas
+ */
+ public IButton getDeleteButton() {
+ if (this.deleteButton == null) {
+ final IButton button = new DeleteButton(extendLocatorId("deleteButton"));
+ button.setIcon(REMOVE_ICON);
+ button.setIconWidth(16);
+ button.setIconHeight(16);
+ button.setTitle(MSG.view_tagCloud_deleteTag());
+ button.setAutoFit(true);
+ button.addClickHandler(new ClickHandler() {
+ @Override
+ public void onClick(ClickEvent event) {
+ final TagReportComposite selected = getSelectedTagReportComposite();
+ if (selected != null) {
+ HashSet<Tag> doomedTag = new HashSet<Tag>(1);
+ doomedTag.add(selected.getTag());
+ GWTServiceLookup.getTagService().removeTags(doomedTag, new AsyncCallback<Void>() {
+ @Override
+ public void onSuccess(Void result) {
+ tags.remove(selected);
+ CoreGUI.goToView(LinkManager.getTagLink(null));
+ CoreGUI.getMessageCenter().notify(
+ new Message(MSG.view_tagCloud_deleteTagSuccess(selected.getTag().toString()),
+ Severity.Info));
+ }
+
+ @Override
+ public void onFailure(Throwable caught) {
+ CoreGUI.getErrorHandler().handleError(
+ MSG.view_tagCloud_deleteTagFailure(selected.getTag().toString()), caught);
+ }
+ });
+ }
+ }
+ });
+ this.deleteButton = button;
+ }
+ return this.deleteButton;
+ }
+
+ private TagReportComposite getSelectedTagReportComposite() {
+ if (selectedTag != null && tags != null) {
+ for (TagReportComposite tag : tags) {
+ if (tag.getTag().toString().equals(selectedTag)) {
+ return tag;
+ }
+ }
+ }
+ return null;
+ }
+
+ class DeleteButton extends LocatableIButton {
+ public DeleteButton(String locatorId) {
+ super(locatorId);
+ }
+
+ @Override
+ protected void onDestroy() {
+ super.onDestroy();
+ deleteButton = null;
+ }
+ }
}
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/report/tag/TaggedView.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/report/tag/TaggedView.java
index 465b37c..36e2ff8 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/report/tag/TaggedView.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/report/tag/TaggedView.java
@@ -26,9 +26,13 @@ import java.util.ArrayList;
import com.smartgwt.client.data.Criteria;
import com.smartgwt.client.widgets.tab.Tab;
+import com.smartgwt.client.widgets.tab.events.TabSelectedEvent;
+import com.smartgwt.client.widgets.tab.events.TabSelectedHandler;
+import org.rhq.core.domain.resource.ResourceCategory;
import org.rhq.core.domain.tagging.Tag;
import org.rhq.enterprise.gui.coregui.client.BookmarkableView;
+import org.rhq.enterprise.gui.coregui.client.ImageManager;
import org.rhq.enterprise.gui.coregui.client.ViewPath;
import org.rhq.enterprise.gui.coregui.client.bundle.deployment.BundleDeploymentListView;
import org.rhq.enterprise.gui.coregui.client.bundle.destination.BundleDestinationListView;
@@ -43,7 +47,11 @@ import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableTabSet;
import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableVLayout;
/**
+ * The main tag cloud view which will show the actual tag cloud with a tabbed view
+ * underneath containing all the tables of data for the selected tag.
+ *
* @author Greg Hinkle
+ * @author John Mazzitelli
*/
public class TaggedView extends LocatableVLayout implements BookmarkableView {
@@ -52,6 +60,7 @@ public class TaggedView extends LocatableVLayout implements BookmarkableView {
private TagCloudView tagCloudView;
private LocatableTabSet container;
private ArrayList<Table> viewsWithTags = new ArrayList<Table>();
+ private int selectedTabNum = 0;
public TaggedView(String locatorId) {
super(locatorId);
@@ -73,40 +82,48 @@ public class TaggedView extends LocatableVLayout implements BookmarkableView {
addMember(tagCloudView);
}
- @Override
- protected void onDraw() {
- super.onDraw();
- }
-
private void viewTag(String tagString) {
+ // if we are switching tags, remove all our tables - we need to recreate them with new criteria
+ if (tagString != null && !tagString.equals(tagCloudView.getSelectedTag())) {
+ destroyTagTables();
+ }
+
tagCloudView.setSelectedTag(tagString);
- Tag tag = new Tag(tagString);
+ if (container == null) {
- Criteria criteria = new Criteria();
- criteria.addCriteria("tagNamespace", tag.getNamespace());
- criteria.addCriteria("tagSemantic", tag.getSemantic());
- criteria.addCriteria("tagName", tag.getName());
+ Tag tag = new Tag(tagString);
- if (container == null) {
+ Criteria criteria = new Criteria();
+ criteria.addCriteria("tagNamespace", tag.getNamespace());
+ criteria.addCriteria("tagSemantic", tag.getSemantic());
+ criteria.addCriteria("tagName", tag.getName());
container = new LocatableTabSet(extendLocatorId("tags"));
container.setWidth100();
container.setHeight100();
- addMember(container);
+ container.setTabBarControls(tagCloudView.getDeleteButton());
+ container.addTabSelectedHandler(new TabSelectedHandler() {
+ public void onTabSelected(TabSelectedEvent event) {
+ selectedTabNum = event.getTabNum();
+ }
+ });
+ container.setSelectedTab(selectedTabNum); // this is so we keep the same tab the user selected between tag selections
Tab tab;
BundlesListView bundlesView = new BundlesListView(getLocatorId(), criteria, null);
viewsWithTags.add(bundlesView);
tab = new LocatableTab(extendLocatorId("bundleList"), MSG.view_bundle_bundles());
+ tab.setIcon(ImageManager.getBundleIcon());
tab.setPane(bundlesView);
container.addTab(tab);
BundleVersionListView bundleVersionListView = new BundleVersionListView(getLocatorId(), criteria);
viewsWithTags.add(bundleVersionListView);
tab = new LocatableTab(extendLocatorId("bundleVersionList"), MSG.view_bundle_bundleVersions());
+ tab.setIcon("subsystems/bundle/BundleVersion_16.png");
tab.setPane(bundleVersionListView);
container.addTab(tab);
@@ -115,6 +132,7 @@ public class TaggedView extends LocatableVLayout implements BookmarkableView {
false);
viewsWithTags.add(bundleDeploymentListView);
tab = new LocatableTab(extendLocatorId("bundleDeploymentsList"), MSG.view_bundle_bundleDeployments());
+ tab.setIcon("subsystems/bundle/BundleDeployment_16.png");
tab.setPane(bundleDeploymentListView);
container.addTab(tab);
@@ -122,6 +140,7 @@ public class TaggedView extends LocatableVLayout implements BookmarkableView {
criteria);
viewsWithTags.add(bundleDestinationListView);
tab = new LocatableTab(extendLocatorId("bundleDestinationsList"), MSG.view_bundle_bundleDestinations());
+ tab.setIcon("subsystems/bundle/BundleDestination_16.png");
tab.setPane(bundleDestinationListView);
container.addTab(tab);
@@ -129,12 +148,15 @@ public class TaggedView extends LocatableVLayout implements BookmarkableView {
.view_taggedResources_title());
viewsWithTags.add(resourceView);
tab = new LocatableTab(extendLocatorId("resourceList"), MSG.view_taggedResources_title());
+ tab.setIcon(ImageManager.getResourceIcon(ResourceCategory.SERVICE));
tab.setPane(resourceView);
container.addTab(tab);
for (Table t : viewsWithTags) {
t.setShowFooter(false);
}
+
+ addMember(container);
}
for (Table t : viewsWithTags) {
@@ -142,10 +164,22 @@ public class TaggedView extends LocatableVLayout implements BookmarkableView {
}
}
+ private void destroyTagTables() {
+ if (this.container != null) {
+ this.viewsWithTags.clear();
+ removeMember(this.container);
+ this.container.destroy();
+ this.container = null;
+ }
+ }
+
public void renderView(ViewPath viewPath) {
if (!viewPath.isEnd()) {
String tagString = viewPath.getCurrent().getPath();
viewTag(tagString);
+ } else {
+ destroyTagTables();
+ tagCloudView.setSelectedTag(null);
}
}
}
diff --git a/modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages.properties b/modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages.properties
index fd6ac7e..a965934 100644
--- a/modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages.properties
+++ b/modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages.properties
@@ -2021,10 +2021,13 @@ view_measurementOob_title = Suspect Metrics
view_tagCloud_title = Tag Cloud
view_tagCloud_error_fetchFailure = Failed to load tags.
view_tagCloud_error_tagUsedCount = Tag used {0} times.
+view_tagCloud_deleteTag = Delete Tag
+view_tagCloud_deleteTagFailure = Failed to delete the tag [{0}]
+view_tagCloud_deleteTagSuccess = You successfully deleted the tag [{0}]
view_reports_inventorySummary_failFetch = Failed to get inventory summary
-view_taggedResources_title = Tagged Resources
+view_taggedResources_title = Resources
view_reports_alertDefinitions_parentHover = Click to go to the parent alert definition
view_reports_alertDefinitions_resTypeLoadError = Cannot get the template resource type - unable to view the alert template.
commit 1385a03d7363cda58358d929349f67e3cf24dd7c
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Tue Mar 29 15:43:05 2011 -0400
- remove refresh button
- add the recent alert count number next to the alert flag
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/Footer.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/Footer.java
index 5a9d3fc..88e7a9b 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/Footer.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/Footer.java
@@ -87,7 +87,9 @@ public class Footer extends LocatableHLayout {
addMember(getMessageCenterButton());
- addMember(getRefreshButton());
+ // people don't like the refresh and CoreGUI.refresh() isn't refreshing everything I want
+ // if we ever want to reintroduce the refresh button to manually call CoreGUI.refresh(), just uncomment this line
+ // addMember(getRefreshButton());
addMember(createHSpacer(0));
@@ -195,13 +197,15 @@ public class Footer extends LocatableHLayout {
private void changeIcon(int alertCount) {
if (alertCount == 0) {
setPrompt(MSG.view_core_noRecentAlerts());
- setContents(imgHTML("subsystems/alert/Alerts_16.png", 16, 16));
+ setContents(imgHTML("subsystems/alert/Alerts_16.png", 16, 16)
+ + "<span style=\"display:inline-block; vertical-align:middle\">0</span>");
} else {
setPrompt(MSG.view_core_recentAlerts(String.valueOf(alertCount)));
String link = '#' + ReportTopView.VIEW_ID.getName() + "/" + ReportTopView.SECTION_SUBSYSTEMS_VIEW_ID
+ "/" + AlertHistoryView.SUBSYSTEM_VIEW_ID;
setContents("<a href=\"" + link + "\">" + imgHTML(ImageManager.getAlertIcon(AlertPriority.HIGH))
- + "</a>");
+ + "<span style=\"display:inline-block; vertical-align:middle\">" + String.valueOf(alertCount)
+ + "</span></a>");
}
}
diff --git a/modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages.properties b/modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages.properties
index 695bd9d..fd6ac7e 100644
--- a/modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages.properties
+++ b/modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages.properties
@@ -2057,7 +2057,7 @@ view_aboutBox_version = Version:
view_core_error_1 = New Alerts lookup failed
#view_core_loggedInAs = Logged in as {0}
view_core_loggedOut = Logged out
-view_core_recentAlerts = There are [{0}] recent alerts - click the icon to go to the recent alerts report
+view_core_recentAlerts = There are [{0}] recent alerts - click to go to the recent alerts report
view_core_noRecentAlerts = There are no recent alerts to report
view_core_uncaught = Globally uncaught exception
12 years, 8 months
[rhq] Branch 'as7plugin' - 3 commits - modules/plugins
by Heiko W. Rupp
modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/ASConnection.java | 19 +
modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/BaseComponent.java | 4
modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/BaseProcessDiscovery.java | 57 ++++
modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/DomainComponent.java | 132 ++++++++++
modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/json/Operation.java | 7
modules/plugins/jboss-as-7/src/main/resources/META-INF/rhq-plugin.xml | 30 ++
6 files changed, 240 insertions(+), 9 deletions(-)
New commits:
commit 7122b59f83eab6785068f46224f4d601373f26ef
Author: Heiko W. Rupp <hwr(a)redhat.com>
Date: Thu Mar 31 12:24:46 2011 +0200
Start support for adding and removal of server instances.
diff --git a/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/ASConnection.java b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/ASConnection.java
index 470722d..bd0b458 100644
--- a/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/ASConnection.java
+++ b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/ASConnection.java
@@ -210,11 +210,19 @@ public class ASConnection {
br.close();
}
}
- String outcome = builder.toString();
+ String outcome;
+ JsonNode operationResult=null;
+ if (builder!=null) {
+ outcome= builder.toString();
+ operationResult = mapper.readTree(outcome);
+ }
+ else {
+ outcome="- no response from server -";
+ }
System.out.println("==> " + outcome);
- JsonNode operationResult = mapper.readTree(outcome);
return operationResult;
+
} catch (IOException e) {
e.printStackTrace(); // TODO: Customise this generated block
}
diff --git a/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/DomainComponent.java b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/DomainComponent.java
index 460aebf..b53dd74 100644
--- a/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/DomainComponent.java
+++ b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/DomainComponent.java
@@ -20,7 +20,9 @@ package org.rhq.modules.plugins.jbossas7;
import java.util.ArrayList;
import java.util.Collections;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import org.codehaus.jackson.JsonNode;
@@ -87,12 +89,27 @@ public class DomainComponent extends BaseComponent implements OperationFacet{
} else if (what.equals("server")) {
List<PROPERTY_VALUE> address = new ArrayList<PROPERTY_VALUE>();
- String host = conf.getSimpleValue("domainHost","local");
-
- address.add(new PROPERTY_VALUE("host",host));
- address.add(new PROPERTY_VALUE("server-config",myServerName));
+ if (context.getResourceType().getName().equals("JBossAS-Managed")) {
+ String host = conf.getSimpleValue("domainHost","local");
+ address.add(new PROPERTY_VALUE("host",host));
+ address.add(new PROPERTY_VALUE("server-config",myServerName));
+ operation = new Operation(op,address);
+ }
+ else if (context.getResourceType().getName().equals("Host")) {
+ address.addAll(pathToAddress(getPath()));
+ String serverName = parameters.getSimpleValue("name",null);
+ address.add(new PROPERTY_VALUE("server-config",serverName));
+ Map<String,String> props = new HashMap<String, String>();
+ String serverGroup = parameters.getSimpleValue("group",null);
+ props.put("name",serverName);
+ props.put("group",serverGroup);
+// boolean autoStart = parameters.getSimple("auto-start").getBooleanValue();
+// props.put("auto-start",String.valueOf(autoStart));
+ // TODO put more properties in
+
+ operation = new Operation(op,address,props);
+ }
- operation = new Operation(op,address);
}
OperationResult operationResult = new OperationResult();
diff --git a/modules/plugins/jboss-as-7/src/main/resources/META-INF/rhq-plugin.xml b/modules/plugins/jboss-as-7/src/main/resources/META-INF/rhq-plugin.xml
index 9994339..e77a2ca 100644
--- a/modules/plugins/jboss-as-7/src/main/resources/META-INF/rhq-plugin.xml
+++ b/modules/plugins/jboss-as-7/src/main/resources/META-INF/rhq-plugin.xml
@@ -120,7 +120,6 @@
</parameters>
</operation>
-
<server name="Profile"
description="One profile in a domain"
discovery="SubsystemDiscovery"
@@ -147,12 +146,31 @@
<server name="Host"
description="Host involved in this domain"
discovery="SubsystemDiscovery"
- class="BaseComponent"
+ class="DomainComponent"
>
<plugin-configuration>
<c:simple-property name="path" default="/host/*" readOnly="true"/>
</plugin-configuration>
+ <operation name="server:add" displayName="Create server" description="Add a new server to this host.">
+ <parameters>
+ <c:simple-property name="name" description="Name of this new server" required="true"/>
+ <c:simple-property name="group" displayName="Server Group" description="Server group to put this sever in" default="" required="false"/>
+ <c:simple-property name="auto-start" displayName="Autostart" description="Should this server start at boot?" type="boolean" default="false" required="false"/>
+ </parameters>
+ <results>
+ <c:simple-property name="result" description="Outcome of the create server operation"/>
+ </results>
+ </operation>
+ <operation name="server:remove" displayName="Delete server" description="Deletes a server on this host.">
+ <parameters>
+ <c:simple-property name="name" description="Name of this new server" required="true"/>
+ </parameters>
+ <results>
+ <c:simple-property name="result" description="Outcome of the delete server operation"/>
+ </results>
+ </operation>
+
<resource-configuration>
<c:list-property name="server-config" />
</resource-configuration>
@@ -210,9 +228,10 @@
<process-scan name="ManagedAS" query="process|basename|match=^java.*,arg|org.jboss.as.server|match=.*"/>
- <operation name="server:start" description="Start this server instance."/>
- <operation name="server:stop" description="Stop this server instance."/>
- <operation name="server:restart" description="Restart this server instance."/>
+ <operation name="server:start" description="Start this server instance." displayName="Start"/>
+ <operation name="server:stop" description="Stop this server instance." displayName="Stop"/>
+ <operation name="server:restart" description="Restart this server instance." displayName="Restart"/>
+
</server>
commit f2aa9b3dfbe8d6c2cc7b8239a753fe1f7023142a
Author: Heiko W. Rupp <hwr(a)redhat.com>
Date: Thu Mar 31 08:30:04 2011 +0200
Get availability for a managed server from the domain.
diff --git a/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/DomainComponent.java b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/DomainComponent.java
index bfed04a..460aebf 100644
--- a/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/DomainComponent.java
+++ b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/DomainComponent.java
@@ -25,6 +25,7 @@ import java.util.List;
import org.codehaus.jackson.JsonNode;
import org.rhq.core.domain.configuration.Configuration;
+import org.rhq.core.domain.measurement.AvailabilityType;
import org.rhq.core.pluginapi.operation.OperationFacet;
import org.rhq.core.pluginapi.operation.OperationResult;
import org.rhq.modules.plugins.jbossas7.json.Operation;
@@ -38,6 +39,29 @@ import org.rhq.modules.plugins.jbossas7.json.PROPERTY_VALUE;
public class DomainComponent extends BaseComponent implements OperationFacet{
@Override
+ public AvailabilityType getAvailability() {
+
+ if (context.getResourceType().getName().equals("JBossAS-Managed")) {
+ List<PROPERTY_VALUE> address = new ArrayList<PROPERTY_VALUE>(2);
+ String host = conf.getSimpleValue("domainHost","local");
+ address.add(new PROPERTY_VALUE("host",host));
+ address.add(new PROPERTY_VALUE("server-config",myServerName));
+ Operation getStatus = new Operation("read-attribute",address,"name","status");
+ JsonNode result = connection.execute(getStatus);
+ if (connection.isErrorReply(result))
+ return AvailabilityType.DOWN;
+
+ String msg = connection.getSuccessDescription(result);
+ if (msg.contains("STARTED"))
+ return AvailabilityType.UP;
+ else
+ return AvailabilityType.DOWN;
+ }
+
+ return super.getAvailability(); // TODO: Customise this generated block
+ }
+
+ @Override
public OperationResult invokeOperation(String name,
Configuration parameters) throws InterruptedException, Exception {
commit 397d5539988b798e49d2dc6e3f896c125274e0bc
Author: Heiko W. Rupp <hwr(a)redhat.com>
Date: Wed Mar 30 21:42:40 2011 +0200
Support start/stop/restart of servers.
diff --git a/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/ASConnection.java b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/ASConnection.java
index 401887b..470722d 100644
--- a/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/ASConnection.java
+++ b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/ASConnection.java
@@ -199,7 +199,6 @@ public class ASConnection {
in.close();
}
else {
- System.out.println(conn.getResponseCode());
InputStream errorStream = conn.getErrorStream();
if (errorStream!=null) {
BufferedReader br = new BufferedReader(new InputStreamReader(errorStream));
@@ -254,6 +253,12 @@ public class ASConnection {
if (node==null)
node = jsonNode.findValue("domain-failure-description"); // TODO JBAS-9182
return node.getValueAsText();
+ }
+ public String getSuccessDescription(JsonNode jsonNode) {
+ if (jsonNode==null)
+ return "No message found";
+ JsonNode node = jsonNode.findValue("result");
+ return node.getValueAsText();
}
}
diff --git a/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/BaseComponent.java b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/BaseComponent.java
index 3b025f3..5dbd0b3 100644
--- a/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/BaseComponent.java
+++ b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/BaseComponent.java
@@ -291,7 +291,7 @@ public class BaseComponent implements ResourceComponent, MeasurementFacet, Confi
return ret;
}
- private String getResultingPath() {
+ protected String getResultingPath() {
ResourceComponent parentResourceComponent = context.getParentResourceComponent();
String parentPath =null;
String myPath;
@@ -328,7 +328,7 @@ public class BaseComponent implements ResourceComponent, MeasurementFacet, Confi
}
- private List<PROPERTY_VALUE> pathToAddress(String path) {
+ protected List<PROPERTY_VALUE> pathToAddress(String path) {
if (path.endsWith("/"))
path = path.substring(0,path.length()-1);
diff --git a/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/BaseProcessDiscovery.java b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/BaseProcessDiscovery.java
index c38e297..5ea4bd7 100644
--- a/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/BaseProcessDiscovery.java
+++ b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/BaseProcessDiscovery.java
@@ -1,12 +1,19 @@
package org.rhq.modules.plugins.jbossas7;
import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStream;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.mc4j.ems.connection.support.metadata.LocalVMTypeDescriptor;
+import org.w3c.dom.Document;
import org.rhq.core.domain.configuration.Configuration;
import org.rhq.core.domain.configuration.PropertyList;
@@ -17,6 +24,7 @@ import org.rhq.core.pluginapi.inventory.DiscoveredResourceDetails;
import org.rhq.core.pluginapi.inventory.ProcessScanResult;
import org.rhq.core.pluginapi.inventory.ResourceDiscoveryComponent;
import org.rhq.core.pluginapi.inventory.ResourceDiscoveryContext;
+import org.rhq.core.system.ProcessInfo;
import org.rhq.plugins.jmx.JMXDiscoveryComponent;
@@ -29,6 +37,7 @@ public class BaseProcessDiscovery implements ResourceDiscoveryComponent
static final String DJBOSS_SERVER_BASE_DIR = "-Djboss.server.base.dir=";
static final String DORG_JBOSS_BOOT_LOG_FILE = "-Dorg.jboss.boot.log.file=";
+ static final String DLOGGING_CONFIGURATION = "-Dlogging.configuration=";
private final Log log = LogFactory.getLog(this.getClass());
/**
@@ -69,6 +78,10 @@ public class BaseProcessDiscovery implements ResourceDiscoveryComponent
tmp = tmp.substring( i + 8);
tmp = tmp.substring(0,tmp.indexOf("/"));
serverNameFull = tmp;
+
+ String host = findHost(psr.getProcessInfo(),true);
+ config.put(new PropertySimple("domainHost",host));
+
}
serverName = serverNameFull.substring(serverNameFull.lastIndexOf("/")+1);
if (serverName.isEmpty())
@@ -114,7 +127,49 @@ public class BaseProcessDiscovery implements ResourceDiscoveryComponent
}
- String getBaseDirFromCommandLine(String[] commandLine) {
+ private String findHost(ProcessInfo processInfo,boolean isDomain) {
+ String hostXmlFile = getHostXmlFileLocation(processInfo, isDomain);
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ String hostName = null;
+ try {
+ DocumentBuilder builder = factory.newDocumentBuilder();
+ InputStream is = new FileInputStream(hostXmlFile);
+ Document document = builder.parse(is); // TODO keep this around
+ hostName = document.getDocumentElement().getAttribute("name");
+ is.close();
+ } catch (Exception e) {
+ e.printStackTrace(); // TODO: Customise this generated block
+ }
+ if (hostName==null)
+ hostName="local"; // Fallback to the installation default
+ return hostName;
+ }
+
+ /**
+ * Get the location of the host definition file (host.xml in domain mode, standalone.xml
+ * in standalone mode.
+ * @param processInfo ProcessInfo structure containing the ENV variables
+ * @param isDomain Are we looking for host.xml (=isDomain) or not
+ * @return The path to the definition file.
+ */
+ private String getHostXmlFileLocation(ProcessInfo processInfo, boolean isDomain) {
+
+ String home = processInfo.getEnvironmentVariable("jboss.home.dir");
+ StringBuilder builder = new StringBuilder(home);
+ if (isDomain)
+ builder.append("/domain");
+ else
+ builder.append("/standalone");
+ builder.append("/configuration");
+ if (isDomain)
+ builder.append("/host.xml");
+ else
+ builder.append("/standalone.xml");
+ return builder.toString();
+
+ }
+
+ String getBaseDirFromCommandLine(String[] commandLine) {
for (String line: commandLine) {
if (line.startsWith(DJBOSS_SERVER_BASE_DIR))
return line.substring(DJBOSS_SERVER_BASE_DIR.length());
diff --git a/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/DomainComponent.java b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/DomainComponent.java
new file mode 100644
index 0000000..bfed04a
--- /dev/null
+++ b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/DomainComponent.java
@@ -0,0 +1,91 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2011 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+package org.rhq.modules.plugins.jbossas7;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.codehaus.jackson.JsonNode;
+
+import org.rhq.core.domain.configuration.Configuration;
+import org.rhq.core.pluginapi.operation.OperationFacet;
+import org.rhq.core.pluginapi.operation.OperationResult;
+import org.rhq.modules.plugins.jbossas7.json.Operation;
+import org.rhq.modules.plugins.jbossas7.json.PROPERTY_VALUE;
+
+/**
+ * Common stuff for the Domain
+ * @author Heiko W. Rupp
+ */
+@SuppressWarnings("unused")
+public class DomainComponent extends BaseComponent implements OperationFacet{
+
+ @Override
+ public OperationResult invokeOperation(String name,
+ Configuration parameters) throws InterruptedException, Exception {
+
+ if (!name.contains(":")) {
+ OperationResult badName = new OperationResult("Operation name did not contain a ':'");
+ badName.setErrorMessage("Operation name did not contain a ':'");
+ return badName;
+ }
+
+ int colonPos = name.indexOf(':');
+ String what = name.substring(0, colonPos);
+ String op = name.substring(colonPos+1);
+ Operation operation=null;
+
+ if (what.equals("server-group")) {
+ String groupName = parameters.getSimpleValue("name",null);
+ String profile = parameters.getSimpleValue("profile","default");
+
+ List<PROPERTY_VALUE> address = new ArrayList<PROPERTY_VALUE>(1);
+ address.add(new PROPERTY_VALUE("server-group",groupName));
+
+ operation = new Operation(op,address,"profile",profile);
+ } else if (what.equals("server")) {
+ List<PROPERTY_VALUE> address = new ArrayList<PROPERTY_VALUE>();
+
+ String host = conf.getSimpleValue("domainHost","local");
+
+ address.add(new PROPERTY_VALUE("host",host));
+ address.add(new PROPERTY_VALUE("server-config",myServerName));
+
+ operation = new Operation(op,address);
+ }
+
+ OperationResult operationResult = new OperationResult();
+ if (operation!=null) {
+ JsonNode result = connection.execute(operation);
+
+ if (connection.isErrorReply(result)) {
+ operationResult.setErrorMessage(connection.getFailureDescription(result));
+ }
+ else {
+ operationResult.setSimpleResult(connection.getSuccessDescription(result));
+ }
+ }
+ else {
+ operationResult.setErrorMessage("No valid operation was given");
+ }
+ // TODO throw an exception if the operation failed?
+ return operationResult;
+ }
+}
diff --git a/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/json/Operation.java b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/json/Operation.java
index 898f176..92abbae 100644
--- a/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/json/Operation.java
+++ b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/json/Operation.java
@@ -64,6 +64,13 @@ public class Operation {
}
+ public Operation(String operation, List<PROPERTY_VALUE> address) {
+ this.operation = operation;
+ this.address = address;
+ additionalProperties = Collections.emptyMap();
+
+ }
+
public Operation() {
// needed for Jackson
}
diff --git a/modules/plugins/jboss-as-7/src/main/resources/META-INF/rhq-plugin.xml b/modules/plugins/jboss-as-7/src/main/resources/META-INF/rhq-plugin.xml
index 6af7de6..9994339 100644
--- a/modules/plugins/jboss-as-7/src/main/resources/META-INF/rhq-plugin.xml
+++ b/modules/plugins/jboss-as-7/src/main/resources/META-INF/rhq-plugin.xml
@@ -199,7 +199,7 @@
<server name="JBossAS-Managed"
discovery="BaseProcessDiscovery"
- class="BaseComponent"
+ class="DomainComponent"
>
<plugin-configuration>
<c:simple-property name="hostname" default="localhost" required="true"/>
@@ -210,6 +210,11 @@
<process-scan name="ManagedAS" query="process|basename|match=^java.*,arg|org.jboss.as.server|match=.*"/>
+ <operation name="server:start" description="Start this server instance."/>
+ <operation name="server:stop" description="Stop this server instance."/>
+ <operation name="server:restart" description="Restart this server instance."/>
+
+
</server>
12 years, 8 months
[rhq] 4 commits - modules/core
by Heiko W. Rupp
modules/core/plugin-container/src/main/java/org/rhq/core/pc/StandaloneContainer.java | 239 +---------
modules/core/plugin-container/src/main/java/org/rhq/core/pc/standaloneContainer/Command.java | 99 ++++
modules/core/plugin-container/src/main/java/org/rhq/core/pc/standaloneContainer/History.java | 147 ++++++
3 files changed, 287 insertions(+), 198 deletions(-)
New commits:
commit 080e1d77247f9fe6a730a3db01152554072fb7b3
Merge: 22cb9ff 8573843
Author: Heiko W. Rupp <hwr(a)redhat.com>
Date: Thu Mar 31 12:56:13 2011 +0200
Merge branch 'master' of ssh://git.fedorahosted.org/git/rhq/rhq
commit 22cb9ff2d4a08c96591f5e6a4670e38505cd6162
Author: Heiko W. Rupp <hwr(a)redhat.com>
Date: Thu Mar 31 12:53:14 2011 +0200
Be more relaxed when parsing the input.
diff --git a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/StandaloneContainer.java b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/StandaloneContainer.java
index 25130ec..fe4ee1c 100644
--- a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/StandaloneContainer.java
+++ b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/StandaloneContainer.java
@@ -199,6 +199,9 @@ public class StandaloneContainer {
if (tokens[0].startsWith("#"))
return false;
+ if (tokens[0].isEmpty())
+ return false;
+
Command com = Command.get(tokens[0]);
if (com == null) {
System.err.println("Command " + tokens[0] + " is unknown");
@@ -486,7 +489,7 @@ public class StandaloneContainer {
String pattern = tokens[2];
pattern = pattern.replaceAll("\\*", "\\.\\*");
- if (tokens[1].equals("r")) {
+ if (tokens[1].equals("r") || tokens[1].startsWith("res")) {
Set<Resource> resources = getResources();
for (Resource res : resources) {
if (res.getName().matches(pattern)) {
commit 3630e07e77391007034d71692a401a1fe8cd2e3c
Author: Heiko W. Rupp <hwr(a)redhat.com>
Date: Thu Mar 31 12:45:42 2011 +0200
Factor out Command enum and History handling.
Print command when input was a script.
diff --git a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/StandaloneContainer.java b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/StandaloneContainer.java
index 74ccf48..25130ec 100644
--- a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/StandaloneContainer.java
+++ b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/StandaloneContainer.java
@@ -1,6 +1,6 @@
/*
* RHQ Management Platform
- * Copyright (C) 2005-2009 Red Hat, Inc.
+ * Copyright (C) 2005-2011 Red Hat, Inc.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
@@ -22,10 +22,7 @@ import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
-import java.io.FileWriter;
-import java.io.IOException;
import java.io.InputStreamReader;
-import java.io.Writer;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.HashMap;
@@ -56,6 +53,8 @@ import org.rhq.core.pc.inventory.ResourceContainer;
import org.rhq.core.pc.measurement.MeasurementManager;
import org.rhq.core.pc.operation.OperationContextImpl;
import org.rhq.core.pc.plugin.FileSystemPluginFinder;
+import org.rhq.core.pc.standaloneContainer.Command;
+import org.rhq.core.pc.standaloneContainer.History;
import org.rhq.core.pluginapi.operation.OperationContext;
import org.rhq.core.pluginapi.operation.OperationServices;
import org.rhq.core.pluginapi.operation.OperationServicesResult;
@@ -80,29 +79,25 @@ public class StandaloneContainer {
InventoryManager inventoryManager;
/** Global operation counter */
Integer opId = 0;
- /** Holder for the command history */
- List<String> history = new ArrayList<String>(10);
/** Map of resource plugin configurations */
Map<Integer, Configuration> resConfigMap = new HashMap<Integer, Configuration>();
/** variable set by find() and which can be used in set() */
int dollarR = 0;
-
- private static final String HISTORY_HELP = "!! : repeat the last action\n" + //
- "!? : show the history of commands issued\n" + //
- "!h : show this help\n" + //
- "!nn : repeat history item with number nn\n" + //
- "!w fileName : write history to file with name fileName\n" + //
- "!dnn : delete history item with number nn";
+ /** Do we read from stdin ? */
+ static boolean isStdin;
public static void main(String[] argv) {
StandaloneContainer sc = new StandaloneContainer();
BufferedReader br = null;
- if (argv.length == 0)
+ if (argv.length == 0) {
br = new BufferedReader(new InputStreamReader(System.in));
+ isStdin = true;
+ }
else {
try {
br = new BufferedReader(new InputStreamReader(new FileInputStream(argv[0])));
+ isStdin=false;
} catch (FileNotFoundException fnfe) {
System.err.println("File " + argv[0] + " not found");
System.exit(1);
@@ -150,6 +145,8 @@ public class StandaloneContainer {
System.out.println("\nReady.");
+ History history = new History();
+
// Run the main loop
while (!shouldQuit) {
try {
@@ -158,13 +155,16 @@ public class StandaloneContainer {
if (answer == null) {
break;
}
+ if (!isStdin)
+ System.out.println(answer);
if (answer.equalsIgnoreCase(Command.STDIN.toString())) {
br = new BufferedReader(new InputStreamReader(System.in));
+ isStdin=true;
}
// Check for history commands
- answer = handleHistory(answer);
+ answer = history.handleHistory(answer);
// If we have a 'real' command, dispatch it
if (!answer.startsWith("!")) {
@@ -184,104 +184,6 @@ public class StandaloneContainer {
}
- /**
- * Handle processing of the command history. This gives some csh like commands
- * and records the commands given. Nice side effect is the possibility to write the
- * history to disk and to use this later as input so that testing can be scripted.
- * Commands are:
- * <ul>
- * <li>!! : repeat the last action</li>
- * <li>!? : show the history</li>
- * <li>!h : show history help</li>
- * <li>!<i>nnn</i> : repeat history item with number <i>nnn</i></li>
- * <li>!w <i>file</i> : write the history to the file <i>file</i></li>
- * <li>!d<i>nnn</i> : delete the history item with number <i>nnn</i>
- * </ul>
- * @param answer the input given on the command line
- * @return a command or '!' if no command substitution from the history was possible.
- */
- private String handleHistory(String answer) {
-
- // Normal command - just return it
- if (!answer.startsWith("!")) {
- history.add(answer);
- return answer;
- }
-
- // History commands
- if (answer.startsWith("!?")) {
- for (int i = 0; i < history.size(); i++)
- System.out.println("[" + i + "]: " + history.get(i));
- } else if (answer.startsWith("!h")) {
- System.out.println(HISTORY_HELP);
- return "!";
- } else if (answer.startsWith("!!")) {
- String text = history.get(history.size() - 1);
- System.out.println(text);
- history.add(text);
- return text;
- } else if (answer.matches("![0-9]+")) {
- String id = answer.substring(1);
- Integer i;
- try {
- i = Integer.valueOf(id);
- } catch (NumberFormatException nfe) {
- System.err.println(id + " is no valid history position");
- return "!";
- }
- if (i > history.size()) {
- System.err.println(i + " is no valid history position");
- return "!";
- } else {
- String text = history.get(i);
- System.out.println(text);
- history.add(text);
- return text;
- }
- } else if (answer.startsWith("!w")) {
- String[] tokens = answer.split(" ");
- if (tokens.length < 2) {
- System.err.println("Not enough parameters. You need to give a file name");
- }
- File file = new File(tokens[1]);
- try {
- file.createNewFile();
- if (file.canWrite()) {
- Writer writer = new FileWriter(file);
- for (String item : history) {
- writer.write(item);
- writer.write("\n");
- }
- writer.flush();
- writer.close();
- } else {
- System.err.println("Can not write to file " + file);
- }
- } catch (IOException ioe) {
- System.err.println("Saving the history to file " + file + " failed: " + ioe.getMessage());
- }
- return "!";
- } else if (answer.matches("!d[0-9]+")) {
- String id = answer.substring(2);
- Integer i;
- try {
- i = Integer.valueOf(id);
- } catch (NumberFormatException nfe) {
- System.err.println(id + " is no valid history position");
- return "!";
- }
- if (i > history.size()) {
- System.err.println(i + " is no valid history position");
- return "!";
- }
- history.remove(i.intValue());
- return "!";
- } else {
- System.err.println(answer + " is no valid history command");
- return "!";
- }
- return "!";
- }
/**
* Dispatches the input to various commands that do the actual work.
@@ -809,78 +711,4 @@ public class StandaloneContainer {
System.out.println(config.getProperties());
}
- /**
- * List of possible commands
- */
- private enum Command {
- ASCAN("as", "", 0, "Triggers an availability scan"), //
- AVAIL("a", " ( id )", 0,
- "Shows an availability report. If id is given, only shows availability for resource with id id"), //
- CHILDREN("chi", "[id]", 0, "Shows the direct children of the resource with the passed id, or if no id passed of the current resource"), //
- DISCOVER("disc", " s | i | all", 1, "Triggers a discovery scan for (s)erver, serv(i)ce or all resources"), //
- // EVENT("e", "", 0, "Pull events"), // TODO needs to be defined
- FIND("find", "r | t | rt <name>", 2,
- "Searches a (r)esource, resource (t)ype or resources of (rt)ype. Use * as wildcard.\n"
- + " Will set $r for the last resource shown."), HELP("h", "", 0, "Shows this help"), //
- INVOKE("i", "operation [params]", 1, "Triggers running an operation. If operation is '-list' it shows available operations"), //
- MEASURE("m", "datatype property+", 1, "Triggers getting metric values. All need to be of the same data type. If datatype is '-list' it shows the defined metrics"), //
- NATIVE("n", "e | d | s", 1, "Enables/disables native system or shows native status"), //
- QUIT("quit", "", 0, "Terminates the application"), //
- RESOURCES("res", "", 0, "Shows the discovered resources"), //
- SET("set", "'resource' N", 2,
- "Sets the resource id to work with. N can be a number or '$r' as result of last find resource call. 'id' is an alias for 'res'"), //
- STDIN("stdin","",0, "Stop reading the batch file and wait for commands on stdin"), //
- WAIT("w", "milliseconds", 1, "Waits the given amount of time"),
- P_CONFIG("pc", "", 0, "Shows the plugin configuration of the current resource."),
- R_CONFIG("rc", "", 0, "Shows the resource configuration of the current resource."),
- SR_CONFIG("rcs", "", 0, "[parameters] set resource config "),
- SP_CONFIG("pcs", "", 0, "[parameters] set plugin config ")
- ;
-
- private String abbrev;
- private String args;
- private String help;
- private int minArgs; // minimum number of args needed
-
- public String getArgs() {
- return args;
- }
-
- public String getHelp() {
- return help;
- }
-
- public int getMinArgs() {
- return minArgs;
- }
-
- /**
- * Construct a new Command
- * @param abbrev Abbreviation for this command
- * @param args Description of expected arguments
- * @param minArgs Minumum number of arguments that need to be present
- * @param help A short description of the command
- */
- private Command(String abbrev, String args, int minArgs, String help) {
- this.abbrev = abbrev;
- this.args = args;
- this.minArgs = minArgs;
- this.help = help;
- }
-
- public String getAbbrev() {
- return abbrev;
- }
-
- public static Command get(String s) {
-
- String upper = s.toUpperCase();
-
- for (Command c : EnumSet.allOf(Command.class)) {
- if (c.name().equals(upper) || c.getAbbrev().equals(s.toLowerCase()))
- return c;
- }
- return null;
- }
- }
}
diff --git a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/standaloneContainer/Command.java b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/standaloneContainer/Command.java
new file mode 100644
index 0000000..aa91e22
--- /dev/null
+++ b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/standaloneContainer/Command.java
@@ -0,0 +1,99 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2011 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+package org.rhq.core.pc.standaloneContainer;
+
+import java.util.EnumSet;
+
+import org.rhq.core.pc.StandaloneContainer;
+
+/**
+ * List of possible commands of the standalone container
+ * @author Heiko W. Rupp
+ */
+public enum Command {
+ ASCAN("as", "", 0, "Triggers an availability scan"), //
+ AVAIL("a", " ( id )", 0,
+ "Shows an availability report. If id is given, only shows availability for resource with id id"), //
+ CHILDREN("chi", "[id]", 0, "Shows the direct children of the resource with the passed id, or if no id passed of the current resource"), //
+ DISCOVER("disc", " s | i | all", 1, "Triggers a discovery scan for (s)erver, serv(i)ce or all resources"), //
+ // EVENT("e", "", 0, "Pull events"), // TODO needs to be defined
+ FIND("find", "r | t | rt <name>", 2,
+ "Searches a (r)esource, resource (t)ype or resources of (rt)ype. Use * as wildcard.\n"
+ + " Will set $r for the last resource shown."), HELP("h", "", 0, "Shows this help"), //
+ INVOKE("i", "operation [params]", 1, "Triggers running an operation. If operation is '-list' it shows available operations"), //
+ MEASURE("m", "datatype property+", 1, "Triggers getting metric values. All need to be of the same data type. If datatype is '-list' it shows the defined metrics"), //
+ NATIVE("n", "e | d | s", 1, "Enables/disables native system or shows native status"), //
+ QUIT("quit", "", 0, "Terminates the application"), //
+ RESOURCES("res", "", 0, "Shows the discovered resources"), //
+ SET("set", "'resource' N", 2,
+ "Sets the resource id to work with. N can be a number or '$r' as result of last find resource call. 'id' is an alias for 'res'"), //
+ STDIN("stdin","",0, "Stop reading the batch file and wait for commands on stdin"), //
+ WAIT("w", "milliseconds", 1, "Waits the given amount of time"),
+ P_CONFIG("pc", "", 0, "Shows the plugin configuration of the current resource."),
+ R_CONFIG("rc", "", 0, "Shows the resource configuration of the current resource."),
+ SR_CONFIG("rcs", "", 0, "[parameters] set resource config "),
+ SP_CONFIG("pcs", "", 0, "[parameters] set plugin config ")
+ ;
+
+ private String abbrev;
+ private String args;
+ private String help;
+ private int minArgs; // minimum number of args needed
+
+ public String getArgs() {
+ return args;
+ }
+
+ public String getHelp() {
+ return help;
+ }
+
+ public int getMinArgs() {
+ return minArgs;
+ }
+
+ /**
+ * Construct a new Command
+ * @param abbrev Abbreviation for this command
+ * @param args Description of expected arguments
+ * @param minArgs Minumum number of arguments that need to be present
+ * @param help A short description of the command
+ */
+ private Command(String abbrev, String args, int minArgs, String help) {
+ this.abbrev = abbrev;
+ this.args = args;
+ this.minArgs = minArgs;
+ this.help = help;
+ }
+
+ public String getAbbrev() {
+ return abbrev;
+ }
+
+ public static Command get(String s) {
+
+ String upper = s.toUpperCase();
+
+ for (Command c : EnumSet.allOf(Command.class)) {
+ if (c.name().equals(upper) || c.getAbbrev().equals(s.toLowerCase()))
+ return c;
+ }
+ return null;
+ }
+}
diff --git a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/standaloneContainer/History.java b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/standaloneContainer/History.java
new file mode 100644
index 0000000..37b5bf1
--- /dev/null
+++ b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/standaloneContainer/History.java
@@ -0,0 +1,147 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2011 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+package org.rhq.core.pc.standaloneContainer;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.Writer;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Handle command line history
+ * @author Heiko W. Rupp
+ */
+public class History {
+
+ private static final String HISTORY_HELP = "!! : repeat the last action\n" + //
+ "!? : show the history of commands issued\n" + //
+ "!h : show this help\n" + //
+ "!nn : repeat history item with number nn\n" + //
+ "!w fileName : write history to file with name fileName\n" + //
+ "!dnn : delete history item with number nn";
+ /** Holder for the command history */
+ List<String> history = new ArrayList<String>(10);
+
+
+ /**
+ * Handle processing of the command history. This gives some csh like commands
+ * and records the commands given. Nice side effect is the possibility to write the
+ * history to disk and to use this later as input so that testing can be scripted.
+ * Commands are:
+ * <ul>
+ * <li>!! : repeat the last action</li>
+ * <li>!? : show the history</li>
+ * <li>!h : show history help</li>
+ * <li>!<i>nnn</i> : repeat history item with number <i>nnn</i></li>
+ * <li>!w <i>file</i> : write the history to the file <i>file</i></li>
+ * <li>!d<i>nnn</i> : delete the history item with number <i>nnn</i>
+ * </ul>
+ * @param answer the input given on the command line
+ * @return a command or '!' if no command substitution from the history was possible.
+ */
+ public String handleHistory(String answer) {
+
+ // Normal command - just return it
+ if (!answer.startsWith("!")) {
+ history.add(answer);
+ return answer;
+ }
+
+ // History commands
+ if (answer.startsWith("!?")) {
+ for (int i = 0; i < history.size(); i++)
+ System.out.println("[" + i + "]: " + history.get(i));
+ } else if (answer.startsWith("!h")) {
+ System.out.println(HISTORY_HELP);
+ return "!";
+ } else if (answer.startsWith("!!")) {
+ String text = history.get(history.size() - 1);
+ System.out.println(text);
+ history.add(text);
+ return text;
+ } else if (answer.matches("![0-9]+")) {
+ String id = answer.substring(1);
+ Integer i;
+ try {
+ i = Integer.valueOf(id);
+ } catch (NumberFormatException nfe) {
+ System.err.println(id + " is no valid history position");
+ return "!";
+ }
+ if (i > history.size()) {
+ System.err.println(i + " is no valid history position");
+ return "!";
+ } else {
+ String text = history.get(i);
+ System.out.println(text);
+ history.add(text);
+ return text;
+ }
+ } else if (answer.startsWith("!w")) {
+ String[] tokens = answer.split(" ");
+ if (tokens.length < 2) {
+ System.err.println("Not enough parameters. You need to give a file name");
+ }
+ File file = new File(tokens[1]);
+ try {
+ file.createNewFile();
+ if (file.canWrite()) {
+ Writer writer = new FileWriter(file);
+ for (String item : history) {
+ writer.write(item);
+ writer.write("\n");
+ }
+ writer.flush();
+ writer.close();
+ } else {
+ System.err.println("Can not write to file " + file);
+ }
+ } catch (IOException ioe) {
+ System.err.println("Saving the history to file " + file + " failed: " + ioe.getMessage());
+ }
+ return "!";
+ } else if (answer.matches("!d[0-9]+")) {
+ String id = answer.substring(2);
+ Integer i;
+ try {
+ i = Integer.valueOf(id);
+ } catch (NumberFormatException nfe) {
+ System.err.println(id + " is no valid history position");
+ return "!";
+ }
+ if (i > history.size()) {
+ System.err.println(i + " is no valid history position");
+ return "!";
+ }
+ history.remove(i.intValue());
+ return "!";
+ } else {
+ System.err.println(answer + " is no valid history command");
+ return "!";
+ }
+ return "!";
+ }
+
+ public int size() {
+ return history.size();
+ }
+
+}
commit ba0c90686a14b3dd6058bcf707de2d66360fc285
Author: Heiko W. Rupp <hwr(a)redhat.com>
Date: Wed Mar 30 13:00:39 2011 +0200
Fix an exception, add an alias for 'set res', rename 'src' to 'rcs', implement 'pcs'.
diff --git a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/StandaloneContainer.java b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/StandaloneContainer.java
index 4e4e103..74ccf48 100644
--- a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/StandaloneContainer.java
+++ b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/StandaloneContainer.java
@@ -42,7 +42,6 @@ import org.rhq.core.domain.configuration.PropertySimple;
import org.rhq.core.domain.configuration.definition.ConfigurationDefinition;
import org.rhq.core.domain.configuration.definition.PropertyDefinition;
import org.rhq.core.domain.discovery.AvailabilityReport;
-import org.rhq.core.clientapi.server.discovery.InventoryReport;
import org.rhq.core.domain.measurement.Availability;
import org.rhq.core.domain.measurement.DataType;
import org.rhq.core.domain.measurement.MeasurementData;
@@ -56,8 +55,6 @@ import org.rhq.core.pc.inventory.InventoryManager;
import org.rhq.core.pc.inventory.ResourceContainer;
import org.rhq.core.pc.measurement.MeasurementManager;
import org.rhq.core.pc.operation.OperationContextImpl;
-import org.rhq.core.pc.operation.OperationManager;
-import org.rhq.core.pc.operation.OperationServicesAdapter;
import org.rhq.core.pc.plugin.FileSystemPluginFinder;
import org.rhq.core.pluginapi.operation.OperationContext;
import org.rhq.core.pluginapi.operation.OperationServices;
@@ -369,7 +366,10 @@ public class StandaloneContainer {
showResourceConfig();
break;
case SR_CONFIG:
- setResourceConfig(tokens);
+ setResourcePluginConfig(tokens, false);
+ break;
+ case SP_CONFIG:
+ setResourcePluginConfig(tokens,true);
break;
}
@@ -431,7 +431,7 @@ public class StandaloneContainer {
}
- private void setResourceConfig(String[] tokens) {
+ private void setResourcePluginConfig(String[] tokens,boolean pluginConfig) {
if (resourceId == 0) {
System.err.println("No resource set");
return;
@@ -450,7 +450,10 @@ public class StandaloneContainer {
ConfigurationManager cm = pc.getConfigurationManager();
- cm.updateResourceConfiguration(request);
+ if (pluginConfig) {
+ pc.getInventoryManager().getResourceContainer(resourceId).getResource().setPluginConfiguration(config);
+ } else
+ cm.updateResourceConfiguration(request);
@@ -534,7 +537,12 @@ public class StandaloneContainer {
* @param tokens tokenized command line tokens[0] is the command itself
*/
private void children(String[] tokens) {
- int id = Integer.valueOf(tokens[1]);
+
+ int id;
+ if (tokens.length>1)
+ id = Integer.valueOf(tokens[1]);
+ else
+ id = resourceId;
ResourceContainer resourceContainer = inventoryManager.getResourceContainer(id);
if (resourceContainer != null) {
Resource r = resourceContainer.getResource();
@@ -623,7 +631,7 @@ public class StandaloneContainer {
if (comm.startsWith("plu")) {
//pluginName = arg;
- } else if (comm.startsWith("r")) {
+ } else if (comm.startsWith("r") || comm.equals("id")) {
try {
if (arg.equals("$r")) {
resourceId = dollarR;
@@ -654,7 +662,6 @@ public class StandaloneContainer {
private void discover(String[] tokens) {
Set<Resource> existing = getResources();
- InventoryReport report;
String what = tokens[1];
long t1 = System.currentTimeMillis();
if (what.startsWith("s"))
@@ -755,10 +762,10 @@ public class StandaloneContainer {
/**
* Creates a configuration object from the passed String. The string must consist
- * of individual key-value pairs, that are spearated by || keys and values are separated by
+ * of individual key-value pairs, that are separated by || keys and values are separated by
* =. Only simple properties are supported for the configuration.
* @param input The input string, may be null
- * @return a Configuration object or null if input was null
+ * @return a Configuration object or null if input was null or if one of the pairs was invalid.
*/
private Configuration createConfigurationFromString(String input) {
if (input == null)
@@ -768,6 +775,10 @@ public class StandaloneContainer {
String[] pairs = input.split("\\|\\|");
for (String pair : pairs) {
String[] kv = pair.split("=");
+ if (kv.length %2 ==1 ) {
+ System.err.println("Token " + pair + " is invalid as it contains no '='");
+ return null;
+ }
PropertySimple ps = new PropertySimple(kv[0], kv[1]);
config.put(ps);
}
@@ -805,7 +816,7 @@ public class StandaloneContainer {
ASCAN("as", "", 0, "Triggers an availability scan"), //
AVAIL("a", " ( id )", 0,
"Shows an availability report. If id is given, only shows availability for resource with id id"), //
- CHILDREN("chi", "id", 1, "Shows the direct children of the resource with the passed id"), //
+ CHILDREN("chi", "[id]", 0, "Shows the direct children of the resource with the passed id, or if no id passed of the current resource"), //
DISCOVER("disc", " s | i | all", 1, "Triggers a discovery scan for (s)erver, serv(i)ce or all resources"), //
// EVENT("e", "", 0, "Pull events"), // TODO needs to be defined
FIND("find", "r | t | rt <name>", 2,
@@ -817,12 +828,13 @@ public class StandaloneContainer {
QUIT("quit", "", 0, "Terminates the application"), //
RESOURCES("res", "", 0, "Shows the discovered resources"), //
SET("set", "'resource' N", 2,
- "Sets the resource id to work with. N can be a number or '$r' as result of last find resource call"), //
+ "Sets the resource id to work with. N can be a number or '$r' as result of last find resource call. 'id' is an alias for 'res'"), //
STDIN("stdin","",0, "Stop reading the batch file and wait for commands on stdin"), //
WAIT("w", "milliseconds", 1, "Waits the given amount of time"),
P_CONFIG("pc", "", 0, "Shows the plugin configuration of the current resource."),
R_CONFIG("rc", "", 0, "Shows the resource configuration of the current resource."),
- SR_CONFIG("src", "", 0, "[parameters] set resource config ")
+ SR_CONFIG("rcs", "", 0, "[parameters] set resource config "),
+ SP_CONFIG("pcs", "", 0, "[parameters] set plugin config ")
;
private String abbrev;
12 years, 8 months
[rhq] modules/enterprise
by mazz
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/recent/operations/OperationsPortlet.java | 3 +++
1 file changed, 3 insertions(+)
New commits:
commit 8573843d27eac077950e9a54246e651897637f0c
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Wed Mar 30 21:13:34 2011 -0400
format col
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/recent/operations/OperationsPortlet.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/recent/operations/OperationsPortlet.java
index c839109..dad4578 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/recent/operations/OperationsPortlet.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/recent/operations/OperationsPortlet.java
@@ -43,6 +43,7 @@ import org.rhq.core.domain.configuration.definition.PropertyDefinitionSimple;
import org.rhq.core.domain.configuration.definition.PropertySimpleType;
import org.rhq.core.domain.dashboard.DashboardPortlet;
import org.rhq.enterprise.gui.coregui.client.LinkManager;
+import org.rhq.enterprise.gui.coregui.client.components.table.TimestampCellFormatter;
import org.rhq.enterprise.gui.coregui.client.dashboard.AutoRefreshPortlet;
import org.rhq.enterprise.gui.coregui.client.dashboard.AutoRefreshPortletUtil;
import org.rhq.enterprise.gui.coregui.client.dashboard.CustomSettingsPortlet;
@@ -186,6 +187,7 @@ public class OperationsPortlet extends LocatableVLayout implements CustomSetting
ListGridField timeRecent = new ListGridField(RecentOperationsDataSource.Field.TIME.propertyName(),
RecentOperationsDataSource.Field.TIME.title(), WIDTH_RECENT_TIME);
+ TimestampCellFormatter.prepareDateField(timeRecent);
ListGridField statusRecent = new ListGridField(RecentOperationsDataSource.Field.STATUS.propertyName(),
RecentOperationsDataSource.Field.STATUS.title(), WIDTH_RECENT_STATUS);
@@ -215,6 +217,7 @@ public class OperationsPortlet extends LocatableVLayout implements CustomSetting
ListGridField timeNext = new ListGridField(ScheduledOperationsDataSource.Field.TIME.propertyName(),
ScheduledOperationsDataSource.Field.TIME.title(), WIDTH_SCHEDULED_TIME);
+ TimestampCellFormatter.prepareDateField(timeNext);
scheduledOperationsGrid.setFields(resourceNext, ancestryNext, operationNext, timeNext);
}
12 years, 8 months