modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/form/ColorButtonItem.java
| 97 ++++++++++
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/DashboardView.java
| 29 +-
modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages.properties
| 2
3 files changed, 115 insertions(+), 13 deletions(-)
New commits:
commit 4c20f81329d6382ea89f9188f22502aecbf80c8f
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Fri Feb 18 12:28:00 2011 -0500
BZ 636714 - provide a new color picker component - uses less real estate and avoids
picking invalid colors
diff --git
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/form/ColorButtonItem.java
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/form/ColorButtonItem.java
new file mode 100644
index 0000000..14be5b2
--- /dev/null
+++
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/form/ColorButtonItem.java
@@ -0,0 +1,97 @@
+/*
+ * 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.components.form;
+
+import com.smartgwt.client.widgets.form.ColorPicker;
+import com.smartgwt.client.widgets.form.events.ColorSelectedEvent;
+import com.smartgwt.client.widgets.form.events.ColorSelectedHandler;
+import com.smartgwt.client.widgets.form.fields.ButtonItem;
+import com.smartgwt.client.widgets.form.fields.events.ClickEvent;
+import com.smartgwt.client.widgets.form.fields.events.ClickHandler;
+
+import org.rhq.enterprise.gui.coregui.client.CoreGUI;
+
+/**
+ * A button that lets you pick a color. This is different than the smartgwt
+ * ColorPickerItem this is just a button - it doesn't let you enter a text
+ * string for any color. You can only pick a color from the dialog.
+ *
+ * @author John Mazzitelli
+ */
+public class ColorButtonItem extends ButtonItem {
+
+ // can't figure out how to change the color of this icon
+ //private static final String ICON_PATH =
"[SKIN]/DynamicForm/PropSheet_ColorPicker_icon.png";
+
+ private String currentColor;
+ private ColorSelectedHandler colorSelectedHandler;
+
+ public ColorButtonItem() {
+ super();
+ prepareWidget();
+ }
+
+ public ColorButtonItem(String name) {
+ super(name);
+ prepareWidget();
+ }
+
+ public ColorButtonItem(String name, String title) {
+ super(name, title);
+ prepareWidget();
+ }
+
+ public String getCurrentColor() {
+ return this.currentColor;
+ }
+
+ public void setCurrentColor(String color) {
+ this.currentColor = color;
+ }
+
+ public void setColorSelectedHandler(ColorSelectedHandler handler) {
+ this.colorSelectedHandler = handler;
+ }
+
+ protected void prepareWidget() {
+ setPrompt(CoreGUI.getMessages().widget_colorPicker_tooltip());
+
+ addClickHandler(new ClickHandler() {
+ @Override
+ public void onClick(ClickEvent event) {
+ ColorPicker picker = new ColorPicker();
+ picker.setAllowComplexMode(false);
+ if (currentColor != null) {
+ picker.setDefaultColor(currentColor);
+ }
+ picker.addColorSelectedHandler(new ColorSelectedHandler() {
+ @Override
+ public void onColorSelected(ColorSelectedEvent event) {
+ if (colorSelectedHandler != null) {
+ colorSelectedHandler.onColorSelected(event);
+ }
+ currentColor = event.getColor();
+ }
+ });
+ picker.show();
+ }
+ });
+ }
+}
\ No newline at end of file
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 5a59b9d..3520afc 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
@@ -28,15 +28,14 @@ import com.smartgwt.client.types.Overflow;
import com.smartgwt.client.widgets.AnimationCallback;
import com.smartgwt.client.widgets.Canvas;
import com.smartgwt.client.widgets.form.DynamicForm;
+import com.smartgwt.client.widgets.form.events.ColorSelectedEvent;
+import com.smartgwt.client.widgets.form.events.ColorSelectedHandler;
import com.smartgwt.client.widgets.form.fields.ButtonItem;
import com.smartgwt.client.widgets.form.fields.CanvasItem;
-import com.smartgwt.client.widgets.form.fields.ColorPickerItem;
import com.smartgwt.client.widgets.form.fields.StaticTextItem;
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.ChangedEvent;
-import com.smartgwt.client.widgets.form.fields.events.ChangedHandler;
import com.smartgwt.client.widgets.layout.LayoutSpacer;
import com.smartgwt.client.widgets.menu.IMenuButton;
import com.smartgwt.client.widgets.menu.Menu;
@@ -54,6 +53,7 @@ import org.rhq.core.domain.dashboard.DashboardPortlet;
import org.rhq.enterprise.gui.coregui.client.CoreGUI;
import org.rhq.enterprise.gui.coregui.client.ImageManager;
import org.rhq.enterprise.gui.coregui.client.UserSessionManager;
+import org.rhq.enterprise.gui.coregui.client.components.form.ColorButtonItem;
import org.rhq.enterprise.gui.coregui.client.gwt.GWTServiceLookup;
import org.rhq.enterprise.gui.coregui.client.util.MeasurementUtility;
import org.rhq.enterprise.gui.coregui.client.util.message.Message;
@@ -243,18 +243,21 @@ public class DashboardView extends LocatableVLayout {
addCanvas.setStartRow(false);
addCanvas.setEndRow(false);
- ColorPickerItem picker = new ColorPickerItem();
- picker.setTitle(MSG.common_title_background());
- picker.addChangedHandler(new ChangedHandler() {
- public void onChanged(ChangedEvent changedEvent) {
- Object v = changedEvent.getValue();
- com.allen_sauer.gwt.log.client.Log.info("color changed to " +
v);
- setBackgroundColor(String.valueOf(v));
- storedDashboard.getConfiguration().put(new
PropertySimple(Dashboard.CFG_BACKGROUND, String.valueOf(v)));
- save();
+ ColorButtonItem picker = new ColorButtonItem("colorButton",
MSG.common_title_background());
+ picker.setStartRow(false);
+ picker.setEndRow(false);
+
picker.setCurrentColor(storedDashboard.getConfiguration().getSimpleValue(Dashboard.CFG_BACKGROUND,
"white"));
+ picker.setColorSelectedHandler(new ColorSelectedHandler() {
+ @Override
+ public void onColorSelected(ColorSelectedEvent event) {
+ String selectedColor = event.getColor();
+ if (selectedColor != null) {
+ setBackgroundColor(selectedColor);
+ storedDashboard.getConfiguration().put(new
PropertySimple(Dashboard.CFG_BACKGROUND, selectedColor));
+ save();
+ }
}
});
-
picker.setValue(storedDashboard.getConfiguration().getSimpleValue(Dashboard.CFG_BACKGROUND,
"white"));
//refresh interval
LocatableMenu refreshMenu = new
LocatableMenu(editForm.extendLocatorId("AutoRefreshMenu"));
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 04336a8..1ec1ece 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
@@ -310,6 +310,8 @@ widget_typeTree_badTemplateType = Invalid URL. Unknown template type
[{0}]
widget_typeTree_badTypeId = Invalid URL. Bad resource type ID [{0}]
widget_typeTree_loadFail = Failed to load resource types
+# Color Picker
+widget_colorPicker_tooltip = Click to select a new color
#===================== Utils ======================
Show replies by date