Skip to content
This repository was archived by the owner on Dec 31, 2020. It is now read-only.

Commit 4b16ddc

Browse files
committed
Getting ready for 0.2.0
1 parent 09b4fd4 commit 4b16ddc

File tree

13 files changed

+248
-47
lines changed

13 files changed

+248
-47
lines changed

README.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,30 @@ Then in scss of your theme, add rule:
3434

3535
After this you should have all 12 columns sized correctly to take 8.333...% of width.
3636

37+
### Using Button (or other active component) without dragging handle
38+
Currently Vaadin components and gridstack.js do not behave well if both fight over same events. For this reason since
39+
0.2.0 default behavior has been to use separate dragging handle. You can still use handle free dragging on components
40+
that are not or do not contain active components.
41+
42+
```java
43+
// Adding component with dragging handle (default behavior)
44+
gridstack.addComponent(myLayout);
45+
46+
// Adding component without dragging handle (content acts as dragging handle)
47+
gridstack.addComponent(myLabel, false);
48+
```
49+
3750
## Download release
3851

3952
Official releases of this add-on are available at Vaadin Directory. For Maven instructions, download and reviews, go to http://vaadin.com/addon/gridstack
4053

4154
## Release notes
4255

43-
### Version 0.1.1 (2015-xx-xx)
56+
### Version 0.2.0 (2015-11-30)
4457
- Fixing issue #3 "Removing and subsequently adding Components"
4558
- Clearning unneeded error debug prints on client side
59+
- Way Vaadin components handle events cause issues with gridstack's drag handling. For this reason separate drag handle element is now used by default. Issue #2
60+
- Adding top level static option to toggle layout's edit mode. Currently still allows to drag children that allow dragging without handle (KNOWN ISSUE).
4661

4762
### Version 0.1.0 (2015-11-09)
4863
- Initial release. Not all features supported yet, but should allow basic usage

gridstack-addon/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<groupId>org.vaadin.alump.gridstack</groupId>
66
<artifactId>gridstack-addon</artifactId>
77
<packaging>bundle</packaging>
8-
<version>0.1.1-SNAPSHOT</version>
8+
<version>0.2.0</version>
99
<name>GridStack Add-on</name>
1010

1111
<properties>

gridstack-addon/src/main/java/org/vaadin/alump/gridstack/GridStackLayout.java

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,17 @@ public void addComponent(Component component) {
130130
addComponent(component, -1, -1);
131131
}
132132

133+
/**
134+
* Add component to layout
135+
* @param component Component added
136+
* @param useDragHandle true to add component with a separate drag handle, or false to make whole content act as a
137+
* drag handle. Notice that using a separate drag handle is recommended if you component
138+
* is or contains any active components (buttons etc..)
139+
*/
140+
public void addComponent(Component component, boolean useDragHandle) {
141+
addComponent(component, -1, -1, useDragHandle);
142+
}
143+
133144
/**
134145
* Add component to given slot
135146
* @param component Component added
@@ -140,6 +151,19 @@ public void addComponent(Component component, int x, int y) {
140151
addComponent(component, x, y, 1, 1);
141152
}
142153

154+
/**
155+
* Add component to given slot
156+
* @param component Component added
157+
* @param x Slot's X coordinate
158+
* @param y Slot's Y coordinate
159+
* @param useDragHandle true to add component with a separate drag handle, or false to make whole content act as a
160+
* drag handle. Notice that using a separate drag handle is recommended if you component
161+
* is or contains any active components (buttons etc..)
162+
*/
163+
public void addComponent(Component component, int x, int y, boolean useDragHandle) {
164+
addComponent(component, x, y, 1, 1, useDragHandle);
165+
}
166+
143167
/**
144168
* Add component to given slot, and define it's size
145169
* @param component Component added
@@ -149,6 +173,21 @@ public void addComponent(Component component, int x, int y) {
149173
* @param height Height of space reserved (in slots)
150174
*/
151175
public void addComponent(Component component, int x, int y, int width, int height) {
176+
addComponent(component, x, y, width, height, true);
177+
}
178+
179+
/**
180+
* Add component to given slot, and define it's size
181+
* @param component Component added
182+
* @param x Slot's X coordinate (use negative values if position can be defined on client side)
183+
* @param y Slot's Y coordinate (use negative values if position can be defined on client side)
184+
* @param width Width of space reserved (in slots)
185+
* @param height Height of space reserved (in slots)
186+
* @param useDragHandle true to add component with a separate drag handle, or false to make whole content act as a
187+
* drag handle. Notice that using a separate drag handle is recommended if you component
188+
* is or contains any active components (buttons etc..)
189+
*/
190+
public void addComponent(Component component, int x, int y, int width, int height, boolean useDragHandle) {
152191
super.addComponent(component);
153192
components.add(component);
154193

@@ -157,6 +196,7 @@ public void addComponent(Component component, int x, int y, int width, int heigh
157196
info.y = y;
158197
info.width = width;
159198
info.height = height;
199+
info.useDragHandle = useDragHandle;
160200
getState().childOptions.put(component, info);
161201
}
162202

@@ -362,4 +402,31 @@ protected GridStackChildOptions getComponentOptions(Component child, boolean mod
362402
}
363403
return opt;
364404
}
405+
406+
/**
407+
* Set layout static (no dragging of resizing) or dynamic (dragging and resizing allowed)
408+
* @param staticGrid true to set static (no dragging of resizing), false to set dynamic (dragging and resizing
409+
* allowed)
410+
*/
411+
public void setStaticGrid(boolean staticGrid) {
412+
getState(true).gridStackOptions.staticGrid = staticGrid;
413+
}
414+
415+
/**
416+
* Check if layout is in static mode
417+
* @return true if in static mode, false if not, null if not defined by server side
418+
*/
419+
public Boolean isStaticGrid() {
420+
return getState(false).gridStackOptions.staticGrid;
421+
}
422+
423+
424+
/**
425+
* Check if component has specific dragging handle
426+
* @param child Child component of layout
427+
* @return true if component has separate dragging handle, false if whole content acts as dragging handle
428+
*/
429+
public boolean isComponentWithDragHandle(Component child) {
430+
return getComponentOptions(child, false).useDragHandle;
431+
}
365432
}

