Modified:
trunk/gdf-core/src/main/java/gdf/core/client/View.java
trunk/gdf-core/src/main/java/gdf/core/client/action/Action.java
trunk/gdf-core/src/main/java/gdf/core/client/action/ActionItem.java
trunk/gdf-core/src/main/java/gdf/core/client/action/ActionPanelModel.java
trunk/gdf-core/src/main/java/gdf/core/client/panel/PanelController.java
trunk/gdf-gwt/src/main/java/gdf/gwt/client/view/ActionPanelView.java
trunk/gdf-gwt/src/main/java/gdf/gwt/client/view/ActionView.java
trunk/gdf-gwt/src/main/java/gdf/gwt/client/view/LocationPanelView.java
trunk/gdf-gwt/src/main/java/gdf/gwt/client/view/PanelView.java
trunk/gdf-gwt/src/main/java/gdf/gwt/client/widget/SmartPanel.java
trunk/gdf-mygwt/src/main/java/gdf/mygwt/client/view/ActionView.java
trunk/gdf-mygwt/src/main/java/gdf/mygwt/client/view/PanelView.java
trunk/gdf-mygwt/src/main/java/gdf/mygwt/client/view/TreeView.java
trunk/gdf-sample/src/main/java/gdf/sample/client/desk/form/FieldForm.java
trunk/gdf-sample/src/main/java/gdf/sample/public/gdf-sample.css
Log:
- Refactoring on actions for more reuse across ActionPanel, Action,
LocationPanel, etc.
- Work towards restoring the context menus.
Modified: trunk/gdf-core/src/main/java/gdf/core/client/View.java
==============================================================================
--- trunk/gdf-core/src/main/java/gdf/core/client/View.java (original)
+++ trunk/gdf-core/src/main/java/gdf/core/client/View.java Tue Jan 8
07:36:32 2008
@@ -52,7 +52,7 @@
this.widget = widget;
}
- public void closeContextMenu() {
+ public void hideContextMenu() {
}
protected void configure(Widget widget, String cssSuffix) {
Modified: trunk/gdf-core/src/main/java/gdf/core/client/action/Action.java
==============================================================================
--- trunk/gdf-core/src/main/java/gdf/core/client/action/Action.java (original)
+++ trunk/gdf-core/src/main/java/gdf/core/client/action/Action.java Tue
Jan 8 07:36:32 2008
@@ -22,10 +22,10 @@
public class Action extends Component {
public static final int TYPE_AUTO = -1;
- public static final int TYPE_HYPERLINKS = 1;
- public static final int TYPE_BUTTONS = 2;
- public static final int TYPE_ICONS = 3;
- public static final int TYPE_ICONS_TEXT = 4;
+ public static final int TYPE_HYPERLINK = 1;
+ public static final int TYPE_BUTTON = 2;
+ public static final int TYPE_ICON = 3;
+ public static final int TYPE_ICON_TEXT = 4;
public static final int TYPE_MIXED = 5;
public Action() {
Modified: trunk/gdf-core/src/main/java/gdf/core/client/action/ActionItem.java
==============================================================================
--- trunk/gdf-core/src/main/java/gdf/core/client/action/ActionItem.java (original)
+++ trunk/gdf-core/src/main/java/gdf/core/client/action/ActionItem.java
Tue Jan 8 07:36:32 2008
@@ -27,7 +27,7 @@
public static final int COMMAND_RETRIEVE = 2;
private Command command;
- private String iconPath;
+ private String iconLocation;
private int impact;
private int probability;
private String title;
@@ -50,12 +50,26 @@
*/
public ActionItem(String title, String iconPath, Command command) {
this.title = title;
- this.iconPath = iconPath;
+ this.iconLocation = iconPath;
this.command = command;
this.probability = PROBABILITY_HIGH;
this.impact = IMPACT_HIGH;
}
+ public int getType(int defaultType) {
+ int result = defaultType;
+
+ if (defaultType == Action.TYPE_AUTO) {
+ if (getProbability() == ActionItem.PROBABILITY_HIGH) {
+ result = Action.TYPE_BUTTON;
+ } else {
+ result = Action.TYPE_HYPERLINK;
+ }
+ }
+
+ return result;
+ }
+
/**
* Retourne le command.
*
@@ -70,8 +84,8 @@
*
* @return Le image.
*/
- public String getIconPath() {
- return this.iconPath;
+ public String getIconLocation() {
+ return this.iconLocation;
}
/**
@@ -117,8 +131,8 @@
* @param newIcon
* Le image à assigner.
*/
- public void setIconPath(String newIcon) {
- this.iconPath = newIcon;
+ public void setIconLocation(String newIcon) {
+ this.iconLocation = newIcon;
}
/**
Modified: trunk/gdf-core/src/main/java/gdf/core/client/action/ActionPanelModel.java
==============================================================================
---
trunk/gdf-core/src/main/java/gdf/core/client/action/ActionPanelModel.java (original)
+++
trunk/gdf-core/src/main/java/gdf/core/client/action/ActionPanelModel.java
Tue Jan 8 07:36:32 2008
@@ -30,7 +30,7 @@
*/
public ActionPanelModel(Component component) {
super(component);
- this.type = Action.TYPE_HYPERLINKS;
+ this.type = Action.TYPE_HYPERLINK;
setOrientation(Panel.ORIENTATION_HORIZONTAL);
}
Modified: trunk/gdf-core/src/main/java/gdf/core/client/panel/PanelController.java
==============================================================================
---
trunk/gdf-core/src/main/java/gdf/core/client/panel/PanelController.java (original)
+++
trunk/gdf-core/src/main/java/gdf/core/client/panel/PanelController.java
Tue Jan 8 07:36:32 2008
@@ -30,7 +30,7 @@
if (event.getType() == Event.TYPE_ACTION) {
// Close any open popup panel
- getComponent().getView().closeContextMenu();
+ getComponent().getView().hideContextMenu();
// Execute the action
ActionEvent actionEvent = (ActionEvent) event;
Modified: trunk/gdf-gwt/src/main/java/gdf/gwt/client/view/ActionPanelView.java
==============================================================================
---
trunk/gdf-gwt/src/main/java/gdf/gwt/client/view/ActionPanelView.java (original)
+++
trunk/gdf-gwt/src/main/java/gdf/gwt/client/view/ActionPanelView.java
Tue Jan 8 07:36:32 2008
@@ -80,19 +80,19 @@
private Widget createActionWidget(ActionItem actionItem) {
Widget result = null;
- int actionType = ActionView.getAutoType(
- getActionPanelModel().getType(), actionItem);
+ int actionType = actionItem
+ .getType(getActionPanelModel().getType());
switch (actionType) {
- case Action.TYPE_BUTTONS:
+ case Action.TYPE_BUTTON:
result = new Button(actionItem.getTitle(), new ActionClickListener(
getComponent(), actionItem));
// resultWidget.setStyleName(CSS_ROOT + "");
break;
- case Action.TYPE_HYPERLINKS:
+ case Action.TYPE_HYPERLINK:
result = new Label(actionItem.getTitle());
DOM.setStyleAttribute(result.getElement(), "cursor", "pointer");
@@ -124,19 +124,19 @@
}
break;
- case Action.TYPE_ICONS:
+ case Action.TYPE_ICON:
- result = new Image(actionItem.getIconPath());
+ result = new Image(actionItem.getIconLocation());
// resultWidget.setStyleName(CSS_ROOT + "PopupPanelLabel");
((Image) result).addClickListener(new ActionClickListener(
getComponent(), actionItem));
break;
- case Action.TYPE_ICONS_TEXT:
+ case Action.TYPE_ICON_TEXT:
result = new FlexTable();
- Image imageAction = new Image(actionItem.getIconPath());
+ Image imageAction = new Image(actionItem.getIconLocation());
DOM
.setStyleAttribute(imageAction.getElement(), "cursor",
"pointer");
Modified: trunk/gdf-gwt/src/main/java/gdf/gwt/client/view/ActionView.java
==============================================================================
--- trunk/gdf-gwt/src/main/java/gdf/gwt/client/view/ActionView.java (original)
+++ trunk/gdf-gwt/src/main/java/gdf/gwt/client/view/ActionView.java Tue
Jan 8 07:36:32 2008
@@ -44,33 +44,17 @@
return (ActionModel) getComponent().getModel();
}
- public static int getAutoType(int defaultType, ActionItem item) {
- int result = defaultType;
-
- if (defaultType == Action.TYPE_AUTO) {
- if (item.getProbability() == ActionItem.PROBABILITY_HIGH) {
- result = Action.TYPE_BUTTONS;
- } else {
- result = Action.TYPE_HYPERLINKS;
- }
- }
-
- return result;
- }
-
public Widget getWidget() {
Widget result = null;
- int actionType = getAutoType(getActionModel().getType(),
- getActionItem());
- switch (actionType) {
+ switch (getActionItem().getType(getActionModel().getType())) {
- case Action.TYPE_BUTTONS:
+ case Action.TYPE_BUTTON:
result = new Button(getActionItem().getTitle(),
new ActionClickListener(getComponent(), getActionItem()));
break;
- case Action.TYPE_HYPERLINKS:
+ case Action.TYPE_HYPERLINK:
result = new Label(getActionItem().getTitle());
DOM.setStyleAttribute(result.getElement(), "cursor", "pointer");
((Label) result).addClickListener(new ActionClickListener(
Modified: trunk/gdf-gwt/src/main/java/gdf/gwt/client/view/LocationPanelView.java
==============================================================================
---
trunk/gdf-gwt/src/main/java/gdf/gwt/client/view/LocationPanelView.java (original)
+++
trunk/gdf-gwt/src/main/java/gdf/gwt/client/view/LocationPanelView.java
Tue Jan 8 07:36:32 2008
@@ -10,9 +10,9 @@
import gdf.core.client.Component;
import gdf.core.client.View;
+import gdf.core.client.action.Action;
import gdf.core.client.action.ActionItem;
import gdf.core.client.form.LocationPanelModel;
-import gdf.gwt.client.widget.ActionClickListener;
import java.util.Iterator;
@@ -20,9 +20,7 @@
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.HasVerticalAlignment;
import com.google.gwt.user.client.ui.HorizontalPanel;
-import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.Label;
-import com.google.gwt.user.client.ui.PushButton;
import com.google.gwt.user.client.ui.Widget;
/**
@@ -58,7 +56,6 @@
HasVerticalAlignment.ALIGN_MIDDLE);
HorizontalPanel actionsPanel = new HorizontalPanel();
- PushButton actionButton;
// Ajout des icônes d'action
ActionItem actionItem;
@@ -66,14 +63,11 @@
.iterator(); iter.hasNext();) {
actionItem = (ActionItem) iter.next();
- if (actionItem.getIconPath() != null) {
- actionButton = new PushButton(new Image(actionItem
- .getIconPath()));
- actionButton.setStyleName(CSS_ROOT
- + "LocationZone-actionButton");
- actionButton.addClickListener(new ActionClickListener(
- getComponent(), actionItem));
- actionsPanel.add(actionButton);
+ if (actionItem.getIconLocation() != null) {
+ Action action = new Action(actionItem);
+ action.setType(Action.TYPE_ICON);
+ action.start();
+ actionsPanel.add(action.getWidget());
}
}
Modified: trunk/gdf-gwt/src/main/java/gdf/gwt/client/view/PanelView.java
==============================================================================
--- trunk/gdf-gwt/src/main/java/gdf/gwt/client/view/PanelView.java (original)
+++ trunk/gdf-gwt/src/main/java/gdf/gwt/client/view/PanelView.java Tue
Jan 8 07:36:32 2008
@@ -14,6 +14,7 @@
import gdf.core.client.panel.Panel;
import gdf.core.client.panel.PanelModel;
import gdf.gwt.client.Utilities;
+import gdf.gwt.client.widget.SmartPanel;
import com.google.gwt.user.client.ui.CellPanel;
import com.google.gwt.user.client.ui.HorizontalPanel;
@@ -29,20 +30,21 @@
*/
public class PanelView extends View {
- private Widget container;
- private PopupPanel popupPanel;
+ private SmartPanel container;
+ protected Widget contextMenu;
public PanelView(Panel panel) {
super(panel);
- this.popupPanel = null;
+ this.contextMenu = null;
}
- public void closeContextMenu() {
- if (this.popupPanel != null) {
- this.popupPanel.hide();
+ public void hideContextMenu() {
+ if (this.contextMenu != null) {
+ PopupPanel popup = (PopupPanel) this.contextMenu;
+ popup.hide();
}
- this.popupPanel = null;
+ this.contextMenu = null;
}
public Panel getPanel() {
@@ -55,6 +57,7 @@
public final Widget getWidget() {
if (this.container == null) {
+ Widget content = null;
CellPanel panel = null;
if (getPanelModel().getOrientation() ==
Panel.ORIENTATION_HORIZONTAL) {
@@ -64,9 +67,9 @@
}
if (getPanelModel().isScrollable()) {
- this.container = new ScrollPanel(panel);
+ content = new ScrollPanel(panel);
} else {
- this.container = panel;
+ content = panel;
}
Component child;
@@ -82,27 +85,29 @@
}
}
+ // Wrap the content in a smart panel to expose the context menu
+ this.container = new SmartPanel(this, content);
configure(this.container, "Panel");
}
return this.container;
}
- public PopupPanel openPopupPanel() {
- closeContextMenu();
-
+ public void showContextMenu(int mouseX, int mouseY) {
if (getPanelModel().getActionItems().size() > 0) {
ActionPanel actionPanel = new ActionPanel();
actionPanel.getActionItems().addAll(
getPanelModel().getActionItems());
- this.popupPanel = new PopupPanel(true);
- Utilities.disableContextMenu(this.popupPanel.getElement());
- this.popupPanel.setWidget(actionPanel.getContent().getWidget());
- this.popupPanel.setStyleName(CSS_ROOT + "PopupPanel");
- }
+ PopupPanel popup = new PopupPanel(true);
+ Utilities.disableContextMenu(this.contextMenu.getElement());
+ popup.setWidget(actionPanel.getContent().getWidget());
+ popup.setStyleName(CSS_ROOT + "PopupPanel");
+ popup.show();
+ popup.setPopupPosition(mouseX, mouseY);
- return this.popupPanel;
+ this.contextMenu = popup;
+ }
}
}
Modified: trunk/gdf-gwt/src/main/java/gdf/gwt/client/widget/SmartPanel.java
==============================================================================
--- trunk/gdf-gwt/src/main/java/gdf/gwt/client/widget/SmartPanel.java (original)
+++ trunk/gdf-gwt/src/main/java/gdf/gwt/client/widget/SmartPanel.java
Tue Jan 8 07:36:32 2008
@@ -7,7 +7,6 @@
import com.google.gwt.user.client.Event;
import com.google.gwt.user.client.ui.FocusPanel;
import com.google.gwt.user.client.ui.MouseListenerAdapter;
-import com.google.gwt.user.client.ui.PopupPanel;
import com.google.gwt.user.client.ui.Widget;
/**
@@ -40,13 +39,8 @@
if (type == Event.ONMOUSEDOWN) {
if (DOM.eventGetButton(event) == Event.BUTTON_RIGHT) {
DOM.eventCancelBubble(event, true);
- PopupPanel popup = view.openPopupPanel();
-
- if (popup != null) {
- popup.show();
- popup.setPopupPosition(this.mouseX, this.mouseY);
- }
-
+ view.hideContextMenu();
+ view.showContextMenu(mouseX, mouseY);
return;
}
}
Modified: trunk/gdf-mygwt/src/main/java/gdf/mygwt/client/view/ActionView.java
==============================================================================
--- trunk/gdf-mygwt/src/main/java/gdf/mygwt/client/view/ActionView.java (original)
+++ trunk/gdf-mygwt/src/main/java/gdf/mygwt/client/view/ActionView.java
Tue Jan 8 07:36:32 2008
@@ -16,9 +16,9 @@
import gdf.gwt.client.widget.ActionClickListener;
import gdf.mygwt.client.action.ActionSelectionListener;
import net.mygwt.ui.client.widget.Button;
+import net.mygwt.ui.client.widget.IconButton;
import com.google.gwt.user.client.DOM;
-import com.google.gwt.user.client.ui.Hyperlink;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.MouseListener;
import com.google.gwt.user.client.ui.Widget;
@@ -49,70 +49,51 @@
public Widget getWidget() {
Widget result = null;
- int actionType = getActionModel().getType();
+ switch (getActionItem().getType(getActionModel().getType())) {
- if (getActionModel().getType() == Action.TYPE_AUTO) {
+ case Action.TYPE_BUTTON:
+ Button button = new Button(getActionItem().getTitle());
+ button.setIconStyle(getActionItem().getIconLocation());
+ button.addSelectionListener(new ActionSelectionListener(
+ getComponent(), getActionItem()));
+ result = button;
+ break;
+
+ case Action.TYPE_HYPERLINK:
+ result = new Label(getActionItem().getTitle());
+ DOM.setStyleAttribute(result.getElement(), "cursor", "pointer");
+ ((Label) result).addClickListener(new ActionClickListener(
+ getComponent(), getActionItem()));
+ ((Label) result).addMouseListener(new MouseListener() {
- if (getActionItem().getProbability() ==
ActionItem.PROBABILITY_HIGH) {
- // Display a button
- if (getActionItem().getIconPath() != null) {
- // Display a button
-
- Button button = new Button(getActionItem().getTitle());
- button.addSelectionListener(new ActionSelectionListener(
- getComponent(), getActionItem()));
- result = button;
+ public void onMouseDown(Widget arg0, int arg1, int arg2) {
}
- } else {
- // Display an hyperlink
- Hyperlink hyperlink = new Hyperlink(getActionItem().getTitle(),
- getActionItem().getTitle());
- hyperlink.addClickListener(new ActionClickListener(
- getComponent(), getActionItem()));
- result = hyperlink;
- }
- } else {
-
- switch (actionType) {
-
- case Action.TYPE_BUTTONS:
-
- Button button = new Button(getActionItem().getTitle());
- button.addSelectionListener(new ActionSelectionListener(
- getComponent(), getActionItem()));
- result = button;
- break;
-
- case Action.TYPE_HYPERLINKS:
-
- result = new Label(getActionItem().getTitle());
- DOM.setStyleAttribute(result.getElement(), "cursor", "pointer");
- ((Label) result).addClickListener(new ActionClickListener(
- getComponent(), getActionItem()));
- ((Label) result).addMouseListener(new MouseListener() {
-
- public void onMouseDown(Widget arg0, int arg1, int arg2) {
- }
-
- public void onMouseEnter(Widget result) {
- result.addStyleName("wfp-Hyperlink");
- }
-
- public void onMouseLeave(Widget result) {
- result.removeStyleName("wfp-Hyperlink");
- }
-
- public void onMouseMove(Widget arg0, int arg1, int arg2) {
- }
- public void onMouseUp(Widget arg0, int arg1, int arg2) {
- }
+ public void onMouseEnter(Widget result) {
+ result.addStyleName("wfp-Hyperlink");
+ }
+
+ public void onMouseLeave(Widget result) {
+ result.removeStyleName("wfp-Hyperlink");
+ }
+
+ public void onMouseMove(Widget arg0, int arg1, int arg2) {
+ }
+
+ public void onMouseUp(Widget arg0, int arg1, int arg2) {
+ }
- });
+ });
- break;
- }
+ break;
+ case Action.TYPE_ICON:
+ IconButton iconButton = new IconButton(getActionItem()
+ .getIconLocation());
+ iconButton.addSelectionListener(new ActionSelectionListener(
+ getComponent(), getActionItem()));
+ result = iconButton;
+ break;
}
configure(result, "Action");
Modified: trunk/gdf-mygwt/src/main/java/gdf/mygwt/client/view/PanelView.java
==============================================================================
--- trunk/gdf-mygwt/src/main/java/gdf/mygwt/client/view/PanelView.java (original)
+++ trunk/gdf-mygwt/src/main/java/gdf/mygwt/client/view/PanelView.java
Tue Jan 8 07:36:32 2008
@@ -15,8 +15,6 @@
import net.mygwt.ui.client.widget.menu.Menu;
import net.mygwt.ui.client.widget.menu.MenuItem;
-import com.google.gwt.user.client.ui.Widget;
-
/**
*
*
@@ -24,26 +22,22 @@
*/
public class PanelView extends gdf.gwt.client.view.PanelView {
- private Menu contextMenu;
-
public PanelView(Panel panel) {
super(panel);
- this.contextMenu = null;
}
- public void closeContextMenu() {
+ public void hideContextMenu() {
if (this.contextMenu != null) {
- this.contextMenu.hide();
+ Menu menu = (Menu) this.contextMenu;
+ menu.hide();
}
this.contextMenu = null;
}
- protected Widget createContextMenu() {
- closeContextMenu();
-
+ public void showContextMenu(int mouseX, int mouseY) {
if (getPanelModel().getActionItems().size() > 0) {
- this.contextMenu = new Menu();
+ Menu menu = new Menu();
MenuItem item;
ActionItem action;
@@ -53,11 +47,13 @@
item.setText(action.getTitle());
item.addSelectionListener(new ActionSelectionListener(
getComponent(), action));
- this.contextMenu.add(item);
+ menu.add(item);
}
- }
- return this.contextMenu;
+ menu.show(mouseX, mouseY);
+
+ this.contextMenu = menu;
+ }
}
}
Modified: trunk/gdf-mygwt/src/main/java/gdf/mygwt/client/view/TreeView.java
==============================================================================
--- trunk/gdf-mygwt/src/main/java/gdf/mygwt/client/view/TreeView.java (original)
+++ trunk/gdf-mygwt/src/main/java/gdf/mygwt/client/view/TreeView.java
Tue Jan 8 07:36:32 2008
@@ -154,7 +154,7 @@
final ActionItem actionItem = (ActionItem) iterator.next();
MenuItem dynamic = new MenuItem(Style.PUSH);
dynamic.setText(actionItem.getTitle());
- dynamic.setIconStyle(actionItem.getIconPath());
+ dynamic.setIconStyle(actionItem.getIconLocation());
dynamic.addListener(Events.Click, new Listener() {
public void handleEvent(BaseEvent be) {
Modified: trunk/gdf-sample/src/main/java/gdf/sample/client/desk/form/FieldForm.java
==============================================================================
---
trunk/gdf-sample/src/main/java/gdf/sample/client/desk/form/FieldForm.java (original)
+++
trunk/gdf-sample/src/main/java/gdf/sample/client/desk/form/FieldForm.java
Tue Jan 8 07:36:32 2008
@@ -8,6 +8,7 @@
package gdf.sample.client.desk.form;
+import gdf.core.client.action.ActionItem;
import gdf.core.client.form.DateField;
import gdf.core.client.form.DecimalField;
import gdf.core.client.form.FieldSet;
@@ -18,6 +19,9 @@
import java.util.List;
import java.util.Map;
+import com.google.gwt.user.client.Command;
+import com.google.gwt.user.client.Window;
+
/**
* Sample form.
*
@@ -37,6 +41,13 @@
}
public void initActions(List actions) {
+ ActionItem saveAction = new ActionItem("Save", "sample-icon-save",
+ new Command() {
+ public void execute() {
+ Window.alert("Saving...");
+ }
+ });
+ actions.add(saveAction);
}
public void initFields(Panel fieldPanel, Map values) {
Modified: trunk/gdf-sample/src/main/java/gdf/sample/public/gdf-sample.css
==============================================================================
--- trunk/gdf-sample/src/main/java/gdf/sample/public/gdf-sample.css (original)
+++ trunk/gdf-sample/src/main/java/gdf/sample/public/gdf-sample.css Tue
Jan 8 07:36:32 2008
@@ -16,6 +16,10 @@
background-image: url(group_obj.gif);
}
+.sample-icon-save {
+ background-image: url(save.gif);
+}
+
.sample-icon-table
{
background-image: url(table_obj.gif);