Skip to content

Commit 5f4ec29

Browse files
committed
Merge pull request #308 from GwtMaterialDesign/prestyle_initialization
Added InitialClassMixin to be defined after attached event of MaterialWidget
2 parents f5e9d07 + 3de5aff commit 5f4ec29

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+249
-115
lines changed

gwt-material/src/main/java/gwt/material/design/client/base/AbstractButton.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ protected AbstractButton() {
7373
getElement().getStyle().setCursor(Style.Cursor.POINTER);
7474
}
7575

76+
protected AbstractButton(String... initialClass) {
77+
this();
78+
setInitialClass(initialClass);
79+
}
80+
7681
protected AbstractButton(String text, String bgColor, WavesType waves) {
7782
this(null, text, bgColor);
7883
setWaves(waves);

gwt-material/src/main/java/gwt/material/design/client/base/AbstractIconButton.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ public AbstractIconButton() {
6161
setIconPosition(IconPosition.LEFT);
6262
}
6363

64+
public AbstractIconButton(String... initialClass) {
65+
super();
66+
setInitialClass(initialClass);
67+
}
68+
6469
@Override
6570
public MaterialIcon getIcon() {
6671
return icon;

gwt-material/src/main/java/gwt/material/design/client/base/BaseCheckBox.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,27 @@
1515
*/
1616
package gwt.material.design.client.base;
1717

18+
/*
19+
* #%L
20+
* GwtMaterial
21+
* %%
22+
* Copyright (C) 2015 - 2016 GwtMaterialDesign
23+
* %%
24+
* Licensed under the Apache License, Version 2.0 (the "License");
25+
* you may not use this file except in compliance with the License.
26+
* You may obtain a copy of the License at
27+
*
28+
* http://www.apache.org/licenses/LICENSE-2.0
29+
*
30+
* Unless required by applicable law or agreed to in writing, software
31+
* distributed under the License is distributed on an "AS IS" BASIS,
32+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
33+
* See the License for the specific language governing permissions and
34+
* limitations under the License.
35+
* #L%
36+
*/
37+
38+
1839
import com.google.gwt.dom.client.Document;
1940
import com.google.gwt.dom.client.Element;
2041
import com.google.gwt.dom.client.InputElement;
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package gwt.material.design.client.base;
2+
3+
/*
4+
* #%L
5+
* GwtMaterial
6+
* %%
7+
* Copyright (C) 2015 - 2016 GwtMaterialDesign
8+
* %%
9+
* Licensed under the Apache License, Version 2.0 (the "License");
10+
* you may not use this file except in compliance with the License.
11+
* You may obtain a copy of the License at
12+
*
13+
* http://www.apache.org/licenses/LICENSE-2.0
14+
*
15+
* Unless required by applicable law or agreed to in writing, software
16+
* distributed under the License is distributed on an "AS IS" BASIS,
17+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18+
* See the License for the specific language governing permissions and
19+
* limitations under the License.
20+
* #L%
21+
*/
22+
23+
24+
25+
public interface HasInitialClass {
26+
27+
/**
28+
* Set the initial class into Material Components
29+
* @param initialClass
30+
*/
31+
void setInitialClass(String... initialClass);
32+
33+
/**
34+
* Get the initial class of Material Components
35+
* @return
36+
*/
37+
String[] getInitialClass();
38+
39+
}

gwt-material/src/main/java/gwt/material/design/client/base/MaterialWidget.java

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,7 @@
2121
*/
2222

2323
import gwt.material.design.client.base.helper.StyleHelper;
24-
import gwt.material.design.client.base.mixin.ColorsMixin;
25-
import gwt.material.design.client.base.mixin.CssNameMixin;
26-
import gwt.material.design.client.base.mixin.EnabledMixin;
27-
import gwt.material.design.client.base.mixin.FlexboxMixin;
28-
import gwt.material.design.client.base.mixin.FocusableMixin;
29-
import gwt.material.design.client.base.mixin.FontSizeMixin;
30-
import gwt.material.design.client.base.mixin.GridMixin;
31-
import gwt.material.design.client.base.mixin.IdMixin;
32-
import gwt.material.design.client.base.mixin.ScrollspyMixin;
33-
import gwt.material.design.client.base.mixin.SeparatorMixin;
34-
import gwt.material.design.client.base.mixin.ShadowMixin;
35-
import gwt.material.design.client.base.mixin.ToggleStyleMixin;
36-
import gwt.material.design.client.base.mixin.TooltipMixin;
37-
import gwt.material.design.client.base.mixin.WavesMixin;
24+
import gwt.material.design.client.base.mixin.*;
3825
import gwt.material.design.client.constants.CenterOn;
3926
import gwt.material.design.client.constants.Display;
4027
import gwt.material.design.client.constants.Flex;
@@ -57,8 +44,10 @@
5744

5845
public class MaterialWidget extends ComplexPanel implements HasId, HasEnabled, HasTextAlign, HasColors, HasGrid,
5946
HasShadow, Focusable, HasInlineStyle, HasSeparator, HasScrollspy, HasHideOn, HasShowOn, HasCenterOn,
60-
HasCircle, HasWaves, HasDataAttributes, HasFloat, HasTooltip, HasFlexbox, HasHoverable, HasFontWeight, HasDepth {
47+
HasCircle, HasWaves, HasDataAttributes, HasFloat, HasTooltip, HasFlexbox, HasHoverable, HasFontWeight, HasDepth, HasInitialClass {
6148

49+
50+
private InitialClassMixin<MaterialWidget> initialClassMixin;
6251
private IdMixin<MaterialWidget> idMixin;
6352
private EnabledMixin<MaterialWidget> enabledMixin;
6453
private CssNameMixin<MaterialWidget, TextAlign> textAlignMixin;
@@ -84,6 +73,11 @@ public class MaterialWidget extends ComplexPanel implements HasId, HasEnabled, H
8473
public MaterialWidget() {
8574
}
8675

76+
public MaterialWidget(Element element, String... initialClass) {
77+
this(element);
78+
setInitialClass(initialClass);
79+
}
80+
8781
public MaterialWidget(Element element) {
8882
setElement(element);
8983
}
@@ -208,6 +202,11 @@ public ToggleStyleMixin<MaterialWidget> getTruncateMixin() {
208202
return truncateMixin;
209203
}
210204

205+
public InitialClassMixin<MaterialWidget> getInitialClassMixin() {
206+
if(initialClassMixin == null) { initialClassMixin = new InitialClassMixin<>(this); }
207+
return initialClassMixin;
208+
}
209+
211210
@Override
212211
public void setId(String id) {
213212
getIdMixin().setId(id);
@@ -692,4 +691,14 @@ private native void stopTouchStartEvent(Element e) /*-{
692691
event.stopPropagation();
693692
});
694693
}-*/;
694+
695+
@Override
696+
public void setInitialClass(String... initialClass) {
697+
getInitialClassMixin().setInitialClass(initialClass);
698+
}
699+
700+
@Override
701+
public String[] getInitialClass() {
702+
return getInitialClassMixin().getInitialClass();
703+
}
695704
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
package gwt.material.design.client.base.mixin;
2+
3+
/*
4+
* #%L
5+
* GwtMaterial
6+
* %%
7+
* Copyright (C) 2015 - 2016 GwtMaterialDesign
8+
* %%
9+
* Licensed under the Apache License, Version 2.0 (the "License");
10+
* you may not use this file except in compliance with the License.
11+
* You may obtain a copy of the License at
12+
*
13+
* http://www.apache.org/licenses/LICENSE-2.0
14+
*
15+
* Unless required by applicable law or agreed to in writing, software
16+
* distributed under the License is distributed on an "AS IS" BASIS,
17+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18+
* See the License for the specific language governing permissions and
19+
* limitations under the License.
20+
* #L%
21+
*/
22+
23+
24+
import com.google.gwt.event.logical.shared.AttachEvent;
25+
import com.google.gwt.user.client.ui.UIObject;
26+
import com.google.gwt.user.client.ui.Widget;
27+
import gwt.material.design.client.base.HasInitialClass;
28+
29+
/**
30+
* @author kevzlou7979
31+
*/
32+
public class InitialClassMixin<T extends UIObject & HasInitialClass> extends AbstractMixin<T> implements HasInitialClass {
33+
34+
private String[] initialClass;
35+
36+
public InitialClassMixin(final T uiObject) {
37+
super(uiObject);
38+
}
39+
40+
41+
@Override
42+
public void setInitialClass(final String... initialClass) {
43+
this.initialClass = initialClass;
44+
if(!((Widget)uiObject).isAttached()){
45+
((Widget)uiObject).addAttachHandler(new AttachEvent.Handler() {
46+
@Override
47+
public void onAttachOrDetach(AttachEvent event) {
48+
49+
for(String s : initialClass) {
50+
if(initialClass != null && !s.isEmpty()) {
51+
uiObject.removeStyleName(s);
52+
}
53+
if(event.isAttached()){
54+
if(initialClass != null && !s.isEmpty()) {
55+
uiObject.addStyleName(s);
56+
}
57+
}
58+
}
59+
}
60+
});
61+
}
62+
}
63+
64+
65+
@Override
66+
public String[] getInitialClass() {
67+
return initialClass;
68+
}
69+
}

gwt-material/src/main/java/gwt/material/design/client/ui/MaterialBadge.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
* #L%
2121
*/
2222

23+
import com.google.gwt.dom.client.Document;
2324
import gwt.material.design.client.ui.html.Span;
2425

2526
import com.google.gwt.user.client.ui.HasText;
@@ -45,7 +46,7 @@ public class MaterialBadge extends Span implements HasText {
4546
* Collection, DropDown, SideNav and any other Material components.
4647
*/
4748
public MaterialBadge() {
48-
setStyleName("badge sideBarBadge");
49+
super(Document.get().createSpanElement(), "badge", "sideBarBadge");
4950
}
5051

5152
/**

gwt-material/src/main/java/gwt/material/design/client/ui/MaterialBreadcrumb.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
public class MaterialBreadcrumb extends AbstractIconButton {
5050

5151
public MaterialBreadcrumb() {
52-
setStyleName("breadcrumb");
52+
super("breadcrumb");
5353
}
5454

5555
@Override

gwt-material/src/main/java/gwt/material/design/client/ui/MaterialCard.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,7 @@ public class MaterialCard extends MaterialWidget implements HasAxis {
101101
* Creates and empty card.
102102
*/
103103
public MaterialCard() {
104-
super(Document.get().createDivElement());
105-
setStyleName("card");
104+
super(Document.get().createDivElement(), "card");
106105
}
107106

108107
@Override

gwt-material/src/main/java/gwt/material/design/client/ui/MaterialCardAction.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
public class MaterialCardAction extends MaterialWidget {
3636

3737
public MaterialCardAction(){
38-
super(Document.get().createDivElement());
39-
setStyleName("card-action");
38+
super(Document.get().createDivElement(), "card-action");
4039
}
4140
}

0 commit comments

Comments
 (0)