Author: jawi
Date: Sun Apr 1 13:01:27 2012
New Revision: 1308093
URL: http://svn.apache.org/viewvc?rev=1308093&view=rev
Log:
ACE-241: give user feedback when the creation of a feature, distribution or target failed.
Modified:
ace/trunk/ace-webui-vaadin/src/main/java/org/apache/ace/webui/vaadin/GenericAddWindow.java
ace/trunk/ace-webui-vaadin/src/main/java/org/apache/ace/webui/vaadin/VaadinClient.java
Modified: ace/trunk/ace-webui-vaadin/src/main/java/org/apache/ace/webui/vaadin/GenericAddWindow.java
URL: http://svn.apache.org/viewvc/ace/trunk/ace-webui-vaadin/src/main/java/org/apache/ace/webui/vaadin/GenericAddWindow.java?rev=1308093&r1=1308092&r2=1308093&view=diff
==============================================================================
--- ace/trunk/ace-webui-vaadin/src/main/java/org/apache/ace/webui/vaadin/GenericAddWindow.java
(original)
+++ ace/trunk/ace-webui-vaadin/src/main/java/org/apache/ace/webui/vaadin/GenericAddWindow.java
Sun Apr 1 13:01:27 2012
@@ -1,76 +1,129 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.ace.webui.vaadin;
import com.vaadin.ui.Alignment;
import com.vaadin.ui.Button;
+import com.vaadin.ui.Button.ClickEvent;
+import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.TextField;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.Window;
-import com.vaadin.ui.Button.ClickEvent;
-
-@SuppressWarnings("serial")
-public class GenericAddWindow extends Window {
- public interface AddFunction {
- void create(String name, String description);
- };
+public abstract class GenericAddWindow extends Window {
- private final Window m_main;
private final TextField m_name;
- private AddFunction m_addFunction;
+ private final TextField m_description;
- public GenericAddWindow(final Window main, String caption) {
- m_main = main;
+ public GenericAddWindow(String caption) {
+ this(caption, "Name");
+ }
+ public GenericAddWindow(String caption, String fieldName) {
setModal(true);
setWidth("15em");
setCaption(caption);
- // Configure the windws layout; by default a VerticalLayout
- VerticalLayout layout = (VerticalLayout) getContent();
- layout.setMargin(true);
- layout.setSpacing(true);
-
- m_name = new TextField("name");
- final TextField description = new TextField("description");
+ m_name = new TextField(fieldName);
+ m_name.setWidth("100%");
- layout.addComponent(m_name);
- layout.addComponent(description);
+ m_description = new TextField("Description");
+ m_description.setWidth("100%");
+
+ VerticalLayout fields = new VerticalLayout();
+ fields.setSpacing(true);
+ fields.addComponent(m_name);
+ fields.addComponent(m_description);
- Button close = new Button("Ok", new Button.ClickListener() {
- // inline click-listener
+ Button okButton = new Button("Ok", new Button.ClickListener() {
public void buttonClick(ClickEvent event) {
- // close the window by removing it from the parent window
- (getParent()).removeWindow(GenericAddWindow.this);
- // create the feature
- if (m_addFunction != null) {
- m_addFunction.create((String) m_name.getValue(),
- (String) description.getValue());
+ try {
+ onOk((String) m_name.getValue(), (String) m_description.getValue());
+ closeDialog();
+ }
+ catch (Exception e) {
+ handleError(e);
}
}
});
+
+ Button cancelButton = new Button("Cancel", new Button.ClickListener() {
+ public void buttonClick(ClickEvent event) {
+ closeDialog();
+ }
+ });
+
+ HorizontalLayout buttonBar = new HorizontalLayout();
+ buttonBar.setSpacing(true);
+ buttonBar.addComponent(okButton);
+ buttonBar.addComponent(cancelButton);
+
+ VerticalLayout layout = (VerticalLayout) getContent();
+ layout.setMargin(true);
+ layout.setSpacing(true);
+ layout.addComponent(fields);
+ layout.addComponent(buttonBar);
+
// The components added to the window are actually added to the window's
// layout; you can use either. Alignments are set using the layout
- layout.addComponent(close);
- layout.setComponentAlignment(close, Alignment.BOTTOM_RIGHT);
- }
-
- public void setOkListeren(AddFunction addFunction) {
- m_addFunction = addFunction;
+ layout.setComponentAlignment(buttonBar, Alignment.BOTTOM_RIGHT);
}
- public void show() {
+ public void show(final Window window) {
if (getParent() != null) {
// window is already showing
- m_main.getWindow().showNotification("Window is already open");
+ window.showNotification("Window is already open");
}
else {
- // Open the subwindow by adding it to the parent
- // window
- m_main.getWindow().addWindow(this);
+ // Open the subwindow by adding it to the parent window
+ window.addWindow(this);
}
setRelevantFocus();
}
+ /**
+ * Closes this dialog by removing it from the parent window.
+ */
+ void closeDialog() {
+ // close the window by removing it from the parent window
+ getParent().removeWindow(this);
+ }
+
+ /**
+ * Called when the user acknowledges this window by pressing Ok.
+ *
+ * @param name the value of the name field;
+ * @param description the value of the description field.
+ * @throws Exception in case the creation failed.
+ */
+ protected abstract void onOk(String name, String description) throws Exception;
+
+ /**
+ * Called when the {@link #onOk(String, String)} method failed with an exception.
+ *
+ * @param e the exception to handle, never <code>null</code>.
+ */
+ protected abstract void handleError(Exception e);
+
+ /**
+ * Sets the focus to the name field.
+ */
private void setRelevantFocus() {
m_name.focus();
}
Modified: ace/trunk/ace-webui-vaadin/src/main/java/org/apache/ace/webui/vaadin/VaadinClient.java
URL: http://svn.apache.org/viewvc/ace/trunk/ace-webui-vaadin/src/main/java/org/apache/ace/webui/vaadin/VaadinClient.java?rev=1308093&r1=1308092&r2=1308093&view=diff
==============================================================================
--- ace/trunk/ace-webui-vaadin/src/main/java/org/apache/ace/webui/vaadin/VaadinClient.java
(original)
+++ ace/trunk/ace-webui-vaadin/src/main/java/org/apache/ace/webui/vaadin/VaadinClient.java
Sun Apr 1 13:01:27 2012
@@ -90,6 +90,7 @@ import com.vaadin.ui.ProgressIndicator;
import com.vaadin.ui.Table;
import com.vaadin.ui.Table.TableTransferable;
import com.vaadin.ui.Window;
+import com.vaadin.ui.Window.Notification;
/*
@@ -919,14 +920,17 @@ public class VaadinClient extends com.va
Button button = new Button("Add Feature...");
button.addListener(new Button.ClickListener() {
public void buttonClick(ClickEvent event) {
- GenericAddWindow addFeatureWindow = new GenericAddWindow(main, "Add Feature");
- addFeatureWindow.setOkListeren(new GenericAddWindow.AddFunction() {
-
- public void create(String name, String description) {
+ GenericAddWindow addFeatureWindow = new GenericAddWindow("Add Feature") {
+ public void onOk(String name, String description) {
createFeature(name, description);
}
- });
- addFeatureWindow.show();
+
+ public void handleError(Exception e) {
+ // ACE-241: notify user when the feature-creation failed!
+ main.showNotification("Failed to add new feature!", "<br/>Reason:
" + e.getMessage(), Notification.TYPE_ERROR_MESSAGE);
+ }
+ };
+ addFeatureWindow.show(main);
}
});
return button;
@@ -943,14 +947,17 @@ public class VaadinClient extends com.va
Button button = new Button("Add Distribution...");
button.addListener(new Button.ClickListener() {
public void buttonClick(ClickEvent event) {
- GenericAddWindow addDistributionWindow = new GenericAddWindow(main, "Add
Distribution");
- addDistributionWindow.setOkListeren(new GenericAddWindow.AddFunction() {
-
- public void create(String name, String description) {
+ GenericAddWindow addDistributionWindow = new GenericAddWindow("Add Distribution")
{
+ public void onOk(String name, String description) {
createDistribution(name, description);
}
- });
- addDistributionWindow.show();
+
+ public void handleError(Exception e) {
+ // ACE-241: notify user when the distribution-creation failed!
+ main.showNotification("Failed to add new distribution!", "<br/>Reason:
" + e.getMessage(), Notification.TYPE_ERROR_MESSAGE);
+ }
+ };
+ addDistributionWindow.show(main);
}
});
@@ -968,14 +975,17 @@ public class VaadinClient extends com.va
Button button = new Button("Add target...");
button.addListener(new Button.ClickListener() {
public void buttonClick(ClickEvent event) {
- GenericAddWindow addTargetWindow = new GenericAddWindow(main, "Add Target");
- addTargetWindow.setOkListeren(new GenericAddWindow.AddFunction() {
-
- public void create(String name, String description) {
- createTarget(name, description);
+ GenericAddWindow addTargetWindow = new GenericAddWindow("Add Target", "Identifier")
{
+ public void onOk(String id, String description) {
+ createTarget(id, description);
}
- });
- addTargetWindow.show();
+
+ public void handleError(Exception e) {
+ // ACE-241: notify user when the target-creation failed!
+ main.showNotification("Failed to add new target!", "<br/>Reason:
" + e.getMessage(), Notification.TYPE_ERROR_MESSAGE);
+ }
+ };
+ addTargetWindow.show(main);
}
});
return button;
|