gridstack-addon/src/main/java/org/vaadin/alump/gridstack/client/GridStackLayoutConnector.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,9 @@ public void onStateChanged(StateChangeEvent event) {
9090
super.onStateChanged(event);
9191
clickEventHandler.handleEventHandlerRegistration();
9292

93-
if(event.isInitialStateChange() || event.hasPropertyChanged("gridStackProperties")) {
93+
if(event.isInitialStateChange() || event.hasPropertyChanged("gridStackOptions")) {
9494
getWidget().setOptions(getState().gridStackOptions.width, getState().gridStackOptions.height,
95-
GwtGridStackOptions.createFrom(getState().gridStackOptions));
95+
getState().gridStackOptions);
9696
}
9797

9898
if(getWidget().isInitialized() && event.hasPropertyChanged("childOptions")) {

gridstack-addon/src/main/java/org/vaadin/alump/gridstack/client/GwtGridStack.java

Lines changed: 55 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@
1919

2020
import com.google.gwt.dom.client.Document;
2121
import com.google.gwt.dom.client.Element;
22-
import com.google.gwt.dom.client.Style.Display;
2322
import com.google.gwt.user.client.Event;
2423
import com.google.gwt.user.client.ui.ComplexPanel;
2524
import com.google.gwt.user.client.ui.Widget;
2625
import org.vaadin.alump.gridstack.client.shared.GridStackChildOptions;
26+
import org.vaadin.alump.gridstack.client.shared.GridStackOptions;
2727

2828
import java.util.ArrayList;
2929
import java.util.Date;
@@ -47,6 +47,9 @@ public class GwtGridStack extends ComplexPanel {
4747

4848
public final static long DISABLE_CLICK_AFTER_EVENT_MS = 100L;
4949

50+
public final static String CONTENT_CLASSNAME = "grid-stack-item-content";
51+
public final static String DRAG_HANDLE_CLASSNAME = GridStackOptions.DRAG_HANDLE_CLASSNAME;
52+
5053
public interface GwtGridStackMoveHandler {
5154
void onWidgetsMoved(Widget[] widgets, GwtGridStackChangedItem[] data);
5255
}
@@ -63,21 +66,32 @@ public boolean isInitialized() {
6366
return initialized;
6467
}
6568

66-
public void setOptions(Integer width, Integer height, GwtGridStackOptions options) {
69+
public void setOptions(Integer width, Integer height, GridStackOptions options) {
6770
if(!initialized) {
68-
if(width != null) {
69-
getElement().setAttribute("data-gs-width", width.toString());
70-
}
71-
if(height != null) {
72-
getElement().setAttribute("data-gs-height", height.toString());
73-
}
74-
initializeGridStack(options);
75-
initialized = true;
71+
initialize(width, height, GwtGridStackOptions.createFrom(options));
7672
} else {
77-
//TODO
73+
if(options.staticGrid != null) {
74+
nativeSetGridStatic(options.staticGrid.booleanValue());
75+
}
7876
}
7977
}
8078

79+
public void initialize(Integer width, Integer height, GwtGridStackOptions options) {
80+
if(initialized) {
81+
LOGGER.severe("gridstack already initialized");
82+
return;
83+
}
84+
85+
if(width != null) {
86+
getElement().setAttribute("data-gs-width", width.toString());
87+
}
88+
if(height != null) {
89+
getElement().setAttribute("data-gs-height", height.toString());
90+
}
91+
initializeGridStack(options);
92+
initialized = true;
93+
}
94+
8195
@Override
8296
public void add(Widget widget) {
8397
add(widget, new GridStackChildOptions());
@@ -106,6 +120,7 @@ public boolean remove(Widget widget) {
106120
protected Element createWrapper(GridStackChildOptions info) {
107121
Element wrapper = Document.get().createDivElement();
108122
wrapper.addClassName("grid-stack-item");
123+
109124
if(info.x >= 0 && info.y >= 0) {
110125
wrapper.setAttribute("data-gs-x", Integer.toString(info.x));
111126
wrapper.setAttribute("data-gs-y", Integer.toString(info.y));
@@ -133,13 +148,20 @@ protected Element createWrapper(GridStackChildOptions info) {
133148
}
134149

135150
Element content = Document.get().createDivElement();
136-
content.addClassName("grid-stack-item-content");
151+
content.addClassName(CONTENT_CLASSNAME);
152+
153+
if(!info.useDragHandle) {
154+
content.addClassName(DRAG_HANDLE_CLASSNAME);
155+
}
156+
137157
wrapper.appendChild(content);
138158

139-
Element dragHandle = Document.get().createDivElement();
140-
dragHandle.addClassName("grid-stack-item-drag-handle");
141-
dragHandle.getStyle().setDisplay(Display.NONE);
142-
wrapper.appendChild(dragHandle);
159+
if(info.useDragHandle) {
160+
Element dragHandle = Document.get().createDivElement();
161+
dragHandle.addClassName("separate-handle");
162+
dragHandle.addClassName(DRAG_HANDLE_CLASSNAME);
163+
wrapper.appendChild(dragHandle);
164+
}
143165

144166
return wrapper;
145167
}
@@ -261,6 +283,14 @@ public void updateChild(Widget widget, GridStackChildOptions options) {
261283
updateWidgetWrapper(wrapper, options.x, options.y, options.width, options.height);
262284
updateWidgetSizeLimits(wrapper, GwtGridSizeLimits.create(options));
263285
setLocked(wrapper, options.locked);
286+
287+
/* Make sure draghandle style name is at right place
288+
Element contentElement = wrapper.getFirstChildElement();
289+
if(options.useDragHandle) {
290+
contentElement.removeClassName(DRAG_HANDLE_CLASSNAME);
291+
} else {
292+
contentElement.addClassName(DRAG_HANDLE_CLASSNAME);
293+
}*/
264294
}
265295

266296
protected native final void updateWidgetWrapper(Element element, int x, int y, int width, int height)
@@ -327,4 +357,13 @@ protected native final void nativeBatchUpdate()
327357
public boolean isClickOk() {
328358
return !draggedOrResized && new Date().getTime() > (lastEvent + DISABLE_CLICK_AFTER_EVENT_MS);
329359
}
360+
361+
protected native final void nativeSetGridStatic(boolean gridStatic)
362+
/*-{
363+
var elementId = this.@org.vaadin.alump.gridstack.client.GwtGridStack::elementId;
364+
$wnd.$(function () {
365+
var grid = $wnd.$('#' + elementId).data('gridstack');
366+
grid.set_static(gridStatic);
367+
});
368+
}-*/;
330369
}

gridstack-addon/src/main/java/org/vaadin/alump/gridstack/client/GwtGridStackOptions.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ public final static GwtGridStackOptions createFrom(GridStackOptions options) {
6060
if(options.width != null) {
6161
obj.setWidth(options.width);
6262
}
63+
if(options.handleClass != null) {
64+
obj.setHandleClass(options.handleClass);
65+
}
6366
return obj;
6467
}
6568

@@ -143,4 +146,14 @@ public final native void setWidth(int width)
143146
this.width = width;
144147
}-*/;
145148

149+
public final native String getHandleClass()
150+
/*-{
151+
return this.handle_class;
152+
}-*/;
153+
154+
public final native void setHandleClass(String handleClass)
155+
/*-{
156+
this.handle_class = handleClass;
157+
}-*/;
158+
146159
}

gridstack-addon/src/main/java/org/vaadin/alump/gridstack/client/shared/GridStackChildOptions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,6 @@ public class GridStackChildOptions implements Serializable {
3434
public Integer maxHeight = null;
3535
public boolean locked = false;
3636

37-
public boolean showDragHandle = false;
37+
public boolean useDragHandle = false;
3838
public String styleName = null;
3939
}

gridstack-addon/src/main/java/org/vaadin/alump/gridstack/client/shared/GridStackOptions.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,14 @@
2525
* Use null to keep default value of gridstack.js
2626
*/
2727
public class GridStackOptions implements Serializable {
28+
29+
public final static String DRAG_HANDLE_CLASSNAME = "grid-stack-item-drag-handle";
30+
2831
public Boolean alwaysShowResizeHandle = null;
2932
public Boolean animate = null;
3033
public Boolean auto = null;
3134
public Integer cellHeight = null;
32-
//TODO draggable
33-
//public String handle = null;
34-
//public String handleClass = null;
35+
public String handleClass = DRAG_HANDLE_CLASSNAME;
3536
public Integer height = null;
3637
public Boolean floating = null;
3738
//public String itemClass = null;

0 commit comments

Comments
 (0)