Exemple #1
0
  @Override
  public void createPartControl(final Composite parent) {
    parent.setLayout(new FillLayout());
    form = tk.createForm(parent);
    Composite body = form.getBody();
    body.setLayout(new GridLayout());
    Table table = new Table(body, SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.SINGLE);
    TableColumn tc0 = new TableColumn(table, SWT.CENTER);
    tc0.setText(Messages.getString("BestellView.Number")); // $NON-NLS-1$
    tc0.setWidth(40);
    TableColumn tc1 = new TableColumn(table, SWT.LEFT);
    tc1.setText(Messages.getString("BestellView.Article")); // $NON-NLS-1$
    tc1.setWidth(280);
    TableColumn tc2 = new TableColumn(table, SWT.LEFT);
    tc2.setText(Messages.getString("BestellView.Dealer")); // $NON-NLS-1$
    tc2.setWidth(250);
    table.setLayoutData(SWTHelper.getFillGridData(1, true, 1, true));
    table.setHeaderVisible(true);
    table.setLinesVisible(true);
    tv = new TableViewer(table);
    tv.setContentProvider(
        new IStructuredContentProvider() {
          public Object[] getElements(final Object inputElement) {
            if (actBestellung != null) {
              return actBestellung.asList().toArray();
            }
            return new Object[0];
          }

          public void dispose() {}

          public void inputChanged(
              final Viewer viewer, final Object oldInput, final Object newInput) {}
        });
    tv.setLabelProvider(new BestellungLabelProvider());
    tv.setSorter(
        new ViewerSorter() {
          @Override
          public int compare(final Viewer viewer, final Object e1, final Object e2) {
            String s1 = ((Item) e1).art.getName();
            String s2 = ((Item) e2).art.getName();
            return s1.compareTo(s2);
          }
        });
    Transfer[] types = new Transfer[] {TextTransfer.getInstance()};
    tv.addDropSupport(
        DND.DROP_COPY,
        types,
        new DropTargetAdapter() {

          @Override
          public void dragEnter(final DropTargetEvent event) {
            event.detail = DND.DROP_COPY;
          }

          @Override
          public void drop(final DropTargetEvent event) {
            String drp = (String) event.data;
            String[] dl = drp.split(","); // $NON-NLS-1$
            if (actBestellung == null) {
              InputDialog dlg =
                  new InputDialog(
                      getViewSite().getShell(),
                      Messages.getString("BestellView.CreateNewOrder"), // $NON-NLS-1$
                      Messages.getString("BestellView.EnterOrderTitle"), // $NON-NLS-1$
                      StringTool.leer,
                      null);
              if (dlg.open() == Dialog.OK) {
                setBestellung(new Bestellung(dlg.getValue(), Hub.actUser));
              } else {
                return;
              }
            }
            for (String obj : dl) {
              PersistentObject dropped = Hub.poFactory.createFromString(obj);
              if (dropped instanceof Artikel) {
                actBestellung.addItem((Artikel) dropped, 1);
              }
            }
            tv.refresh();
          }
        });
    makeActions();
    viewmenus = new ViewMenus(getViewSite());
    viewmenus.createToolbar(wizardAction, saveAction, loadAction, printAction, sendAction);
    viewmenus.createMenu(
        wizardAction, saveAction, loadAction, printAction, sendAction, exportClipboardAction);
    viewmenus.createViewerContextMenu(tv, new IAction[] {removeAction, countAction});
    form.getToolBarManager().add(checkInAction);
    form.updateToolBar();
    setBestellung(null);
    tv.setInput(getViewSite());
  }
  @Override
  public void createPartControl(Composite parent) {
    Composite container = new Composite(parent, SWT.NONE);
    container.setLayout(new FillLayout(SWT.HORIZONTAL));

    Form frmServiosPrestados = formToolkit.createForm(container);
    formToolkit.paintBordersFor(frmServiosPrestados);
    frmServiosPrestados.setText("Servi\u00E7os Prestados");
    frmServiosPrestados.getBody().setLayout(new GridLayout(5, false));

    Label lblBuscar = new Label(frmServiosPrestados.getBody(), SWT.NONE);
    lblBuscar.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
    formToolkit.adapt(lblBuscar, true, true);
    lblBuscar.setText("Buscar:");

    txtFiltro = new Text(frmServiosPrestados.getBody(), SWT.BORDER);
    txtFiltro.addKeyListener(
        new KeyAdapter() {
          @Override
          public void keyReleased(KeyEvent e) {
            filtro.setSearch(txtFiltro.getText());
            tvServicoPrestado.refresh();
          }
        });
    txtFiltro.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 4, 1));
    txtFiltro.setMessage("Filtro...");
    formToolkit.adapt(txtFiltro, true, true);

    Label lblPeriodoDe =
        formToolkit.createLabel(frmServiosPrestados.getBody(), "Per\u00EDodo de", SWT.NONE);
    lblPeriodoDe.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 2, 1));

    txtDataInicial = new MecasoftText(frmServiosPrestados.getBody(), SWT.NONE);
    txtDataInicial.setOptions(MecasoftText.NUMEROS, 10);
    txtDataInicial.addChars(FormatterHelper.MECASOFTTXTDATA, new Integer[] {2, 4}, null, null);
    formToolkit.adapt(txtDataInicial);
    formToolkit.paintBordersFor(txtDataInicial);

    Calendar c = Calendar.getInstance();
    c.add(Calendar.MONTH, -1);
    txtDataInicial.setText(FormatterHelper.getDateFormatData().format(c.getTime()));

    Label lblAte = new Label(frmServiosPrestados.getBody(), SWT.NONE);
    formToolkit.adapt(lblAte, true, true);
    lblAte.setText("at\u00E9");

    txtDataFinal = new MecasoftText(frmServiosPrestados.getBody(), SWT.NONE);
    txtDataFinal.setOptions(MecasoftText.NUMEROS, 10);
    txtDataFinal.addChars(FormatterHelper.MECASOFTTXTDATA, new Integer[] {2, 4}, null, null);
    formToolkit.adapt(txtDataFinal);
    formToolkit.paintBordersFor(txtDataFinal);

    txtDataFinal.setText(FormatterHelper.getDateFormatData().format(new Date()));

    tvServicoPrestado =
        new TableViewer(frmServiosPrestados.getBody(), SWT.BORDER | SWT.FULL_SELECTION);
    tvServicoPrestado.addDoubleClickListener(
        new IDoubleClickListener() {
          public void doubleClick(DoubleClickEvent event) {
            try {
              IStructuredSelection selecao =
                  (IStructuredSelection) tvServicoPrestado.getSelection();

              if (selecao.isEmpty()) return;

              ServicoPrestado sp = (ServicoPrestado) selecao.getFirstElement();

              getSite()
                  .getPage()
                  .openEditor(new AbrirOrdemServicoEditorInput(sp), AbrirOrdemServicoEditor.ID);
            } catch (PartInitException e) {
              e.printStackTrace();
            }
          }
        });
    table = tvServicoPrestado.getTable();
    table.setLinesVisible(true);
    table.setHeaderVisible(true);
    table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 5, 1));
    tvServicoPrestado.setContentProvider(ArrayContentProvider.getInstance());
    tvServicoPrestado.addFilter(filtro);
    formToolkit.paintBordersFor(table);

    TableViewerColumn tvcNumero = new TableViewerColumn(tvServicoPrestado, SWT.NONE);
    tvcNumero.setLabelProvider(
        new ColumnLabelProvider() {
          @Override
          public String getText(Object element) {
            return ((ServicoPrestado) element).getId().toString();
          }
        });
    TableColumn tblclmnNumero = tvcNumero.getColumn();
    tblclmnNumero.setWidth(100);
    tblclmnNumero.setText("N\u00FAmero");

    TableViewerColumn tvcCliente = new TableViewerColumn(tvServicoPrestado, SWT.NONE);
    tvcCliente.setLabelProvider(
        new ColumnLabelProvider() {
          @Override
          public String getText(Object element) {
            return ((ServicoPrestado) element).getCliente().getNomeFantasia();
          }
        });
    TableColumn tblclmnCliente = tvcCliente.getColumn();
    tblclmnCliente.setWidth(203);
    tblclmnCliente.setText("Cliente");

    TableViewerColumn tvcVeiculo = new TableViewerColumn(tvServicoPrestado, SWT.NONE);
    tvcVeiculo.setLabelProvider(
        new ColumnLabelProvider() {
          @Override
          public String getText(Object element) {
            return ((ServicoPrestado) element).getVeiculo().getModelo();
          }
        });
    TableColumn tblclmnVeculo = tvcVeiculo.getColumn();
    tblclmnVeculo.setWidth(148);
    tblclmnVeculo.setText("Ve\u00EDculo");

    TableViewerColumn tvcMecanico = new TableViewerColumn(tvServicoPrestado, SWT.NONE);
    tvcMecanico.setLabelProvider(
        new ColumnLabelProvider() {
          @Override
          public String getText(Object element) {
            service.setServicoPrestado((ServicoPrestado) element);
            StatusServico status = service.getServicoPrestado().getUltimoStatus();

            if (status != null) return status.getFuncionario().getNomeFantasia();

            return "Não há mecânico";
          }
        });
    TableColumn tblclmnMecnico = tvcMecanico.getColumn();
    tblclmnMecnico.setWidth(152);
    tblclmnMecnico.setText("Mec\u00E2nico");

    TableViewerColumn tvcStatus = new TableViewerColumn(tvServicoPrestado, SWT.NONE);
    tvcStatus.setLabelProvider(
        new ColumnLabelProvider() {
          @Override
          public String getText(Object element) {
            service.setServicoPrestado((ServicoPrestado) element);
            StatusServico status = service.getServicoPrestado().getUltimoStatus();

            if (status != null) return status.getStatus().getDescricao();

            return "Serviço não iniciado";
          }
        });
    TableColumn tblclmnStatusAtual = tvcStatus.getColumn();
    tblclmnStatusAtual.setWidth(137);
    tblclmnStatusAtual.setText("Status Atual");
    frmServiosPrestados.getToolBarManager().add(actionAtualizar);
    frmServiosPrestados.getToolBarManager().add(actionNovo);
    frmServiosPrestados.updateToolBar();
  }