Переглянути джерело

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

tags/8.6.0.alpha1
Ilia Motornyi 5 роки тому
джерело
коміт
2f34a006ed
Аккаунт користувача з таким Email не знайдено

+ 1
- 6
client/src/main/java/com/vaadin/client/ComponentConnector.java Переглянути файл

* Updates can be sent back to the server using the * Updates can be sent back to the server using the
* {@link ApplicationConnection#updateVariable()} methods. * {@link ApplicationConnection#updateVariable()} methods.
*/ */
public interface ComponentConnector extends ServerConnector {
public interface ComponentConnector extends HasWidget {


/* /*
* (non-Javadoc) * (non-Javadoc)
@Override @Override
public AbstractComponentState getState(); public AbstractComponentState getState();


/**
* Returns the widget for this {@link ComponentConnector}.
*/
public Widget getWidget();

public LayoutManager getLayoutManager(); public LayoutManager getLayoutManager();


/** /**

+ 28
- 0
client/src/main/java/com/vaadin/client/HasWidget.java Переглянути файл

/*
* 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 Переглянути файл

import com.google.gwt.event.dom.client.ClickEvent; import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.user.client.ui.Widget; import com.google.gwt.user.client.ui.Widget;
import com.google.web.bindery.event.shared.HandlerRegistration; 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.client.ServerConnector;
import com.vaadin.shared.extension.PartInformationState; import com.vaadin.shared.extension.PartInformationState;




@Override @Override
protected void extend(ServerConnector target) { protected void extend(ServerConnector target) {
Widget targetWidget = ((ComponentConnector) target).getWidget();
Widget targetWidget = ((HasWidget) target).getWidget();
if (targetWidget instanceof EventTrigger) { if (targetWidget instanceof EventTrigger) {
String partInformation = getState().partInformation; String partInformation = getState().partInformation;
eventHandlerRegistration = ((EventTrigger) targetWidget) eventHandlerRegistration = ((EventTrigger) targetWidget)

+ 49
- 11
client/src/main/java/com/vaadin/client/ui/VMenuBar.java Переглянути файл

* For internal use only. May be removed or replaced in the future. * For internal use only. May be removed or replaced in the future.
*/ */
public String buildItemHTML(UIDL item) { 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 // Construct html from the text and the optional icon
StringBuilder itemHTML = new StringBuilder(); StringBuilder itemHTML = new StringBuilder();
if (item.hasAttribute("separator")) {
if (separator) {
itemHTML.append("<span>---</span>"); itemHTML.append("<span>---</span>");
} else { } else {
// Add submenu indicator // Add submenu indicator
if (item.getChildCount() > 0) {
if (subMenu) {
String bgStyle = ""; String bgStyle = "";
itemHTML.append("<span class=\"" + getStylePrimaryName() itemHTML.append("<span class=\"" + getStylePrimaryName()
+ "-submenu-indicator\"" + bgStyle + "-submenu-indicator\"" + bgStyle


itemHTML.append("<span class=\"" + getStylePrimaryName() itemHTML.append("<span class=\"" + getStylePrimaryName()
+ "-menuitem-caption\">"); + "-menuitem-caption\">");
Icon icon = client.getIcon(item.getStringAttribute("icon"));
Icon icon = client.getIcon(iconUrl);
if (icon != null) { if (icon != null) {
itemHTML.append(icon.getElement().getString()); itemHTML.append(icon.getElement().getString());
} }
String itemText = item.getStringAttribute("text");
String itemText = text;
if (!htmlContentAllowed) { if (!htmlContentAllowed) {
itemText = WidgetUtil.escapeHTML(itemText); itemText = WidgetUtil.escapeHTML(itemText);
} }
*/ */
@Override @Override
public void onClose(CloseEvent<PopupPanel> event) { public void onClose(CloseEvent<PopupPanel> event) {
hideChildren();
close(event, true);
}

protected void close(CloseEvent<PopupPanel> event, boolean animated) {
hideChildren(animated, animated);
if (event.isAutoClosed()) { if (event.isAutoClosed()) {
hideParents(true);
hideParents(true, animated);
menuVisible = false; menuVisible = false;
} }
visibleChildMenu = null; visibleChildMenu = null;
* Recursively hide all parent menus. * Recursively hide all parent menus.
*/ */
public void hideParents(boolean autoClosed) { public void hideParents(boolean autoClosed) {
hideParents(autoClosed, true);
}

public void hideParents(boolean autoClosed, boolean animated) {
if (visibleChildMenu != null) { if (visibleChildMenu != null) {
popup.hide();
popup.hide(false, animated, animated);
setSelected(null); setSelected(null);
menuVisible = false; menuVisible = false;
} }


if (getParentMenu() != null) { if (getParentMenu() != null) {
getParentMenu().hideParents(autoClosed);
getParentMenu().hideParents(autoClosed, animated);
} }
} }


updateStyleNames(); updateStyleNames();
} }


protected void updateStyleNames() {
public void updateStyleNames() {
if (parentMenu == null) { if (parentMenu == null) {
// Style names depend on the parent menu's primary style name so // Style names depend on the parent menu's primary style name so
// don't do updates until the item has a parent // don't do updates until the item has a parent
return enabled; return enabled;
} }


private void setSeparator(boolean separator) {
public void setSeparator(boolean separator) {
isSeparator = separator; isSeparator = separator;
updateStyleNames(); updateStyleNames();
if (!separator) { if (!separator) {
this.id = id; this.id = id;
} }


public void setDescription(String description) {
this.description = description;
}

public void setDescriptionContentMode(
ContentMode descriptionContentMode) {
this.descriptionContentMode = descriptionContentMode;
}
} }


/** /**
LazyCloser.schedule(); LazyCloser.schedule();
} }


private VMenuBar getRoot() {
protected VMenuBar getRoot() {
VMenuBar root = this; VMenuBar root = this;


while (root.getParentMenu() != null) { while (root.getParentMenu() != null) {

+ 11
- 9
client/src/main/java/com/vaadin/client/ui/VOverlay.java Переглянути файл

super(autoHide, modal); 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 * Get the {@link ApplicationConnection} that this overlay belongs to. If
* it's not set, {@link #getOwner()} is used to figure it out. * it's not set, {@link #getOwner()} is used to figure it out.
overlayContainerLabel); overlayContainerLabel);
} }


/**
* Sets the {@link ApplicationConnection} that this overlay belongs to.
*
* @see #getApplicationConnection()
*
* @param ac
* the connection
*/
public void setApplicationConnection(ApplicationConnection ac) {
this.ac = ac;
}
} }

Завантаження…
Відмінити
Зберегти