Пример #1
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()});
  }
  private void initGird(Composite compContents) {
    gridViewer = new GridTableViewer(compContents, SWT.V_SCROLL | SWT.BORDER);
    gridViewer.setLabelProvider(new ListGridLabelProvider());
    gridViewer.setContentProvider(new ListGridContentProvider());
    gridViewer.getGrid().setSelectionEnabled(true);
    gridViewer.getGrid().setFont(SWTResourceManager.getFont("Arial", 16, SWT.NORMAL));
    gridViewer.getGrid().setItemHeight(28);
    gridViewer.getGrid().addFocusListener(new HelpAdapter("계류차량 선택 후 더블클릭 또는 [2차 계량] 버튼 클릭."));

    gridViewer.setCellEditors(
        new CellEditor[] {
          new TextCellEditor(gridViewer.getGrid()), new TextCellEditor(gridViewer.getGrid())
        });
    gridViewer.setCellModifier(
        new ICellModifier() {

          public boolean canModify(Object element, String property) {
            return false;
          }

          public Object getValue(Object element, String property) {
            return element.toString();
          }

          public void modify(Object element, String property, Object value) {}
        });
    gridViewer.setColumnProperties(colProp);
    ColumnViewerEditorActivationStrategy actSupport =
        new ColumnViewerEditorActivationStrategy(gridViewer) {
          protected boolean isEditorActivationEvent(ColumnViewerEditorActivationEvent event) {
            return event.eventType == ColumnViewerEditorActivationEvent.TRAVERSAL
                || event.eventType == ColumnViewerEditorActivationEvent.MOUSE_DOUBLE_CLICK_SELECTION
                || (event.eventType == ColumnViewerEditorActivationEvent.KEY_PRESSED
                    && event.keyCode == SWT.CR);
          }
        };
    GridViewerEditor.create(
        gridViewer,
        actSupport,
        ColumnViewerEditor.TABBING_HORIZONTAL
            | ColumnViewerEditor.TABBING_MOVE_TO_ROW_NEIGHBOR
            | ColumnViewerEditor.TABBING_VERTICAL
            | ColumnViewerEditor.KEYBOARD_ACTIVATION);

    GridColumnGroup cgSpot = new GridColumnGroup(gridViewer.getGrid(), SWT.CENTER);
    cgSpot.setText("        1차 계량");

    for (int i = 0; i < colName.length; i++) {
      GridColumn column = null;
      if (i == 3 || i == 4) {
        column = new GridColumn(cgSpot, SWT.NONE);
      } else {
        column = new GridColumn(gridViewer.getGrid(), SWT.NONE);
      }
      column.setWidth(colWidth[i]);
      column.setAlignment(colAlign[i]);
      column.setText(colName[i]);
      column.setResizeable(true);
    }

    gridViewer.getGrid().setLinesVisible(true);
    gridViewer.getGrid().setHeaderVisible(true);
    gridViewer
        .getGrid()
        .addMouseListener(
            new MouseAdapter() {
              @Override
              public void mouseDoubleClick(MouseEvent evt) {
                Grid g = (Grid) evt.getSource();
                if (listData != null
                    && listData.length > g.getSelectionIndex()
                    && g.getSelectionIndex() != -1) {
                  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();
                  }
                }
              }
            });
    Grid grid = gridViewer.getGrid();
    grid.addControlListener(
        new ControlAdapter() {
          @Override
          public void controlResized(ControlEvent e) {
            int width = 0;
            for (int i = 0; i < gridViewer.getGrid().getColumnCount(); i++) {
              width = (int) (colWidth[i] * gridViewer.getGrid().getClientArea().width / 100);
              if (i == gridViewer.getGrid().getColumnCount() - 1) {
                width += 5;
              }
              gridViewer.getGrid().getColumn(i).setWidth(width);
            }
            int add = gridViewer.getGrid().getBounds().width / 100 - 0;
            gridViewer
                .getGrid()
                .setFont(SWTResourceManager.getFont("Arial", 12 + (add > 0 ? add : 0), SWT.NORMAL));
          }
        });
    grid.setRowsResizeable(true);

    grid.setLineColor(ColorRepository.getColor(ColorRepository.GRID_LINE));
    // grid.setBackgroundMode(SWT.INHERIT_FORCE);
    GridData gridViewerLData = new GridData();
    gridViewerLData.grabExcessHorizontalSpace = true;
    gridViewerLData.horizontalAlignment = GridData.FILL;
    gridViewerLData.grabExcessVerticalSpace = true;
    gridViewerLData.verticalAlignment = GridData.FILL;
    gridViewerLData.verticalIndent = 5;
    gridViewer.getGrid().setLayoutData(gridViewerLData);
  } // initGird