Pārlūkot izejas kodu

Unlock and refactor some API to create a new ContextMenu (#11041)

tags/8.6.0.alpha1
Ilia Motornyi pirms 5 gadiem
vecāks
revīzija
2f34a006ed
Revīzijas autora e-pasta adrese nav piesaistīta nevienam kontam

+ 1
- 6
client/src/main/java/com/vaadin/client/ComponentConnector.java Parādīt failu

@@ -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();

/**

+ 28
- 0
client/src/main/java/com/vaadin/client/HasWidget.java Parādīt failu

@@ -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();
}

+ 2
- 2
client/src/main/java/com/vaadin/client/extensions/AbstractEventTriggerExtensionConnector.java Parādīt failu

@@ -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)

+ 49
- 11
client/src/main/java/com/vaadin/client/ui/VMenuBar.java Parādīt failu

@@ -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) {

+ 11
- 9
client/src/main/java/com/vaadin/client/ui/VOverlay.java Parādīt failu

@@ -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;
}
}

Notiek ielāde…
Atcelt
Saglabāt