"Show used connectors and how to optimize widgetset");
private final Button showHierarchy = new DebugButton(Icon.HIERARCHY,
"Show the connector hierarchy tree");
+ private final Button generateDesign = new DebugButton(Icon.SHOW_DESIGN,
+ "Generate a declarative design for the given component sub tree");
private HandlerRegistration highlightModeRegistration = null;
+ public interface FindHandler {
+
+ /**
+ * Called when the user hovers over a connector, which is highlighted.
+ * Also called when hovering outside the tree, e.g. over the debug
+ * console, but in this case the connector is null
+ *
+ * @param connector
+ */
+ void onHover(ComponentConnector connector);
+
+ /**
+ * Called when the user clicks on a highlighted connector.
+ *
+ * @param connector
+ */
+ void onSelected(ComponentConnector connector);
+
+ }
+
+ private FindHandler inspectComponent = new FindHandler() {
+
+ @Override
+ public void onHover(ComponentConnector connector) {
+ if (connector == null) {
+ infoPanel.clear();
+ } else {
+ printState(connector, false);
+ }
+ }
+
+ @Override
+ public void onSelected(ComponentConnector connector) {
+ stopFind();
+ printState(connector, true);
+ }
+
+ };
+ private FindHandler showComponentDesign = new FindHandler() {
+
+ @Override
+ public void onHover(ComponentConnector connector) {
+ Highlight.showOnly(connector);
+ }
+
+ @Override
+ public void onSelected(ComponentConnector connector) {
+ stopFind();
+ connector.getConnection().getUIConnector()
+ .showServerDesign(connector);
+ content.setWidget(new HTML(
+ "Design file for component sent to server log"));
+ }
+
+ };
+
+ private FindHandler activeFindHandler;
+
public HierarchySection() {
controls.add(showHierarchy);
showHierarchy.setStylePrimaryName(VDebugWindow.STYLENAME_BUTTON);
find.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
- toggleFind();
+ toggleFind(inspectComponent);
}
});
}
});
+ controls.add(generateDesign);
+ generateDesign.setStylePrimaryName(VDebugWindow.STYLENAME_BUTTON);
+ generateDesign.addClickHandler(new ClickHandler() {
+ @Override
+ public void onClick(ClickEvent event) {
+ content.setWidget(new HTML(
+ "Select a layout or component to generate the declarative design"));
+ toggleFind(showComponentDesign);
+ }
+ });
+
hierarchyPanel.addListener(new SelectConnectorListener() {
@Override
public void select(ServerConnector connector, Element element) {
+ showHierarchy.getTitle() + "<br/>" + find.getHTML() + " "
+ find.getTitle() + "<br/>" + analyze.getHTML() + " "
+ analyze.getTitle() + "<br/>" + generateWS.getHTML() + " "
- + generateWS.getTitle() + "<br/>");
+ + generateWS.getTitle() + "<br/>" + generateDesign.getHTML()
+ + " " + generateDesign.getTitle() + "<br/>");
info.setStyleName(VDebugWindow.STYLENAME + "-info");
helpPanel.add(info);
}
// NOP
}
+ private boolean isFindMode(FindHandler handler) {
+ return activeFindHandler == handler;
+ }
+
private boolean isFindMode() {
- return (highlightModeRegistration != null);
+ return (activeFindHandler != null);
}
- private void toggleFind() {
+ private void toggleFind(FindHandler handler) {
if (isFindMode()) {
- stopFind();
+ // Currently finding something
+ if (isFindMode(handler)) {
+ // Toggle off, stop finding
+ stopFind();
+ return;
+ } else {
+ // Stop finding something else, start finding this
+ stopFind();
+ startFind(handler);
+ }
} else {
- startFind();
+ // Not currently finding anything
+ startFind(handler);
}
}
- private void startFind() {
+ private void startFind(FindHandler handler) {
+ if (isFindMode()) {
+ stopFind();
+ }
Highlight.hideAll();
- if (!isFindMode()) {
- highlightModeRegistration = Event
- .addNativePreviewHandler(highlightModeHandler);
+
+ highlightModeRegistration = Event
+ .addNativePreviewHandler(highlightModeHandler);
+ activeFindHandler = handler;
+ if (handler == inspectComponent) {
find.addStyleDependentName(VDebugWindow.STYLENAME_ACTIVE);
+ } else if (handler == showComponentDesign) {
+ generateDesign.addStyleDependentName(VDebugWindow.STYLENAME_ACTIVE);
}
+
}
+ /**
+ * Stop any current find operation, regardless of the handler
+ */
private void stopFind() {
- if (isFindMode()) {
- highlightModeRegistration.removeHandler();
- highlightModeRegistration = null;
- find.removeStyleDependentName(VDebugWindow.STYLENAME_ACTIVE);
+ if (!isFindMode()) {
+ return;
}
+
+ highlightModeRegistration.removeHandler();
+ highlightModeRegistration = null;
+ find.removeStyleDependentName(VDebugWindow.STYLENAME_ACTIVE);
+ generateDesign.removeStyleDependentName(VDebugWindow.STYLENAME_ACTIVE);
+ activeFindHandler = null;
}
private void printState(ServerConnector connector, boolean serverDebug) {
Element eventTarget = WidgetUtil.getElementFromPoint(event
.getNativeEvent().getClientX(), event.getNativeEvent()
.getClientY());
+
if (VDebugWindow.get().getElement().isOrHasChild(eventTarget)) {
+ // Do not prevent using debug window controls
infoPanel.clear();
return;
}
RootPanel.get(), eventTarget);
}
if (connector != null) {
- printState(connector, false);
+ activeFindHandler.onHover(connector);
event.cancel();
event.consume();
event.getNativeEvent().stopPropagation();
return;
}
}
- infoPanel.clear();
+ // Not over any connector
+ activeFindHandler.onHover(null);
}
if (event.getTypeInt() == Event.ONCLICK) {
Highlight.hideAll();
event.cancel();
event.consume();
event.getNativeEvent().stopPropagation();
- stopFind();
Element eventTarget = WidgetUtil.getElementFromPoint(event
.getNativeEvent().getClientX(), event.getNativeEvent()
.getClientY());
}
if (connector != null) {
- printState(connector, true);
+ activeFindHandler.onSelected(connector);
return;
}
}
+ // Click on something else -> stop find operation
+ stopFind();
}
event.cancel();
}
package com.vaadin.ui;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
import java.net.URI;
import java.util.ArrayList;
import java.util.Collection;
import com.vaadin.shared.ui.ui.UIServerRpc;
import com.vaadin.shared.ui.ui.UIState;
import com.vaadin.ui.Component.Focusable;
+import com.vaadin.ui.declarative.Design;
import com.vaadin.util.ConnectorHelper;
import com.vaadin.util.CurrentInstance;
json.toString());
}
+ @Override
+ public void showServerDesign(Connector connector) {
+ if (!(connector instanceof Component)) {
+ getLogger().severe(
+ "Tried to output declarative design for " + connector
+ + ", which is not a component");
+ return;
+ }
+ if (connector instanceof UI) {
+ // We want to see the content of the UI, so we can add it to
+ // another UI or component container
+ connector = ((UI) connector).getContent();
+ }
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ try {
+ Design.write((Component) connector, baos);
+ getLogger().info(
+ "Design for " + connector
+ + " requested from debug window:\n"
+ + baos.toString("UTF-8"));
+ } catch (IOException e) {
+ getLogger().log(Level.WARNING,
+ "Error producing design for " + connector, e);
+ }
+
+ }
};
/**