aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc Englund <marc.englund@itmill.com>2009-02-19 09:15:08 +0000
committerMarc Englund <marc.englund@itmill.com>2009-02-19 09:15:08 +0000
commit15e294af28513c2163fe127b8493060b9317eaa6 (patch)
tree35ab251c9e83cdf4600df50b84a73d267f8b8064
parent929f49bb75b3a5bbb32a3e226dfcf0997b16d9ee (diff)
downloadvaadin-framework-15e294af28513c2163fe127b8493060b9317eaa6.tar.gz
vaadin-framework-15e294af28513c2163fe127b8493060b9317eaa6.zip
Better window handing for Sampler, so that samples can open subwindows.
svn changeset:6902/svn branch:trunk
-rw-r--r--src/com/itmill/toolkit/demo/sampler/FeatureView.java43
-rw-r--r--src/com/itmill/toolkit/demo/sampler/SamplerApplication.java28
2 files changed, 39 insertions, 32 deletions
diff --git a/src/com/itmill/toolkit/demo/sampler/FeatureView.java b/src/com/itmill/toolkit/demo/sampler/FeatureView.java
index 797b336720..f32e122d51 100644
--- a/src/com/itmill/toolkit/demo/sampler/FeatureView.java
+++ b/src/com/itmill/toolkit/demo/sampler/FeatureView.java
@@ -14,6 +14,7 @@ import com.itmill.toolkit.ui.Label;
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 {
@@ -25,12 +26,14 @@ 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%");
@@ -71,25 +74,41 @@ public class FeatureView extends HorizontalLayout {
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() {
@@ -143,8 +162,8 @@ public class FeatureView extends HorizontalLayout {
{ // 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));
}
diff --git a/src/com/itmill/toolkit/demo/sampler/SamplerApplication.java b/src/com/itmill/toolkit/demo/sampler/SamplerApplication.java
index fbd87748ad..7ce97ffade 100644
--- a/src/com/itmill/toolkit/demo/sampler/SamplerApplication.java
+++ b/src/com/itmill/toolkit/demo/sampler/SamplerApplication.java
@@ -161,8 +161,6 @@ public class SamplerApplication extends Application {
Button previousSample;
Button nextSample;
- private Window srcWindow = null;
-
SamplerWindow() {
// Main top/expanded-bottom layout
VerticalLayout mainExpand = new VerticalLayout();
@@ -253,23 +251,13 @@ public class SamplerApplication extends Application {
});
}
- 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);
+ }
}
}
@@ -280,7 +268,7 @@ public class SamplerApplication extends Application {
* the Feature(Set) to show
*/
public void setFeature(Feature f) {
- hideSource();
+ removeSubwindows();
currentFeature.setValue(f);
String path = getPathFor(f);
webAnalytics.trackPageview(path);