From de70ee2f0132661c9bf771cb66a40d1961073037 Mon Sep 17 00:00:00 2001 From: Marc Englund Date: Tue, 11 Feb 2014 10:15:07 +0200 Subject: Font icon support (#13152) Renamed Icon to ImageIcon Change-Id: I608815f17a3651b205fed81b5294385df0d68802 Extracted the abstract client-side Icon class Change-Id: Ic32e270595a5796d0bbd1dd31f34282b56672aa9 Created the FontIcon class Change-Id: Iad13871e7bf1807dee2c538c76306d4620191f5e Renamed AbstractComponentConnector.getIcon to getIconUri Change-Id: I6953ab79661993b561655d483c1bd013b66407f3 Added the AbstractComponentConnector.getIcon method Change-Id: I6fb91dc643fb09da3ba53666b1a8a289901702e3 Refactored getIcon Change-Id: Ibae39e66d0fb8449e20ac5209eb8c18b6ada4387 Made all existing uses of Icon compatible with FontIcons Change-Id: I8f28ec5254f2e5282a887519d3f44bc1e27aba72 Initial server-side support for font icons - does not include an actual icon set yet (#13152) Change-Id: Ie6c09b17dd577c726e0efc13567749f6f4d56d8d Changed server side FontIcon URI generation to match the correct scheme Change-Id: I3628b930b310b3f285bc58a3f471e31e641d307e Initial server-side icon font (FontAwesome) with scss - to be considered placeholder for testing (#13152) Change-Id: I361e62aba0d943a736471824e149d65c7eea9c76 Changed the FontIcon URI scheme Change-Id: I15c92f6bb3d0aa0a800f3f0bfa80419979453e17 Added FontIcon support to AbstractOrderedLayoutConnector Change-Id: I3b2b45b22d29622fd888dbe922aa0cc8a718104d Added FontIcon support to table items Change-Id: Id22ce94c96a892420aab1e39663688fc9f3bc282 Added FontIcon support to OptionGroup items Change-Id: Ie08bef688f6802182ef5f8b2bf82cf8b1f9096bb Switched to openly use FontAwesome (#13152) Change-Id: I18c3325ce93915b7fd6e338c8c293a89711277bc VaadinIcons are now FontAwesome (#13152) Change-Id: I0ab2a80735cbf08b6e33d358e3e8c6a205626fc4 VCaption does not longer set icon to 0x0px if it's a FontIcon (#13152) Change-Id: Ibcd96e0f79f0adf2e217a8580d17f1cc93705710 Fixed typo in @font-face, removed .otf (#13152) Change-Id: I698ca32c560e5f198c32a6c44f7884d3030ee610 Make font icons behave more like img (display:inline-block) (#13152) Change-Id: Ic79186c90f1fc566deae1f4d8d4ba2c21d89a42e --- shared/src/com/vaadin/shared/ApplicationConstants.java | 1 + 1 file changed, 1 insertion(+) (limited to 'shared/src') diff --git a/shared/src/com/vaadin/shared/ApplicationConstants.java b/shared/src/com/vaadin/shared/ApplicationConstants.java index a81f29b77c..d54823ee60 100644 --- a/shared/src/com/vaadin/shared/ApplicationConstants.java +++ b/shared/src/com/vaadin/shared/ApplicationConstants.java @@ -35,6 +35,7 @@ public class ApplicationConstants implements Serializable { public static final String APP_PROTOCOL_PREFIX = "app://"; public static final String VAADIN_PROTOCOL_PREFIX = "vaadin://"; + public static final String FONTICON_PROTOCOL_PREFIX = "fonticon://"; public static final String PUBLISHED_PROTOCOL_NAME = "published"; public static final String PUBLISHED_PROTOCOL_PREFIX = PUBLISHED_PROTOCOL_NAME + "://"; -- cgit v1.2.3 From 09969ce1fedb3dc9cca863c393735f64bfbbedc1 Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Mon, 3 Feb 2014 21:46:06 +0200 Subject: Add change event for Upload (#13222) Change-Id: I9850888b1997104cbc493ae0882316a9d2b1cedd --- .../vaadin/client/ui/upload/UploadConnector.java | 19 +++ server/src/com/vaadin/ui/Upload.java | 92 ++++++++++++++- shared/src/com/vaadin/shared/EventId.java | 2 + .../vaadin/shared/ui/upload/UploadServerRpc.java | 30 +++++ .../tests/components/ui/MultiFileUploadTest.java | 128 +++++++++++++++++++++ 5 files changed, 270 insertions(+), 1 deletion(-) create mode 100644 shared/src/com/vaadin/shared/ui/upload/UploadServerRpc.java create mode 100644 uitest/src/com/vaadin/tests/components/ui/MultiFileUploadTest.java (limited to 'shared/src') diff --git a/client/src/com/vaadin/client/ui/upload/UploadConnector.java b/client/src/com/vaadin/client/ui/upload/UploadConnector.java index 989a913adc..03f1a2802c 100644 --- a/client/src/com/vaadin/client/ui/upload/UploadConnector.java +++ b/client/src/com/vaadin/client/ui/upload/UploadConnector.java @@ -16,13 +16,17 @@ package com.vaadin.client.ui.upload; +import com.google.gwt.event.dom.client.ChangeEvent; +import com.google.gwt.event.dom.client.ChangeHandler; import com.vaadin.client.ApplicationConnection; import com.vaadin.client.Paintable; import com.vaadin.client.UIDL; import com.vaadin.client.ui.AbstractComponentConnector; import com.vaadin.client.ui.VUpload; +import com.vaadin.shared.EventId; import com.vaadin.shared.ui.Connect; import com.vaadin.shared.ui.upload.UploadClientRpc; +import com.vaadin.shared.ui.upload.UploadServerRpc; import com.vaadin.ui.Upload; @Connect(Upload.class) @@ -38,6 +42,21 @@ public class UploadConnector extends AbstractComponentConnector implements }); } + @Override + protected void init() { + super.init(); + + getWidget().fu.addChangeHandler(new ChangeHandler() { + @Override + public void onChange(ChangeEvent event) { + if (hasEventListener(EventId.CHANGE)) { + getRpcProxy(UploadServerRpc.class).change( + getWidget().fu.getFilename()); + } + } + }); + } + @Override public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { if (!isRealUpdate(uidl)) { diff --git a/server/src/com/vaadin/ui/Upload.java b/server/src/com/vaadin/ui/Upload.java index 98f5d2ded9..c8d9f3ff09 100644 --- a/server/src/com/vaadin/ui/Upload.java +++ b/server/src/com/vaadin/ui/Upload.java @@ -28,7 +28,10 @@ import com.vaadin.server.NoOutputStreamException; import com.vaadin.server.PaintException; import com.vaadin.server.PaintTarget; import com.vaadin.server.StreamVariable.StreamingProgressEvent; +import com.vaadin.shared.EventId; import com.vaadin.shared.ui.upload.UploadClientRpc; +import com.vaadin.shared.ui.upload.UploadServerRpc; +import com.vaadin.util.ReflectTools; /** * Component for uploading files from client to server. @@ -113,9 +116,16 @@ public class Upload extends AbstractComponent implements Component.Focusable, * The receiver must be set before performing an upload. */ public Upload() { + registerRpc(new UploadServerRpc() { + @Override + public void change(String filename) { + fireEvent(new ChangeEvent(Upload.this, filename)); + } + }); } public Upload(String caption, Receiver uploadReceiver) { + this(); setCaption(caption); receiver = uploadReceiver; } @@ -485,6 +495,42 @@ public class Upload extends AbstractComponent implements Component.Focusable, } + /** + * Upload.ChangeEvent event is sent when the value (filename) of the upload + * changes. + * + * @since 7.2 + */ + public static class ChangeEvent extends Component.Event { + + private final String filename; + + public ChangeEvent(Upload source, String filename) { + super(source); + this.filename = filename; + } + + /** + * Uploads where the event occurred. + * + * @return the Source of the event. + */ + @Override + public Upload getSource() { + return (Upload) super.getSource(); + } + + /** + * Gets the file name. + * + * @return the filename. + */ + public String getFilename() { + return filename; + } + + } + /** * Receives the events when the upload starts. * @@ -553,6 +599,25 @@ public class Upload extends AbstractComponent implements Component.Focusable, public void uploadSucceeded(SucceededEvent event); } + /** + * Listener for {@link ChangeEvent} + * + * @since 7.2 + */ + public interface ChangeListener extends Serializable { + + Method FILENAME_CHANGED = ReflectTools.findMethod(ChangeListener.class, + "filenameChanged", ChangeEvent.class); + + /** + * A file has been selected but upload has not yet started. + * + * @param event + * the change event + */ + public void filenameChanged(ChangeEvent event); + } + /** * Adds the upload started event listener. * @@ -739,6 +804,27 @@ public class Upload extends AbstractComponent implements Component.Focusable, } } + /** + * Adds a filename change event listener + * + * @param listener + * the Listener to add + */ + public void addChangeListener(ChangeListener listener) { + super.addListener(EventId.CHANGE, ChangeEvent.class, listener, + ChangeListener.FILENAME_CHANGED); + } + + /** + * Removes a filename change event listener + * + * @param listener + * the listener to be removed + */ + public void removeChangeListener(ChangeListener listener) { + super.removeListener(EventId.CHANGE, ChangeEvent.class, listener); + } + /** * @deprecated As of 7.0, replaced by * {@link #removeProgressListener(ProgressListener)} @@ -1040,7 +1126,11 @@ public class Upload extends AbstractComponent implements Component.Focusable, @Override public OutputStream getOutputStream() { - OutputStream receiveUpload = receiver.receiveUpload( + if (getReceiver() == null) { + throw new IllegalStateException( + "Upload cannot be performed without a receiver set"); + } + OutputStream receiveUpload = getReceiver().receiveUpload( lastStartedEvent.getFileName(), lastStartedEvent.getMimeType()); lastStartedEvent = null; diff --git a/shared/src/com/vaadin/shared/EventId.java b/shared/src/com/vaadin/shared/EventId.java index d669f8fa83..7cf760b885 100644 --- a/shared/src/com/vaadin/shared/EventId.java +++ b/shared/src/com/vaadin/shared/EventId.java @@ -23,4 +23,6 @@ public interface EventId extends Serializable { public static final String CLICK_EVENT_IDENTIFIER = "click"; public static final String LAYOUT_CLICK_EVENT_IDENTIFIER = "lClick"; public static final String POLL = "poll"; + public static final String CHANGE = "change"; + } diff --git a/shared/src/com/vaadin/shared/ui/upload/UploadServerRpc.java b/shared/src/com/vaadin/shared/ui/upload/UploadServerRpc.java new file mode 100644 index 0000000000..79a6778da3 --- /dev/null +++ b/shared/src/com/vaadin/shared/ui/upload/UploadServerRpc.java @@ -0,0 +1,30 @@ +/* + * Copyright 2000-2013 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.shared.ui.upload; + +import com.vaadin.shared.communication.ServerRpc; + +public interface UploadServerRpc extends ServerRpc { + + /** + * Event sent when the file name of the upload component is changed. + * + * @param filename + * The filename + */ + void change(String filename); + +} diff --git a/uitest/src/com/vaadin/tests/components/ui/MultiFileUploadTest.java b/uitest/src/com/vaadin/tests/components/ui/MultiFileUploadTest.java new file mode 100644 index 0000000000..8f3e08335f --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/ui/MultiFileUploadTest.java @@ -0,0 +1,128 @@ +/* + * Copyright 2000-2013 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.tests.components.ui; + +import java.io.IOException; +import java.io.OutputStream; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUIWithLog; +import com.vaadin.ui.Button; +import com.vaadin.ui.Button.ClickEvent; +import com.vaadin.ui.Button.ClickListener; +import com.vaadin.ui.Upload; +import com.vaadin.ui.Upload.ChangeEvent; +import com.vaadin.ui.Upload.ChangeListener; +import com.vaadin.ui.Upload.FailedEvent; +import com.vaadin.ui.Upload.FailedListener; +import com.vaadin.ui.Upload.Receiver; +import com.vaadin.ui.Upload.SucceededEvent; +import com.vaadin.ui.Upload.SucceededListener; +import com.vaadin.ui.VerticalLayout; + +public class MultiFileUploadTest extends AbstractTestUIWithLog { + + private ChangeListener changeListener = new ChangeListener() { + + @Override + public void filenameChanged(ChangeEvent event) { + if (event.getFilename().equals("")) { + removeUpload(event.getSource()); + } else { + addUpload(); + } + + } + }; + private VerticalLayout uploadsLayout = new VerticalLayout(); + + @Override + protected void setup(VaadinRequest request) { + getPage().getStyles().add( + ".v-upload-hidden-button .v-button {display:none};"); + addUpload(); + addComponent(uploadsLayout); + addComponent(new Button("Upload files", new ClickListener() { + + @Override + public void buttonClick(ClickEvent event) { + for (Upload u : getUploads()) { + u.submitUpload(); + } + } + })); + } + + protected Iterable getUploads() { + return (Iterable) uploadsLayout; + } + + protected void removeUpload(Upload source) { + uploadsLayout.removeComponent(source); + + } + + protected void addUpload() { + Upload upload = createUpload(); + upload.addSucceededListener(new SucceededListener() { + + @Override + public void uploadSucceeded(SucceededEvent event) { + log("Upload of " + event.getFilename() + " complete"); + uploadsLayout.removeComponent(event.getUpload()); + } + }); + + upload.addFailedListener(new FailedListener() { + @Override + public void uploadFailed(FailedEvent event) { + log("Upload of " + event.getFilename() + " FAILED"); + } + }); + + upload.setReceiver(new Receiver() { + @Override + public OutputStream receiveUpload(String filename, String mimeType) { + return new OutputStream() { + @Override + public void write(int arg0) throws IOException { + + } + }; + } + }); + upload.setStyleName("hidden-button"); + uploadsLayout.addComponent(upload); + + } + + private Upload createUpload() { + Upload upload = new Upload(); + upload.addChangeListener(changeListener); + return upload; + } + + @Override + protected String getTestDescription() { + return "Tests that an Upload change event can be used to create a multiple file upload component"; + } + + @Override + protected Integer getTicketNumber() { + return 13222; + } + +} -- cgit v1.2.3