import com.itmill.toolkit.ui.Link;
import com.itmill.toolkit.ui.Panel;
import com.itmill.toolkit.ui.VerticalLayout;
+import com.itmill.toolkit.ui.Window;
import com.itmill.toolkit.ui.Button.ClickEvent;
public class FeatureView extends HorizontalLayout {
private VerticalLayout controls;
- private ActiveLink srcWin;
+ private ActiveLink showSrc;
private HashMap<Feature, Component> exampleCache = new HashMap<Feature, Component>();
private Feature currentFeature;
+ private Window srcWindow;
+
public FeatureView() {
setWidth("100%");
controlButtons.addComponent(new Label("|"));
- srcWin = new ActiveLink();
- srcWin
+ showSrc = new ActiveLink();
+ showSrc
.setDescription("Right / middle / ctrl / shift -click for browser window/tab");
- srcWin.addListener(new LinkActivatedListener() {
+ showSrc.addListener(new LinkActivatedListener() {
public void linkActivated(LinkActivatedEvent event) {
if (!event.isLinkOpened()) {
- ((SamplerWindow) getWindow()).showSource(currentFeature
- .getSource());
+ showSource(currentFeature.getSource());
}
}
});
- srcWin.setCaption(MSG_SHOW_SRC);
- srcWin.addStyleName("showcode");
- srcWin.setTargetBorder(Link.TARGET_BORDER_NONE);
- controlButtons.addComponent(srcWin);
+ showSrc.setCaption(MSG_SHOW_SRC);
+ showSrc.addStyleName("showcode");
+ showSrc.setTargetBorder(Link.TARGET_BORDER_NONE);
+ controlButtons.addComponent(showSrc);
+
+ }
+ public void showSource(String source) {
+ if (srcWindow == null) {
+ srcWindow = new Window("Java™ source");
+ ((VerticalLayout) srcWindow.getLayout()).setSizeUndefined();
+ srcWindow.setWidth("70%");
+ srcWindow.setHeight("60%");
+ srcWindow.setPositionX(100);
+ srcWindow.setPositionY(100);
+ }
+ srcWindow.removeAllComponents();
+ srcWindow.addComponent(new CodeLabel(source));
+
+ if (srcWindow.getParent() == null) {
+ getWindow().addWindow(srcWindow);
+ }
}
private void resetExample() {
{ // open src in new window -link
String path = SamplerApplication.getPathFor(currentFeature);
- srcWin.setTargetName(path);
- srcWin.setResource(new ExternalResource(getApplication()
+ showSrc.setTargetName(path);
+ showSrc.setResource(new ExternalResource(getApplication()
.getURL()
+ "src/" + path));
}
Button previousSample;
Button nextSample;
- private Window srcWindow = null;
-
SamplerWindow() {
// Main top/expanded-bottom layout
VerticalLayout mainExpand = new VerticalLayout();
});
}
- public void showSource(String source) {
- hideSource();
- Window w = new Window("Java™ source");
- ((VerticalLayout) w.getLayout()).setSizeUndefined();
- w.setWidth("70%");
- w.setHeight("60%");
- w.setPositionX(100);
- w.setPositionY(100);
- w.addComponent(new CodeLabel(source));
- addWindow(w);
- srcWindow = w;
- }
-
- public void hideSource() {
- if (srcWindow != null) {
- removeWindow(srcWindow);
- srcWindow = null;
+ @SuppressWarnings("unchecked")
+ public void removeSubwindows() {
+ Collection<Window> wins = getChildWindows();
+ if (null != wins) {
+ for (Window w : wins) {
+ removeWindow(w);
+ }
}
}
* the Feature(Set) to show
*/
public void setFeature(Feature f) {
- hideSource();
+ removeSubwindows();
currentFeature.setValue(f);
String path = getPathFor(f);
webAnalytics.trackPageview(path);