aboutsummaryrefslogtreecommitdiffstats
path: root/client/src/main
diff options
context:
space:
mode:
authorIlia Motornyi <elmot@vaadin.com>2018-07-11 21:59:32 +0300
committerGitHub <noreply@github.com>2018-07-11 21:59:32 +0300
commit2f34a006ed3d98acd79c48c1a2d8fc680188053a (patch)
treec8e978dc9598f8101cc25bf9a84011a150eb3dc8 /client/src/main
parentceb9593f5d08814dd0dfe4d83030fc403078b5cd (diff)
downloadvaadin-framework-2f34a006ed3d98acd79c48c1a2d8fc680188053a.tar.gz
vaadin-framework-2f34a006ed3d98acd79c48c1a2d8fc680188053a.zip
Unlock and refactor some API to create a new ContextMenu (#11041)
Diffstat (limited to 'client/src/main')
-rw-r--r--client/src/main/java/com/vaadin/client/ComponentConnector.java7
-rw-r--r--client/src/main/java/com/vaadin/client/HasWidget.java28
-rw-r--r--client/src/main/java/com/vaadin/client/extensions/AbstractEventTriggerExtensionConnector.java4
-rw-r--r--client/src/main/java/com/vaadin/client/ui/VMenuBar.java60
-rw-r--r--client/src/main/java/com/vaadin/client/ui/VOverlay.java20
5 files changed, 91 insertions, 28 deletions
diff --git a/client/src/main/java/com/vaadin/client/ComponentConnector.java b/client/src/main/java/com/vaadin/client/ComponentConnector.java
index 0dd88975e4..0a0e1ca06c 100644
--- a/client/src/main/java/com/vaadin/client/ComponentConnector.java
+++ b/client/src/main/java/com/vaadin/client/ComponentConnector.java
@@ -28,7 +28,7 @@ import com.vaadin.shared.AbstractComponentState;
* Updates can be sent back to the server using the
* {@link ApplicationConnection#updateVariable()} methods.
*/
-public interface ComponentConnector extends ServerConnector {
+public interface ComponentConnector extends HasWidget {
/*
* (non-Javadoc)
@@ -38,11 +38,6 @@ public interface ComponentConnector extends ServerConnector {
@Override
public AbstractComponentState getState();
- /**
- * Returns the widget for this {@link ComponentConnector}.
- */
- public Widget getWidget();
-
public LayoutManager getLayoutManager();
/**
diff --git a/client/src/main/java/com/vaadin/client/HasWidget.java b/client/src/main/java/com/vaadin/client/HasWidget.java
new file mode 100644
index 0000000000..45c93aa210
--- /dev/null
+++ b/client/src/main/java/com/vaadin/client/HasWidget.java
@@ -0,0 +1,28 @@
+/*
+ * Copyright 2000-2018 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.client;
+
+import com.google.gwt.user.client.ui.Widget;
+
+/**
+ * An interface used by client-side connectors which have widgets.
+ */
+public interface HasWidget extends ServerConnector {
+ /**
+ * Returns the widget for this {@link ServerConnector}.
+ */
+ public Widget getWidget();
+}
diff --git a/client/src/main/java/com/vaadin/client/extensions/AbstractEventTriggerExtensionConnector.java b/client/src/main/java/com/vaadin/client/extensions/AbstractEventTriggerExtensionConnector.java
index 79419f3da8..1d6f1b0a49 100644
--- a/client/src/main/java/com/vaadin/client/extensions/AbstractEventTriggerExtensionConnector.java
+++ b/client/src/main/java/com/vaadin/client/extensions/AbstractEventTriggerExtensionConnector.java
@@ -18,7 +18,7 @@ package com.vaadin.client.extensions;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.user.client.ui.Widget;
import com.google.web.bindery.event.shared.HandlerRegistration;
-import com.vaadin.client.ComponentConnector;
+import com.vaadin.client.HasWidget;
import com.vaadin.client.ServerConnector;
import com.vaadin.shared.extension.PartInformationState;
@@ -50,7 +50,7 @@ public abstract class AbstractEventTriggerExtensionConnector
@Override
protected void extend(ServerConnector target) {
- Widget targetWidget = ((ComponentConnector) target).getWidget();
+ Widget targetWidget = ((HasWidget) target).getWidget();
if (targetWidget instanceof EventTrigger) {
String partInformation = getState().partInformation;
eventHandlerRegistration = ((EventTrigger) targetWidget)
diff --git a/client/src/main/java/com/vaadin/client/ui/VMenuBar.java b/client/src/main/java/com/vaadin/client/ui/VMenuBar.java
index 70af301be0..a652cf79fd 100644
--- a/client/src/main/java/com/vaadin/client/ui/VMenuBar.java
+++ b/client/src/main/java/com/vaadin/client/ui/VMenuBar.java
@@ -225,13 +225,35 @@ public class VMenuBar extends FocusableFlowPanel implements
* For internal use only. May be removed or replaced in the future.
*/
public String buildItemHTML(UIDL item) {
+ return buildItemHTML(item.hasAttribute("separator"),
+ item.getChildCount() > 0, item.getStringAttribute("icon"),
+ item.getStringAttribute("text"));
+
+ }
+
+ /**
+ * Build the HTML content for a menu item.
+ * <p>
+ * For internal use only. May be removed or replaced in the future.
+ *
+ * @param separator
+ * the menu item is separator
+ * @param subMenu
+ * the menu item contains submenu
+ * @param iconUrl
+ * the menu item icon URL or {@code null}
+ * @param text
+ * the menu item text. May not be {@code null}
+ */
+ public String buildItemHTML(boolean separator, boolean subMenu,
+ String iconUrl, String text) {
// Construct html from the text and the optional icon
StringBuilder itemHTML = new StringBuilder();
- if (item.hasAttribute("separator")) {
+ if (separator) {
itemHTML.append("<span>---</span>");
} else {
// Add submenu indicator
- if (item.getChildCount() > 0) {
+ if (subMenu) {
String bgStyle = "";
itemHTML.append("<span class=\"" + getStylePrimaryName()
+ "-submenu-indicator\"" + bgStyle
@@ -240,11 +262,11 @@ public class VMenuBar extends FocusableFlowPanel implements
itemHTML.append("<span class=\"" + getStylePrimaryName()
+ "-menuitem-caption\">");
- Icon icon = client.getIcon(item.getStringAttribute("icon"));
+ Icon icon = client.getIcon(iconUrl);
if (icon != null) {
itemHTML.append(icon.getElement().getString());
}
- String itemText = item.getStringAttribute("text");
+ String itemText = text;
if (!htmlContentAllowed) {
itemText = WidgetUtil.escapeHTML(itemText);
}
@@ -701,9 +723,13 @@ public class VMenuBar extends FocusableFlowPanel implements
*/
@Override
public void onClose(CloseEvent<PopupPanel> event) {
- hideChildren();
+ close(event, true);
+ }
+
+ protected void close(CloseEvent<PopupPanel> event, boolean animated) {
+ hideChildren(animated, animated);
if (event.isAutoClosed()) {
- hideParents(true);
+ hideParents(true, animated);
menuVisible = false;
}
visibleChildMenu = null;
@@ -739,14 +765,18 @@ public class VMenuBar extends FocusableFlowPanel implements
* Recursively hide all parent menus.
*/
public void hideParents(boolean autoClosed) {
+ hideParents(autoClosed, true);
+ }
+
+ public void hideParents(boolean autoClosed, boolean animated) {
if (visibleChildMenu != null) {
- popup.hide();
+ popup.hide(false, animated, animated);
setSelected(null);
menuVisible = false;
}
if (getParentMenu() != null) {
- getParentMenu().hideParents(autoClosed);
+ getParentMenu().hideParents(autoClosed, animated);
}
}
@@ -949,7 +979,7 @@ public class VMenuBar extends FocusableFlowPanel implements
updateStyleNames();
}
- protected void updateStyleNames() {
+ public void updateStyleNames() {
if (parentMenu == null) {
// Style names depend on the parent menu's primary style name so
// don't do updates until the item has a parent
@@ -1088,7 +1118,7 @@ public class VMenuBar extends FocusableFlowPanel implements
return enabled;
}
- private void setSeparator(boolean separator) {
+ public void setSeparator(boolean separator) {
isSeparator = separator;
updateStyleNames();
if (!separator) {
@@ -1185,6 +1215,14 @@ public class VMenuBar extends FocusableFlowPanel implements
this.id = id;
}
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ public void setDescriptionContentMode(
+ ContentMode descriptionContentMode) {
+ this.descriptionContentMode = descriptionContentMode;
+ }
}
/**
@@ -1906,7 +1944,7 @@ public class VMenuBar extends FocusableFlowPanel implements
LazyCloser.schedule();
}
- private VMenuBar getRoot() {
+ protected VMenuBar getRoot() {
VMenuBar root = this;
while (root.getParentMenu() != null) {
diff --git a/client/src/main/java/com/vaadin/client/ui/VOverlay.java b/client/src/main/java/com/vaadin/client/ui/VOverlay.java
index 6bc9896863..c70ef12c24 100644
--- a/client/src/main/java/com/vaadin/client/ui/VOverlay.java
+++ b/client/src/main/java/com/vaadin/client/ui/VOverlay.java
@@ -65,15 +65,6 @@ public class VOverlay extends Overlay {
super(autoHide, modal);
}
- /*
- * A "thread local" of sorts, set temporarily so that VOverlayImpl knows
- * which VOverlay is using it, so that it can be attached to the correct
- * overlay container.
- *
- * TODO this is a strange pattern that we should get rid of when possible.
- */
- protected static VOverlay current;
-
/**
* Get the {@link ApplicationConnection} that this overlay belongs to. If
* it's not set, {@link #getOwner()} is used to figure it out.
@@ -162,4 +153,15 @@ public class VOverlay extends Overlay {
overlayContainerLabel);
}
+ /**
+ * Sets the {@link ApplicationConnection} that this overlay belongs to.
+ *
+ * @see #getApplicationConnection()
+ *
+ * @param ac
+ * the connection
+ */
+ public void setApplicationConnection(ApplicationConnection ac) {
+ this.ac = ac;
+ }
}