From: Jani Laakso Date: Fri, 8 Feb 2008 13:38:35 +0000 (+0000) Subject: Fixed #1393 (Focusable has id which is obsolete) X-Git-Tag: 6.7.0.beta1~5076 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=3c447bac504ddc6770e1ad15f38e4b0bec165851;p=vaadin-framework.git Fixed #1393 (Focusable has id which is obsolete) svn changeset:3752/svn branch:trunk --- diff --git a/src/com/itmill/toolkit/ui/AbstractField.java b/src/com/itmill/toolkit/ui/AbstractField.java index d85ab2014e..9d926f0e7f 100644 --- a/src/com/itmill/toolkit/ui/AbstractField.java +++ b/src/com/itmill/toolkit/ui/AbstractField.java @@ -102,11 +102,6 @@ public abstract class AbstractField extends AbstractComponent implements Field, */ private int tabIndex = 0; - /** - * Unique focusable id. - */ - private long focusableId = -1; - /** * Required field. */ @@ -114,21 +109,12 @@ public abstract class AbstractField extends AbstractComponent implements Field, /* Component basics ************************************************ */ - public AbstractField() { - focusableId = Window.getNewFocusableId(this); - } - /* * Paints the field. Don't add a JavaDoc comment here, we use the default * documentation from the implemented interface. */ public void paintContent(PaintTarget target) throws PaintException { - // Focus control id - if (focusableId > 0) { - target.addAttribute("focusid", focusableId); - } - // The tab ordering number if (tabIndex > 0) { target.addAttribute("tabindex", tabIndex); @@ -938,15 +924,6 @@ public abstract class AbstractField extends AbstractComponent implements Field, value = newValue; } - /** - * Gets the unique ID of focusable - * - * @see com.itmill.toolkit.ui.Component.Focusable#getFocusableId() - */ - public long getFocusableId() { - return focusableId; - } - /** * Notifies the component that it is connected to an application. * @@ -980,15 +957,4 @@ public abstract class AbstractField extends AbstractComponent implements Field, this.required = required; } - /** - * Free used resources. - * - * @see java.lang.Object#finalize() - */ - public void finalize() throws Throwable { - if (focusableId > -1) { - Window.removeFocusableId(focusableId); - } - super.finalize(); - } } \ No newline at end of file diff --git a/src/com/itmill/toolkit/ui/Component.java b/src/com/itmill/toolkit/ui/Component.java index 032f45c283..e500d17255 100644 --- a/src/com/itmill/toolkit/ui/Component.java +++ b/src/com/itmill/toolkit/ui/Component.java @@ -385,13 +385,5 @@ public interface Component extends Paintable, VariableOwner, Sizeable { */ public void setTabIndex(int tabIndex); - /** - * Gets the unique ID of focusable. This will be used to move input - * focus directly to this component. - * - * @return the Unique id of focusable. - */ - public long getFocusableId(); - } } diff --git a/src/com/itmill/toolkit/ui/Select.java b/src/com/itmill/toolkit/ui/Select.java index de09f6149d..9acbb3f7d2 100644 --- a/src/com/itmill/toolkit/ui/Select.java +++ b/src/com/itmill/toolkit/ui/Select.java @@ -90,11 +90,6 @@ public class Select extends AbstractSelect implements AbstractSelect.Filtering { // clear caption change listeners getCaptionChangeListener().clear(); - // Focus control id - if (getFocusableId() > 0) { - target.addAttribute("focusid", getFocusableId()); - } - // The tab ordering number if (getTabIndex() > 0) { target.addAttribute("tabindex", getTabIndex()); diff --git a/src/com/itmill/toolkit/ui/Table.java b/src/com/itmill/toolkit/ui/Table.java index 580fadc399..5f7e7180cd 100644 --- a/src/com/itmill/toolkit/ui/Table.java +++ b/src/com/itmill/toolkit/ui/Table.java @@ -1427,11 +1427,6 @@ public class Table extends AbstractSelect implements Action.Container, */ public void paintContent(PaintTarget target) throws PaintException { - // Focus control id - if (getFocusableId() > 0) { - target.addAttribute("focusid", getFocusableId()); - } - // The tab ordering number if (getTabIndex() > 0) { target.addAttribute("tabindex", getTabIndex()); diff --git a/src/com/itmill/toolkit/ui/Tree.java b/src/com/itmill/toolkit/ui/Tree.java index d617e3118d..25edb814d9 100644 --- a/src/com/itmill/toolkit/ui/Tree.java +++ b/src/com/itmill/toolkit/ui/Tree.java @@ -398,11 +398,6 @@ public class Tree extends AbstractSelect implements Container.Hierarchical, } else { getCaptionChangeListener().clear(); - // Focus control id - if (getFocusableId() > 0) { - target.addAttribute("focusid", getFocusableId()); - } - // The tab ordering number if (getTabIndex() > 0) { target.addAttribute("tabindex", getTabIndex()); @@ -489,7 +484,12 @@ public class Tree extends AbstractSelect implements Container.Hierarchical, target.addAttribute("key", key); if (isSelected(itemId)) { target.addAttribute("selected", true); - selectedKeys[keyIndex++] = key; + try { + selectedKeys[keyIndex++] = key; + } catch (Exception e) { + // TODO Fix, see TreeExample (featurebrowser) + e.printStackTrace(); + } } if (areChildrenAllowed(itemId) && isExpanded(itemId)) { target.addAttribute("expanded", true); diff --git a/src/com/itmill/toolkit/ui/Upload.java b/src/com/itmill/toolkit/ui/Upload.java index d15bf44c0e..10123d3d5e 100644 --- a/src/com/itmill/toolkit/ui/Upload.java +++ b/src/com/itmill/toolkit/ui/Upload.java @@ -17,25 +17,23 @@ import com.itmill.toolkit.terminal.UploadStream; /** * Component for uploading files from client to server. * - * The visible component consists of a file name input box and a browse - * button and an upload submit button to start uploading. + * The visible component consists of a file name input box and a browse button + * and an upload submit button to start uploading. * - * The Upload component needs a java.io.OutputStream to write the uploaded - * data. You need to implement the Upload.Receiver interface and return - * the output stream in the receiveUpload() method. + * The Upload component needs a java.io.OutputStream to write the uploaded data. + * You need to implement the Upload.Receiver interface and return the output + * stream in the receiveUpload() method. * - * You can get an event regarding starting (StartedEvent), - * progress (ProgressEvent), and finishing (FinishedEvent) of upload by - * implementing StartedListener, ProgressListener, and FinishedListener, - * respectively. The FinishedListener is called for both failed and - * succeeded uploads. If you wish to separate between these two cases, - * you can use SucceededListener (SucceededEvenet) and FailedListener - * (FailedEvent). + * You can get an event regarding starting (StartedEvent), progress + * (ProgressEvent), and finishing (FinishedEvent) of upload by implementing + * StartedListener, ProgressListener, and FinishedListener, respectively. The + * FinishedListener is called for both failed and succeeded uploads. If you wish + * to separate between these two cases, you can use SucceededListener + * (SucceededEvenet) and FailedListener (FailedEvent). * - * The upload component does not itself show upload progress, but - * you can use the ProgressIndicator for providing progress feedback - * by implementing ProgressListener and updating the indicator in - * updateProgress(). + * The upload component does not itself show upload progress, but you can use + * the ProgressIndicator for providing progress feedback by implementing + * ProgressListener and updating the indicator in updateProgress(). * * @author IT Mill Ltd. * @version @@ -64,8 +62,6 @@ public class Upload extends AbstractComponent implements Component.Focusable { */ private Receiver receiver; - private long focusableId = -1; - private boolean isUploading; private long contentLength = -1; @@ -87,14 +83,13 @@ public class Upload extends AbstractComponent implements Component.Focusable { * stream given by the Receiver. * * @param caption - * Normal component caption. You can set the caption of the - * upload submit button with setButtonCaption(). + * Normal component caption. You can set the caption of the + * upload submit button with setButtonCaption(). * @param uploadReceiver - * Receiver to call to retrieve output stream when upload - * starts. + * Receiver to call to retrieve output stream when upload + * starts. */ public Upload(String caption, Receiver uploadReceiver) { - focusableId = Window.getNewFocusableId(this); setCaption(caption); receiver = uploadReceiver; } @@ -205,8 +200,8 @@ public class Upload extends AbstractComponent implements Component.Focusable { } /** - * Interface that must be implemented by the upload receivers to provide - * the Upload component an output stream to write the uploaded data. + * Interface that must be implemented by the upload receivers to provide the + * Upload component an output stream to write the uploaded data. * * @author IT Mill Ltd. * @version @@ -716,15 +711,6 @@ public class Upload extends AbstractComponent implements Component.Focusable { this.tabIndex = tabIndex; } - /** - * Gets the unique ID of focusable. - * - * @see com.itmill.toolkit.ui.Component.Focusable#getFocusableId() - */ - public long getFocusableId() { - return focusableId; - } - /** * Sets the size of the file currently being uploaded. * @@ -738,10 +724,10 @@ public class Upload extends AbstractComponent implements Component.Focusable { * Go into upload state. This is to prevent double uploading on same * component. * - * Warning: this is an internal method used by the framework and should - * not be used by user of the Upload component. Using it results - * in the Upload component going in wrong state and not working. - * It is currently public because it is used by another class. + * Warning: this is an internal method used by the framework and should not + * be used by user of the Upload component. Using it results in the Upload + * component going in wrong state and not working. It is currently public + * because it is used by another class. */ public void startUpload() { if (isUploading) { @@ -753,8 +739,8 @@ public class Upload extends AbstractComponent implements Component.Focusable { /** * Go into state where new uploading can begin. * - * Warning: this is an internal method used by the framework and should - * not be used by user of the Upload component. + * Warning: this is an internal method used by the framework and should not + * be used by user of the Upload component. */ public void endUpload() { isUploading = false; diff --git a/src/com/itmill/toolkit/ui/Window.java b/src/com/itmill/toolkit/ui/Window.java index 2eca2e0a40..a042a30776 100644 --- a/src/com/itmill/toolkit/ui/Window.java +++ b/src/com/itmill/toolkit/ui/Window.java @@ -4,12 +4,10 @@ package com.itmill.toolkit.ui; -import java.lang.ref.WeakReference; import java.lang.reflect.Method; import java.net.MalformedURLException; import java.net.URL; import java.util.Collections; -import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.LinkedList; @@ -494,14 +492,6 @@ public class Window extends Panel implements URIHandler, ParameterHandler { // Window closing target.addVariable(this, "close", false); - // Sets the focused component - if (focusedComponent != null) { - target.addVariable(this, "focused", "" - + focusedComponent.getFocusableId()); - } else { - target.addVariable(this, "focused", ""); - } - // Paint subwindows for (final Iterator i = subwindows.iterator(); i.hasNext();) { final Window w = (Window) i.next(); @@ -833,17 +823,6 @@ public class Window extends Panel implements URIHandler, ParameterHandler { public void changeVariables(Object source, Map variables) { super.changeVariables(source, variables); - // Gets the focused component - final String focusedId = (String) variables.get("focused"); - if (focusedId != null) { - try { - final long id = Long.parseLong(focusedId); - focusedComponent = Window.getFocusableById(id); - } catch (final NumberFormatException ignored) { - // We ignore invalid focusable ids - } - } - // Positioning final Integer positionx = (Integer) variables.get("positionx"); if (positionx != null) { @@ -915,57 +894,6 @@ public class Window extends Panel implements URIHandler, ParameterHandler { } } - /* Focusable id generator ****************************************** */ - - private static long lastUsedFocusableId = 0; - - private static Map focusableComponents = new HashMap(); - - /** - * Gets an id for focusable component. - * - * @param focusable - * the focused component. - */ - public static long getNewFocusableId(Component.Focusable focusable) { - final long newId = ++lastUsedFocusableId; - final WeakReference ref = new WeakReference(focusable); - focusableComponents.put(new Long(newId), ref); - return newId; - } - - /** - * Maps the focusable id back to focusable component. - * - * @param focusableId - * the Focused Id. - * @return the focusable Id. - */ - public static Component.Focusable getFocusableById(long focusableId) { - final WeakReference ref = (WeakReference) focusableComponents - .get(new Long(focusableId)); - if (ref != null) { - final Object o = ref.get(); - if (o != null) { - return (Component.Focusable) o; - } - } - return null; - } - - /** - * Releases the focusable component id when not used anymore. - * - * @param focusableId - * the focusable Id to remove. - */ - public static void removeFocusableId(long focusableId) { - final Long id = new Long(focusableId); - final WeakReference ref = (WeakReference) focusableComponents.get(id); - ref.clear(); - focusableComponents.remove(id); - } - /** * Gets the distance of Window left border in pixels from left border of the * containing (main window).