Table: modify to remove item of table
authorjihye424.kim <jihye424.kim@samsung.com>
Thu, 20 Aug 2015 05:08:27 +0000 (14:08 +0900)
committerjihye424.kim <jihye424.kim@samsung.com>
Thu, 20 Aug 2015 05:52:46 +0000 (14:52 +0900)
Change-Id: I14fb170b349153c9c729fc78829f0394390e871c
Signed-off-by: jihye424.kim <jihye424.kim@samsung.com>
src/org/tizen/emulator/manager/ui/table/CustomScrolledComposite.java [new file with mode: 0644]
src/org/tizen/emulator/manager/ui/table/CustomScrolledCompositeLayout.java [new file with mode: 0644]
src/org/tizen/emulator/manager/ui/table/Table.java
src/org/tizen/emulator/manager/ui/table/TableItem.java

diff --git a/src/org/tizen/emulator/manager/ui/table/CustomScrolledComposite.java b/src/org/tizen/emulator/manager/ui/table/CustomScrolledComposite.java
new file mode 100644 (file)
index 0000000..5605c10
--- /dev/null
@@ -0,0 +1,409 @@
+/*
+ * Emulator Manager
+ *
+ * Copyright (C) 2015 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * JiHye Kim <jihye424.kim@samsung.com>
+ * Minkee Lee <minkee.lee@samsung.com>
+ * SeokYeon Hwang <syeon.hwang@samsung.com>
+ * Sangho Park <sangho1206.park@samsung.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ * Contributors:
+ * - S-Core Co., Ltd
+ *
+ */
+
+package org.tizen.emulator.manager.ui.table;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.DisposeEvent;
+import org.eclipse.swt.events.DisposeListener;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Listener;
+import org.eclipse.swt.widgets.Shell;
+
+import com.codeaffine.eclipse.swt.widget.scrollbar.FlatScrollBar;
+
+public class CustomScrolledComposite extends Composite {
+       Control content;
+       Listener contentListener;
+       Listener filter;
+
+       int minHeight = 0;
+       int minWidth = 0;
+       boolean expandHorizontal = false;
+       boolean expandVertical = false;
+       boolean showFocusedControl = false;
+       boolean showNextFocusedControl = true;
+
+       FlatScrollBar vBar;
+       FlatScrollBar hBar;
+
+       int scrollBarWidth = 6;
+
+       public CustomScrolledComposite(Composite parent, int style) {
+               super(parent, checkStyle(style));
+               super.setLayout(new CustomScrolledCompositeLayout());
+
+               if ((style & SWT.VERTICAL) != 0) {
+                       vBar = new FlatScrollBar(this, SWT.VERTICAL);
+                       if (vBar != null) {
+                               vBar.setVisible(false);
+                               vBar.addListener(SWT.Selection, new Listener() {
+                                       @Override
+                                       public void handleEvent(Event event) {
+                                               vScroll();
+                                       }
+                               });
+                       }
+               }
+
+               if ((style & SWT.HORIZONTAL) != 0) {
+                       hBar = new FlatScrollBar(this, SWT.HORIZONTAL);
+                       if (hBar != null) {
+                               hBar.setVisible(false);
+                               hBar.addListener(SWT.Selection, new Listener() {
+                                       @Override
+                                       public void handleEvent(Event event) {
+                                               hScroll();
+                                       }
+                               });
+                       }
+               }
+
+               contentListener = new Listener() {
+                       @Override
+                       public void handleEvent(Event event) {
+                               if (event.type == SWT.Resize) {
+                                       layout(false);
+                               }
+                       }
+               };
+
+               filter = new Listener() {
+                       @Override
+                       public void handleEvent(Event event) {
+                               if (event.type == SWT.FocusIn) {
+                                       if (!showNextFocusedControl) {
+                                               showNextFocusedControl = true;
+                                       } else if (event.widget instanceof Control) {
+                                               Control control = (Control) event.widget;
+                                               if (contains(control)) {
+                                                       showControl(control);
+                                               }
+                                       }
+                               } else {
+                                       if (event.widget instanceof Control) {
+                                               Control control = (Control) event.widget;
+                                               showNextFocusedControl = control.getDisplay().getActiveShell()
+                                                               == control.getShell();
+                                       }
+                               }
+                       }
+               };
+
+               addDisposeListener(new DisposeListener(){
+                       @Override
+                       public void widgetDisposed(DisposeEvent e) {
+                               getDisplay().removeFilter(SWT.FocusIn, filter);
+                               getDisplay().removeFilter(SWT.FocusOut, filter);
+                       }
+
+               });
+       }
+
+       static int checkStyle (int style) {
+               int mask = SWT.BORDER | SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT;
+               return style & mask;
+       }
+
+       boolean contains(Control control) {
+               if (control == null || control.isDisposed()) {
+                       return false;
+               }
+
+               Composite parent = control.getParent();
+               while (parent != null && !(parent instanceof Shell)) {
+                       if (this == parent) return true;
+                       parent = parent.getParent();
+               }
+
+               return false;
+       }
+
+       public Control getContent() {
+               return content;
+       }
+
+       public Point getOrigin() {
+               checkWidget();
+               if (content == null) {
+                       return new Point(0, 0);
+               }
+               Point location = content.getLocation();
+               return new Point(-location.x, -location.y);
+       }
+
+       public void setOrigin(Point origin) {
+               setOrigin(origin.x, origin.y);
+       }
+
+       public void setOrigin(int x, int y) {
+               checkWidget();
+               if (content == null) return;
+               if (hBar != null) {
+                       hBar.setSelection(x);
+                       hBar.notifyListeners(SWT.None);
+                       x = -hBar.getSelection();
+               } else {
+                       x = 0;
+               }
+
+               if (vBar != null) {
+                       vBar.setSelection(y);
+                       hBar.notifyListeners(SWT.None);
+                       y = -vBar.getSelection();
+               } else {
+                       y = 0;
+               }
+               content.setLocation(x, y);
+       }
+
+       public void setContent(Control content) {
+               checkWidget();
+               if (this.content != null && !this.content.isDisposed()) {
+                       this.content.removeListener(SWT.Resize, contentListener);
+                       this.content.setBounds(new Rectangle(-200, -200, 0, 0));
+               }
+
+               this.content = content;
+
+               if (this.content != null) {
+
+                       if (vBar != null) {
+                               vBar.setMaximum (0);
+                               vBar.setThumb (0);
+                               vBar.setSelection(0);
+                               vBar.notifyListeners(SWT.None);
+                       }
+                       if (hBar != null) {
+                               hBar.setMaximum (0);
+                               hBar.setThumb (0);
+                               hBar.setSelection(0);
+                               hBar.notifyListeners(SWT.None);
+                       }
+                       //content.setLocation(0, 0);
+                       layout(false);
+                       this.content.addListener(SWT.Resize, contentListener);
+               } else {
+                       if (hBar != null) {
+                               hBar.setVisible(false);
+                       }
+                       if (vBar != null) {
+                               vBar.setVisible(false);
+                       }
+               }
+       }
+
+       boolean needVScroll(Rectangle contentRect, boolean hVisible) {
+               if (vBar == null) {
+                       return false;
+               }
+               boolean result = false;
+               Rectangle hostRect = getBounds();
+               int border = getBorderWidth();
+               hostRect.height -= 2*border;
+
+               if (contentRect.height != hostRect.height) {
+                       if (hVisible && hBar != null) {
+                               hostRect.height -= hBar.getSize().y;
+                       }
+               }
+
+               if (!expandVertical && contentRect.height > hostRect.height) {
+                       result = true;
+               }
+               if (expandVertical && minHeight > hostRect.height) {
+                       result = true;
+               }
+
+               if (result) {
+                       vBar.setBounds(hostRect.width - 6, 0, 6, hostRect.height);
+               } else {
+                       vBar.setBounds(0, 0, 0, 0);
+               }
+
+               return result;
+       }
+
+       void vScroll() {
+               if (content == null) return;
+               Point location = content.getLocation ();
+               int vSelection = vBar.getSelection();
+               content.setLocation (location.x, -vSelection);
+       }
+
+       boolean needHScroll(Rectangle contentRect, boolean vVisible) {
+               if (hBar == null) {
+                       return false;
+               }
+
+               boolean result = false;
+               Rectangle hostRect = getBounds();
+               int border = getBorderWidth();
+               hostRect.width -= 2*border;
+
+               if (contentRect.width != hostRect.width) {
+                       if (vVisible && vBar != null) {
+                               hostRect.width -= vBar.getSize().x;
+                       }
+               }
+
+               if (!expandHorizontal && contentRect.width > hostRect.width) {
+                       result = true;
+               }
+               if (expandHorizontal && minWidth > hostRect.width) {
+                       result = true;
+               }
+
+               if (result) {
+                       hBar.setBounds(0, hostRect.height-6, hostRect.width, 6);
+               } else {
+                       hBar.setBounds(0, 0, 0, 0);
+               }
+               return result;
+       }
+
+       void hScroll() {
+               if (content == null) return;
+               Point location = content.getLocation ();
+               int hSelection = hBar.getSelection();
+               content.setLocation (-hSelection, location.y);
+       }
+
+       public void setMinSize(Point size) {
+               if (size == null) {
+                       setMinSize(0, 0);
+               } else {
+                       setMinSize(size.x, size.y);
+               }
+       }
+
+       public void setMinSize(int width, int height) {
+               checkWidget();
+               if (width == minWidth && height == minHeight) {
+                       return;
+               }
+
+               minWidth = Math.max(0, width);
+               minHeight = Math.max(0, height);
+               layout(false);
+       }
+
+       public void setShowFocusedControl(boolean show) {
+               checkWidget();
+               if (showFocusedControl == show) {
+                       return;
+               }
+
+               Display display = getDisplay();
+               display.removeFilter(SWT.FocusIn, filter);
+               display.removeFilter(SWT.FocusOut, filter);
+
+               showFocusedControl = show;
+               if (showFocusedControl) {
+                       display.addFilter(SWT.FocusIn, filter);
+                       display.addFilter(SWT.FocusOut, filter);
+               }
+
+               Control control = display.getFocusControl();
+               if (contains(control)) {
+                       showControl(control);
+               }
+       }
+
+       public void showControl(Control control) {
+               checkWidget();
+               if (control == null) {
+                       SWT.error(SWT.ERROR_NULL_ARGUMENT);
+               }
+               if (control.isDisposed()) {
+                       SWT.error(SWT.ERROR_INVALID_ARGUMENT);
+               }
+               if (!contains(control)) {
+                       SWT.error(SWT.ERROR_INVALID_ARGUMENT);
+               }
+
+               Rectangle itemRect = getDisplay().map(control.getParent(), this, control.getBounds());
+               Rectangle area = getClientArea();
+               Point origin = getOrigin();
+
+               if (itemRect.x < 0) {
+                       origin.x = Math.max(0, origin.x + itemRect.x);
+               } else {
+                       if (area.width < itemRect.x + itemRect.width) {
+                               origin.x = Math.max(0,
+                                               origin.x + itemRect.x
+                                               + Math.min(itemRect.width, area.width)
+                                               - area.width);
+                       }
+               }
+
+               if (itemRect.y < 0) {
+                       origin.y = Math.max(0, origin.y + itemRect.y);
+               } else {
+                       if (area.height < itemRect.y + itemRect.height) {
+                               origin.y = Math.max(0,
+                                               origin.y + itemRect.y
+                                               + Math.min(itemRect.height, area.height)
+                                               - area.height);
+                       }
+               }
+
+               setOrigin(origin);
+       }
+
+       public boolean getExpandHorizontal() {
+               checkWidget();
+               return expandHorizontal;
+       }
+
+       public boolean getExpandVertical() {
+               checkWidget();
+               return expandVertical;
+       }
+
+       public void setExpandHorizontal(boolean expand) {
+               checkWidget();
+               if (expand == expandHorizontal) return;
+               expandHorizontal = expand;
+               layout(false);
+       }
+
+       public void setExpandVertical(boolean expand) {
+               checkWidget();
+               if (expand == expandVertical) return;
+               expandVertical = expand;
+               layout(false);
+       }
+}
diff --git a/src/org/tizen/emulator/manager/ui/table/CustomScrolledCompositeLayout.java b/src/org/tizen/emulator/manager/ui/table/CustomScrolledCompositeLayout.java
new file mode 100644 (file)
index 0000000..80f5448
--- /dev/null
@@ -0,0 +1,139 @@
+/*
+ * Emulator Manager
+ *
+ * Copyright (C) 2015 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * JiHye Kim <jihye424.kim@samsung.com>
+ * Minkee Lee <minkee.lee@samsung.com>
+ * SeokYeon Hwang <syeon.hwang@samsung.com>
+ * Sangho Park <sangho1206.park@samsung.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ * Contributors:
+ * - S-Core Co., Ltd
+ *
+ */
+
+package org.tizen.emulator.manager.ui.table;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.GC;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Layout;
+
+public class CustomScrolledCompositeLayout extends Layout {
+       boolean inLayout = false;
+       static final int DEFAULT_WIDTH  = 64;
+       static final int DEFAULT_HEIGHT = 64;
+
+       @Override
+       protected Point computeSize(Composite composite, int wHint, int hHint,
+                       boolean flushCache) {
+               CustomScrolledComposite sc = (CustomScrolledComposite)composite;
+               Point size = new Point(DEFAULT_WIDTH, DEFAULT_HEIGHT);
+               if (sc.content != null) {
+                       Point preferredSize = sc.content.computeSize(wHint, hHint, flushCache);
+                       Point currentSize = sc.content.getSize();
+                       size.x = sc.getExpandHorizontal() ? preferredSize.x : currentSize.x;
+                       size.y = sc.getExpandVertical() ? preferredSize.y : currentSize.y;
+               }
+               size.x = Math.max(size.x, sc.minWidth);
+               size.y = Math.max(size.y, sc.minHeight);
+               if (wHint != SWT.DEFAULT) size.x = wHint;
+               if (hHint != SWT.DEFAULT) size.y = hHint;
+               return size;
+       }
+
+       @Override
+       protected void layout(Composite composite, boolean flushCache) {
+               if (inLayout) {
+                       return;
+               }
+               CustomScrolledComposite sc = (CustomScrolledComposite)composite;
+               if (sc.content == null) {
+                       return;
+               }
+               Rectangle hostRect = sc.getClientArea();
+               if (sc.hBar != null) {
+                       if (sc.hBar.getSize().y >= hostRect.height) {
+                               return;
+                       }
+               }
+               if (sc.vBar != null) {
+
+                       if (sc.vBar.getSize().x >= hostRect.width) {
+                               System.out.println(sc.vBar.getSize().x + " " + sc.getSize().x);
+                               return;
+                       }
+               }
+
+               inLayout = true;
+               Rectangle contentRect = sc.content.getBounds();
+
+               boolean hVisible = sc.needHScroll(contentRect, false);
+               boolean vVisible = sc.needVScroll(contentRect, hVisible);
+               if (!hVisible && vVisible) {
+                       hVisible = sc.needHScroll(contentRect, vVisible);
+               }
+               if (sc.hBar != null) {
+                       sc.hBar.setVisible(hVisible);
+               }
+               if (sc.vBar != null) {
+                       sc.vBar.setVisible(vVisible);
+               }
+
+               if (sc.expandHorizontal) {
+                       contentRect.width = Math.max(sc.minWidth, hostRect.width);
+               }
+               if (sc.expandVertical) {
+                       contentRect.height = Math.max(sc.minHeight, hostRect.height);
+               }
+
+               GC gc = new GC (sc);
+               if (sc.hBar != null && sc.hBar.isVisible()) {
+                       int hPage = contentRect.width - hostRect.width;
+                       int hSelection = sc.hBar.getSelection ();
+                       if (hSelection >= hPage) {
+                               if (hPage <= 0) {
+                                       hSelection = 0;
+                                       sc.hBar.setSelection(0);
+                               }
+                               contentRect.x = -hSelection;
+                       }
+               }
+
+               if (sc.vBar != null && sc.vBar.isVisible()) {
+                       sc.vBar.setMaximum(contentRect.height - hostRect.height);
+                       int vPage = contentRect.height - hostRect.height;
+                       int vSelection = sc.vBar.getSelection ();
+                       if (vSelection >= vPage) {
+                               if (vPage <= 0) {
+                                       vSelection = 0;
+                                       sc.vBar.setSelection(0);
+                               }
+                               contentRect.y = -vSelection;
+                       }
+               }
+               gc.dispose ();
+
+               sc.content.setBounds (contentRect);
+               inLayout = false;
+       }
+
+}
index 611294b..fbd1fac 100644 (file)
@@ -211,6 +211,12 @@ public class Table extends TableScrolledComposite {
                if (item != null && !item.isDisposed()) {
                        item.dispose();
                        itemCount--;
+                       TableItem[] newItems = new TableItem[itemCount];
+                       System.arraycopy(items, 0, newItems, 0, index);
+                       System.arraycopy(items, index + 1, newItems, index, itemCount - index);
+                       items = newItems;
+                       this.adjustItemIndices(index);
+                       updateScrollBars(true);
                } else {
                        destroyItem(null);
                }
@@ -411,7 +417,7 @@ public class Table extends TableScrolledComposite {
                        items[index].updateSizeAndLocation(-1);
                        for (int i = index + 1; i < items.length; i ++) {
                                if (items[i] != null) {
-                                       items[i].updateLocation(-1);
+                                       items[i].updateLocation();
                                }
                        }
                } else {
@@ -420,7 +426,7 @@ public class Table extends TableScrolledComposite {
                                items[lastSelectedIndex].updateSizeAndLocation(-1);
                                for (int i = index + 1; i < lastSelectedIndex; i ++) {
                                        if (items[i] != null) {
-                                               items[i].updateLocation(-1);
+                                               items[i].updateLocation();
                                        }
                                }
                        } else {
@@ -428,7 +434,7 @@ public class Table extends TableScrolledComposite {
                                items[index].updateSizeAndLocation(-1);
                                for (int i = lastSelectedIndex + 1; i < index; i ++) {
                                        if (items[i] != null) {
-                                               items[i].updateLocation(-1);
+                                               items[i].updateLocation();
                                        }
                                }
                        }
@@ -442,7 +448,7 @@ public class Table extends TableScrolledComposite {
                        items[lastSelectedIndex].updateSizeAndLocation(-1);
                        for (int i = lastSelectedIndex + 1; i < items.length; i++) {
                                if (items[i] != null) {
-                                       items[i].updateLocation(-1);
+                                       items[i].updateLocation();
                                }
                        }
                }
index 2e045b3..b4361d4 100644 (file)
@@ -424,7 +424,11 @@ public class TableItem extends Canvas {
                        SWT.error(SWT.ERROR_WIDGET_DISPOSED);
                }
                if (hasData(index)) {
-                       return dataList[index].selectedImage;
+                       if(dataList[index].selectedImage != null) {
+                               return dataList[index].selectedImage;
+                       } else {
+                               return dataList[index].image;
+                       }
                }
                return null;
        }
@@ -600,6 +604,7 @@ public class TableItem extends Canvas {
                if (parent.isChecked() && checkBox != null) {
                        checkBox.setBackground(getBackground());
                }
+               updateLocation();
        }
 
        final void shiftData(int index) {
@@ -749,9 +754,13 @@ public class TableItem extends Canvas {
                }
        }
 
-       void updateLocation(int columnIndex) {
+       void updateLocation() {
                Rectangle rect = this.getClientArea();
-               setBounds(new Rectangle(rect.x, getTop(index), rect.width, rect.height));
+               if (rect.width == 0) {
+                       updateSizeAndLocation(-1);
+               } else {
+                       setBounds(new Rectangle(rect.x, getTop(index), rect.width, rect.height));
+               }
        }
 
        void updateSizeAndLocation(int columnIndex) {