]> source.dussan.org Git - vaadin-framework.git/commitdiff
Fixed #1393 (Focusable has id which is obsolete)
authorJani Laakso <jani.laakso@itmill.com>
Fri, 8 Feb 2008 13:38:35 +0000 (13:38 +0000)
committerJani Laakso <jani.laakso@itmill.com>
Fri, 8 Feb 2008 13:38:35 +0000 (13:38 +0000)
svn changeset:3752/svn branch:trunk

src/com/itmill/toolkit/ui/AbstractField.java
src/com/itmill/toolkit/ui/Component.java
src/com/itmill/toolkit/ui/Select.java
src/com/itmill/toolkit/ui/Table.java
src/com/itmill/toolkit/ui/Tree.java
src/com/itmill/toolkit/ui/Upload.java
src/com/itmill/toolkit/ui/Window.java

index d85ab2014ef76111d3d76e78c5e5e5d976773922..9d926f0e7f5bba06d4550882cdd3d34eee9a2de9 100644 (file)
@@ -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
index 032f45c283074ec76b32b11fa17fbe0c040d2278..e500d1725525bbc536b2b5f8aab444a40fd02e06 100644 (file)
@@ -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();
-
     }
 }
index de09f6149db5e329ce4fa47cf6a56b4cb7678520..9acbb3f7d2632aedca0e936d14e332095f100a59 100644 (file)
@@ -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());
index 580fadc39907fdbaa7ea73721e9d8d7f77d18104..5f7e7180cd1318e11387a2d0d870ed2f84ae5528 100644 (file)
@@ -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());
index d617e3118d9f351fdfe693171016c91f505513c1..25edb814d91797635a8d62fc627d862ed234aecf 100644 (file)
@@ -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);
index d15bf44c0e2d51ee0ffc2c87adbc98fae1eafcd8..10123d3d5e2050424598b5df98d0b4ed269dcb6d 100644 (file)
@@ -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;
index 2eca2e0a409f29763440a2d547e131ef10c5c60c..a042a30776ccb33b80b9ee364817798b6c400ccc 100644 (file)
@@ -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).