Exemple #1
0
  public void testUpdateFromModel() {
    final ITableRidget ridget = getRidget();
    final Grid control = getWidget();
    final List<ChangeEvent> changeEvents = new ArrayList<ChangeEvent>();
    final IChangeListener listener =
        new IChangeListener() {
          public void handleChange(final ChangeEvent event) {
            changeEvents.add(event);
          }
        };
    ridget.getObservableList().addChangeListener(listener);

    final int oldCount = manager.getPersons().size();

    assertEquals(oldCount, ridget.getObservableList().size());
    assertEquals(oldCount, control.getItemCount());

    manager.getPersons().remove(person1);

    final int newCount = oldCount - 1;

    assertEquals(newCount, manager.getPersons().size());
    assertEquals(oldCount, ridget.getObservableList().size());
    assertEquals(oldCount, control.getItemCount());
    assertEquals(0, changeEvents.size());

    ridget.updateFromModel();

    assertEquals(newCount, manager.getPersons().size());
    assertEquals(newCount, ridget.getObservableList().size());
    assertEquals(newCount, control.getItemCount());
    // TODO [ev] discuss with team
    //		assertEquals(1, changeEvents.size());
    assertEquals(0, changeEvents.size());
  }
Exemple #2
0
  /** As per Bug 295305 */
  public void testSetColumnWidths() {
    final ITableRidget ridget = createRidget();
    final Grid control = new Grid(getShell(), SWT.FULL_SELECTION | SWT.SINGLE);
    ridget.setUIControl(control);

    try {
      ridget.setColumnWidths(new Object[] {null});
      fail();
    } catch (final RuntimeException rex) {
      assertTrue(rex.getMessage().contains("null")); // $NON-NLS-1$
    }

    try {
      ridget.setColumnWidths(new Object[] {new Object()});
      fail();
    } catch (final RuntimeException rex) {
      assertTrue(rex.getMessage().contains("Object")); // $NON-NLS-1$
    }

    ridget.setColumnWidths(
        new Object[] {new ColumnPixelData(20), new ColumnPixelData(40), new ColumnPixelData(60)});
    final String[] columns3 = {
      Person.PROPERTY_FIRSTNAME, Person.PROPERTY_LASTNAME, Person.PROPERTY_BIRTHDAY
    };
    ridget.bindToModel(manager, "persons", Person.class, columns3, null); // $NON-NLS-1$

    final int[] expected = {20, 40, 60};
    for (int i = 0; i < 3; i++) {
      final int actual = control.getColumn(i).getWidth();
      final String msg =
          String.format("col #%d, exp:%d, act:%d", i, expected[i], actual); // $NON-NLS-1$
      assertEquals(msg, expected[i], actual);
    }
  }
  /** OK Button click event */
  private void onClickOK() {
    Grid g = gridViewer.getGrid();
    if (g.getSelectionIndex() == -1) {
      MessageDialog.openInformation(shell, "데이터 선택 필요", "선택된 데이터가 없습니다. \n\n목록에서 선택 후 작업하세요.");
      return;
    } else {
      if (listData != null && listData.length > g.getSelectionIndex()) {
        TsWgtInfDTO vo = listData[g.getSelectionIndex()];
        WeighSecondDialog dialog =
            new WeighSecondDialog(parent, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
        shell.close();

        Object answer = dialog.open(vo);
        if (answer != null) {
          HomeView hv =
              (HomeView)
                  PlatformUI.getWorkbench()
                      .getActiveWorkbenchWindow()
                      .getActivePage()
                      .findView(HomeView.ID);
          hv.refreshData();
        }
      }
    }
  }
Exemple #4
0
  public void testAddDoubleClickListener() {
    final ITableRidget ridget = getRidget();
    final Grid control = getWidget();

    try {
      ridget.addDoubleClickListener(null);
      fail();
    } catch (final RuntimeException npe) {
      ok();
    }

    final FTActionListener listener1 = new FTActionListener();
    ridget.addDoubleClickListener(listener1);

    final FTActionListener listener2 = new FTActionListener();
    ridget.addDoubleClickListener(listener2);
    ridget.addDoubleClickListener(listener2);

    final Event doubleClick = new Event();
    doubleClick.widget = control;
    doubleClick.type = SWT.MouseDoubleClick;
    control.notifyListeners(SWT.MouseDoubleClick, doubleClick);

    assertEquals(1, listener1.getCount());
    assertEquals(1, listener2.getCount());

    ridget.removeDoubleClickListener(listener1);

    control.notifyListeners(SWT.MouseDoubleClick, doubleClick);

    assertEquals(1, listener1.getCount());
  }
Exemple #5
0
 @Override
 protected Grid createWidget(final Composite parent) {
   final Grid grid = new Grid(parent, SWT.MULTI | SWT.BORDER);
   grid.setHeaderVisible(true);
   new GridColumn(grid, SWT.NONE);
   new GridColumn(grid, SWT.NONE);
   return grid;
 }
Exemple #6
0
  public void testTableColumnsNumAndHeader() {
    final Grid control = getWidget();

    final GridColumn[] columns = control.getColumns();
    assertEquals(2, columns.length);
    assertEquals("First Name", columns[0].getText()); // $NON-NLS-1$
    assertEquals("Last Name", columns[1].getText()); // $NON-NLS-1$
    assertTrue(control.getHeaderVisible());
  }
Exemple #7
0
 @Override
 protected final void setUiSelection(final Widget item) {
   Assert.isTrue(item instanceof GridItem);
   final Grid control = getUIControl();
   if (control != null) {
     final int index = control.getIndexOfItem((GridItem) item);
     control.setSelection(index);
   }
 }
Exemple #8
0
 private void clearSortIndicator() {
   final Grid control = getUIControl();
   if (control == null) {
     return;
   }
   final GridColumn[] columns = control.getColumns();
   for (final GridColumn column : columns) {
     column.setSort(SWT.NONE);
   }
 }
Exemple #9
0
 @Override
 protected int getColumnStyle(final int columnIndex) {
   checkColumnRange(columnIndex);
   final Grid control = getUIControl();
   if (control == null) {
     return SWT.DEFAULT;
   }
   final GridColumn[] columns = control.getColumns();
   return columns[columnIndex].getStyle();
 }
Exemple #10
0
 @Override
 protected final void applyColumnsMovable() {
   final Grid control = getUIControl();
   if (control == null) {
     return;
   }
   for (final GridColumn column : control.getColumns()) {
     column.setMoveable(hasMoveableColumns());
   }
 }
Exemple #11
0
 @Override
 protected final void unbindUIControl() {
   super.unbindUIControl();
   final Grid control = getUIControl();
   if (control != null) {
     for (final GridColumn column : control.getColumns()) {
       column.removeSelectionListener(sortListener);
     }
     control.removeSelectionListener(selectionTypeEnforcer);
   }
 }
Exemple #12
0
 @Override
 protected final void bindUIControl() {
   super.bindUIControl();
   final Grid control = getUIControl();
   if (control != null) {
     for (final GridColumn column : control.getColumns()) {
       column.addSelectionListener(sortListener);
       column.setCellRenderer(cellRenderer);
     }
     control.addSelectionListener(selectionTypeEnforcer);
     control.setEmptyCellRenderer(emptyCellRenderer);
   }
 }
Exemple #13
0
  /**
   * Tests that for multiple selection, the ridget selection state and the ui selection state cannot
   * be changed by the user when ridget is set to "output only".
   */
  public void testOutputMultipleSelectionCannotBeChangedFromUI() {
    final ITableRidget ridget = getRidget();
    final Grid control = getWidget();

    ridget.setSelectionType(SelectionType.MULTI);

    assertEquals(0, ridget.getSelection().size());
    assertEquals(0, control.getSelectionCount());

    ridget.setOutputOnly(true);
    control.setFocus();
    // move down and up to select row 0; space does not select in tables
    UITestHelper.sendKeyAction(control.getDisplay(), UITestHelper.KC_ARROW_DOWN);
    UITestHelper.sendKeyAction(control.getDisplay(), UITestHelper.KC_ARROW_UP);

    assertEquals(0, ridget.getSelection().size());
    assertEquals(0, control.getSelectionCount());

    ridget.setOutputOnly(false);
    control.setFocus();
    // move down and up to select row 0; space does not select in tables
    UITestHelper.sendKeyAction(control.getDisplay(), UITestHelper.KC_ARROW_DOWN);
    UITestHelper.sendKeyAction(control.getDisplay(), UITestHelper.KC_ARROW_UP);

    assertEquals(1, ridget.getSelection().size());
    assertEquals(1, control.getSelectionCount());
  }
Exemple #14
0
  @Override
  public void controlResized(ControlEvent e) {
    int restWidth = 0;
    for (CodeViewerColumn col : CodeViewerColumn.values()) {
      if (col.equals(column)) continue;
      restWidth += grid.getColumn(col.ordinal()).getWidth();
    }
    if (grid.getVerticalBar().isVisible()) {
      restWidth += grid.getVerticalBar().getSize().x;
    }
    int totalWidth = grid.getBounds().width;

    grid.getColumn(column.ordinal()).setWidth(totalWidth - restWidth - 4);
  }
Exemple #15
0
  public void testTableColumnsWithNullHeaderEntry() {
    final ITableRidget ridget = getRidget();
    final Grid control = getWidget();

    control.getColumn(0).setText("foo"); // $NON-NLS-1$
    control.getColumn(1).setText("bar"); // $NON-NLS-1$

    final String[] properties1 =
        new String[] {"firstname", "lastname"}; // $NON-NLS-1$ //$NON-NLS-2$
    final String[] headers = new String[] {"First Name", null}; // $NON-NLS-1$
    ridget.bindToModel(manager, "persons", Person.class, properties1, headers); // $NON-NLS-1$

    assertEquals("First Name", control.getColumn(0).getText()); // $NON-NLS-1$
    assertEquals("", control.getColumn(1).getText()); // $NON-NLS-1$
  }
Exemple #16
0
  public void testTableColumnsWithNullHeader() {
    final ITableRidget ridget = getRidget();
    final Grid control = getWidget();

    control.setHeaderVisible(true);
    control.getColumn(0).setText("foo"); // $NON-NLS-1$
    control.getColumn(1).setText("bar"); // $NON-NLS-1$

    final String[] properties1 =
        new String[] {"firstname", "lastname"}; // $NON-NLS-1$ //$NON-NLS-2$
    // null should hide the headers
    ridget.bindToModel(manager, "persons", Person.class, properties1, null); // $NON-NLS-1$

    assertFalse(control.getHeaderVisible());
  }
Exemple #17
0
  /** As per Bug 295305 */
  public void testAutoCreateColumnsWithNoLayout() {
    final ITableRidget ridget = createRidget();
    final Grid control = new Grid(getShell(), SWT.FULL_SELECTION | SWT.SINGLE);
    ridget.setUIControl(control);

    getShell().setLayout(null);
    control.setSize(300, 100);
    final String[] columns3 = {
      Person.PROPERTY_FIRSTNAME, Person.PROPERTY_LASTNAME, Person.PROPERTY_BIRTHDAY
    };
    ridget.bindToModel(manager, "persons", Person.class, columns3, null); // $NON-NLS-1$

    assertEquals(null, control.getParent().getLayout());
    assertEquals(null, control.getLayout());

    assertColumnWidths(control, 3);
  }
Exemple #18
0
  /** As per bug 301182 */
  public void testRefreshNull() {
    final ITableRidget ridget = createRidget();
    final Grid control = createWidget(getShell());
    ridget.setUIControl(control);

    final StringPojo word1 = new StringPojo("eclipse"); // $NON-NLS-1$
    final StringPojo word2 = new StringPojo("riena"); // $NON-NLS-1$
    final WritableList values = new WritableList(Arrays.asList(word1, word2), StringPojo.class);
    final String[] columns = {"value"}; // $NON-NLS-1$
    ridget.bindToModel(values, StringPojo.class, columns, null);
    ridget.updateFromModel();

    assertEquals("eclipse", control.getItem(0).getText()); // $NON-NLS-1$
    assertEquals("riena", control.getItem(1).getText()); // $NON-NLS-1$

    word1.setValue("alpha"); // $NON-NLS-1$
    word2.setValue("beta"); // $NON-NLS-1$

    assertEquals("eclipse", control.getItem(0).getText()); // $NON-NLS-1$
    assertEquals("riena", control.getItem(1).getText()); // $NON-NLS-1$

    ridget.refresh(null);

    assertEquals("alpha", control.getItem(0).getText()); // $NON-NLS-1$
    assertEquals("beta", control.getItem(1).getText()); // $NON-NLS-1$
  }
Exemple #19
0
  public void testSetColumnFormatter() {
    final ITableRidget ridget = getRidget();
    final Grid table = getWidget();
    final IColumnFormatter formatter =
        new ColumnFormatter() {
          @Override
          public String getText(final Object element) {
            final Person person = (Person) element;
            return person.getLastname().toUpperCase();
          }
        };
    final String lastName = person1.getLastname();
    final String lastNameUpperCase = lastName.toUpperCase();

    try {
      ridget.setColumnFormatter(-1, formatter);
      fail();
    } catch (final RuntimeException rex) {
      ok();
    }

    try {
      ridget.setColumnFormatter(99, formatter);
      fail();
    } catch (final RuntimeException rex) {
      ok();
    }

    ridget.setColumnFormatter(1, formatter);

    assertEquals(lastName, table.getItem(0).getText(1));

    ridget.updateFromModel();

    assertEquals(lastNameUpperCase, table.getItem(0).getText(1));

    ridget.setColumnFormatter(1, null);

    assertEquals(lastNameUpperCase, table.getItem(0).getText(1));

    ridget.updateFromModel();

    assertEquals(lastName, table.getItem(0).getText(1));
  }
Exemple #20
0
 /**
  * Returns the 0 based index of the column at {@code pt}. The code can handle re-ordered columns.
  * The index refers to the original ordering (as used by SWT API).
  *
  * <p>Will return -1 if no column could be computed -- this is the case when all columns are
  * resized to have width 0.
  */
 private int findColumn(final Grid grid, final Point pt) {
   int width = 0;
   final int[] colOrder = grid.getColumnOrder();
   // compute the current column ordering
   final GridColumn[] columns = new GridColumn[colOrder.length];
   for (int i = 0; i < colOrder.length; i++) {
     final int idx = colOrder[i];
     columns[i] = grid.getColumn(idx);
   }
   // find the column under Point pt\
   for (final GridColumn col : columns) {
     final int colWidth = col.getWidth();
     if (width < pt.x && pt.x < width + colWidth) {
       return grid.indexOf(col);
     }
     width += colWidth;
   }
   return -1;
 }
Exemple #21
0
  /**
   * {@inheritDoc}
   *
   * <p>Sets for every item the tool tip text. The text can be configured with the {@link
   * IColumnFormatter}.
   *
   * <p><i>note: The tool tip of a grid is only shown, if in a cell not the complete text can be
   * displayed.</i>
   */
  @Override
  protected final void updateToolTipSupport() {

    final Grid control = getUIControl();
    if (control == null) {
      return;
    }
    int colCount = getColumnCount();
    final GridItem[] items = control.getItems();
    for (final GridItem item : items) {
      for (final int colIndex = 0; colCount < colCount; colCount++) {
        String toolTip = null;
        if (toolTip == null) {
          toolTip = getToolTipText(item, colIndex);
        }
        item.setToolTipText(colIndex, toolTip);
      }
    }
  }
Exemple #22
0
  @Override
  public void createPartControl(Composite parent) {
    taskModel = new TaskModel();

    Composite container = new Composite(parent, SWT.NONE);
    container.setLayout(new FillLayout());
    {
      viewer =
          new GridTableViewer(
              container, SWT.BORDER | SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL);

      Grid table = viewer.getGrid();
      table.setCellSelectionEnabled(true);
      table.setHeaderVisible(true);
      table.addMouseListener(new TaskMouseListener());
      table.addKeyListener(new TaskKeyListener());

      {
        GridColumn column = new GridColumn(table, SWT.NONE);
        column.setText("Summary");
        column.setWidth(400);
      }

      for (Version version : taskModel.getVersions()) {
        GridColumn column = new GridColumn(table, SWT.CENTER);
        column.setText(version.toString());
        column.setWidth(90);
      }

      viewer.setContentProvider(new TaskContentProvider());
      viewer.setLabelProvider(new TaskLabelProvider());
      viewer.setInput(taskModel);

      // ColumnViewerToolTipSupport.enableFor(viewer, ToolTip.RECREATE);
      getViewSite().setSelectionProvider(viewer);
    }

    createActions();
    initializeToolBar();
    initializeMenu();

    viewer.setFilters(new ViewerFilter[] {new TaskViewerFilter()});
  }
Exemple #23
0
  /** As per Bug 295305 */
  public void testAutoCreateTableColumns() {
    final ITableRidget ridget = createRidget();
    final Grid control = new Grid(getShell(), SWT.FULL_SELECTION | SWT.SINGLE);
    ridget.setUIControl(control);

    assertEquals(0, control.getColumnCount());

    final String[] columns3 = {
      Person.PROPERTY_FIRSTNAME, Person.PROPERTY_LASTNAME, Person.PROPERTY_BIRTHDAY
    };
    ridget.bindToModel(manager, "persons", Person.class, columns3, null); // $NON-NLS-1$

    assertEquals(3, control.getColumnCount());

    final String[] columns1 = {Person.PROPERTY_FIRSTNAME};
    ridget.bindToModel(manager, "persons", Person.class, columns1, null); // $NON-NLS-1$

    assertEquals(1, control.getColumnCount());
  }
Exemple #24
0
 @Override
 protected final void applyTableColumnHeaders() {
   final Grid control = getUIControl();
   final boolean headersVisible = columnHeaders != null;
   control.setHeaderVisible(headersVisible);
   if (headersVisible) {
     final GridColumn[] columns = control.getColumns();
     for (int i = 0; i < columns.length; i++) {
       String columnHeader = ""; // $NON-NLS-1$
       if (i < columnHeaders.length && columnHeaders[i] != null) {
         columnHeader = columnHeaders[i];
       }
       columns[i].setText(columnHeader);
       // not necessary for GridColumns because they implement this function already!
       // final String tooltip = isShowColumnTooltip(columns[i], columnHeader) ? columnHeader : "";
       // //$NON-NLS-1$
       // columns[i].setHeaderTooltip(tooltip);
     }
   }
 }
Exemple #25
0
  public void testSetMoveableColumns() {
    final ITableRidget ridget = getRidget();
    final Grid table = getWidget();

    assertFalse(ridget.hasMoveableColumns());
    assertFalse(table.getColumn(0).getMoveable());
    assertFalse(table.getColumn(1).getMoveable());

    ridget.setMoveableColumns(true);

    assertTrue(ridget.hasMoveableColumns());
    assertTrue(table.getColumn(0).getMoveable());
    assertTrue(table.getColumn(1).getMoveable());

    ridget.setMoveableColumns(false);

    assertFalse(ridget.hasMoveableColumns());
    assertFalse(table.getColumn(0).getMoveable());
    assertFalse(table.getColumn(1).getMoveable());
  }
Exemple #26
0
  public void testSetSelectionType() {
    final ITableRidget ridget = getRidget();
    final Grid control = getWidget();

    assertEquals(SelectionType.SINGLE, ridget.getSelectionType());
    assertTrue((control.getStyle() & SWT.MULTI) != 0);

    ridget.setSelection(new int[] {0, 1});

    // single selection is enforced
    assertEquals(1, ridget.getSelectionIndices().length);
    assertEquals(1, control.getSelectionCount());

    // multiple selection is now allowed
    ridget.setSelectionType(SelectionType.MULTI);
    ridget.setSelection(new int[] {0, 1});

    assertEquals(2, ridget.getSelectionIndices().length);
    assertEquals(2, control.getSelectionCount());
  }
Exemple #27
0
 @Override
 protected final void applyComparator(final Map<Integer, Comparator<?>> comparatorMap) {
   if (getTableViewer() != null) {
     Comparator<?> compi = null;
     if (getSortedColumn() != -1) {
       final Integer key = Integer.valueOf(getSortedColumn());
       compi = comparatorMap.get(key);
     }
     final Grid control = getUIControl();
     clearSortIndicator();
     if (compi != null) {
       final GridColumn column = control.getColumn(getSortedColumn());
       final int direction = getSortDirection();
       column.setSort(direction);
       final SortableComparator sortableComparator = new SortableComparator(this, compi);
       getTableViewer().setComparator(new TableComparator(sortableComparator));
     } else {
       getTableViewer().setComparator(null);
     }
   }
 }
 protected void onClickDelete() {
   Grid g = gridViewer.getGrid();
   if (g.getSelectionIndex() == -1) {
     MessageDialog.openInformation(shell, "데이터 선택 필요", "선택된 데이터가 없습니다. \n\n목록에서 선택 후 작업하세요.");
     return;
   } else {
     if (listData != null && listData.length > g.getSelectionIndex()) {
       boolean rtn =
           MessageDialog.openConfirm(
               shell,
               "삭제 확인",
               "1차 계량 정보를 삭제하시겠습니까?\n\n차량번호-" + listData[g.getSelectionIndex()].getCar_num());
       if (!rtn) {
         return;
       }
       try {
         TsWgtInfManager wim = new TsWgtInfManager();
         TsWgtInfDTO dto = (TsWgtInfDTO) ObjectUtil.getDefaultObject(TsWgtInfDTO.class.getName());
         dto.setDel_yn(DTSConstants.FLAG_Y);
         dto.setWgt_cd(listData[g.getSelectionIndex()].getWgt_cd());
         wim.updateTsWgtInf(dto);
         // 목록 재조회
         select();
         // HomeView refresh
         HomeView hv =
             (HomeView)
                 PlatformUI.getWorkbench()
                     .getActiveWorkbenchWindow()
                     .getActivePage()
                     .findView(HomeView.ID);
         hv.refreshData();
       } catch (IOException e) {
         MessageDialog.openError(shell, "삭제 오류", "데이터 삭제 중 오류가 발생하였습니다. \n\n" + e.getMessage());
         return;
       }
     }
   }
 }
Exemple #29
0
  /** As per Bug 295305 */
  public void testPreserveColumnWidths() {
    final int[] widths = {50, 100, 150};
    final ITableRidget ridget = createRidget();
    final Grid control = new Grid(getShell(), SWT.FULL_SELECTION | SWT.SINGLE);
    for (final int width : widths) {
      final GridColumn column = new GridColumn(control, SWT.NONE);
      column.setWidth(width);
    }
    ridget.setUIControl(control);

    final String[] columns3 = {
      Person.PROPERTY_FIRSTNAME, Person.PROPERTY_LASTNAME, Person.PROPERTY_BIRTHDAY
    };
    ridget.bindToModel(manager, "persons", Person.class, columns3, null); // $NON-NLS-1$
    ridget.updateFromModel();

    for (int i = 0; i < 3; i++) {
      final int actual = control.getColumn(i).getWidth();
      final String msg =
          String.format("col #%d, exp:%d, act:%d", i, widths[i], actual); // $NON-NLS-1$
      assertEquals(msg, widths[i], actual);
    }
  }
Exemple #30
0
 @Override
 protected final void applyColumns() {
   final Grid control = getUIControl();
   if (control == null) {
     return;
   }
   final int expectedCols = getExpectedColumnCount();
   if (getColumnCount() != expectedCols) {
     for (final GridColumn column : control.getColumns()) {
       column.dispose();
     }
     for (int i = 0; i < expectedCols; i++) {
       new GridColumn(control, SWT.NONE);
     }
     applyColumnWidths();
   }
   final GridColumn[] columns = control.getColumns();
   for (int columnIndex = 0; columnIndex < columns.length; columnIndex++) {
     final ViewerColumn viewerColumn =
         new GridViewerColumn(getTableViewer(), columns[columnIndex]);
     applyEditingSupport(viewerColumn, columnIndex);
   }
 }