Esempio n. 1
0
  public boolean createTable(
      int lenX, int lenY, String[][] dataArray, typeOfCell[][] type, Object[][] extra) {
    int[] widthArr = new int[lenX];
    for (int i = 0; i < lenX; i++) widthArr[i] = normalWidth;
    widthArr[0] = Width0;
    Table varTable = new Table(_parent, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
    if (lenY > 30) {
      if (debug) System.out.println("lenY=" + lenY);
      varTable.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    }
    // else varTable.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 10));

    varTable.setHeaderVisible(true);
    TableColumn tableColumn[] = new TableColumn[lenX];
    for (int i = 0; i < lenX; i++) {
      tableColumn[i] = new TableColumn(varTable, SWT.LEFT);
      tableColumn[i].setText(_columnName[i]);
      tableColumn[i].setWidth(widthArr[i]);
    }
    TableItem Sp[] = new TableItem[lenY];
    String[] value = new String[lenX];
    for (int j = 0; j < lenY; j++) {
      for (int i = 0; i < lenX; i++) value[i] = dataArray[i][j];
      Sp[j] = new TableItem(varTable, SWT.NONE);
      Sp[j].setText(value);

      for (int i = 0; i < lenX; i++) {
        switch (type[i][j]) {
          case Combo:
            int current = -1;
            combo = new CCombo(varTable, SWT.NONE);
            Object valueArr = extra[i][j];
            if (valueArr instanceof String[]) {
              String[] valueAsString = (String[]) valueArr;
              for (int k = 0; k < valueAsString.length; k++) {
                combo.add(valueAsString[k]);
                if (valueAsString[k].compareTo(dataArray[i][j]) == 0) current = k;
              }
              if (current == -1) {
                // org.csstudio.diag.IOCremoteManagement.Activator.errorPrint ("Wrong comboSelect");
                System.out.println("Wrong comboSelect");
              } else combo.select(current);

              TableEditor editor = new TableEditor(varTable);
              editor.grabHorizontal = editor.grabVertical = true;
              editor.setEditor(combo, Sp[j], i);
              if (dataArray[0][j].compareTo(ssRunCtrlStr) == 0) {
                comboSsRunCtrl = combo;
                comboSsRunCtrl.addSelectionListener(
                    new SelectionAdapter() {
                      public void widgetSelected(SelectionEvent e) {
                        overwriteSS();
                      }
                    });
              } else if (dataArray[0][j].compareTo(this.currentStateStr) == 0) {
                comboCurrentState = combo;
                comboCurrentState.addSelectionListener(
                    new SelectionAdapter() {
                      public void widgetSelected(SelectionEvent e) {
                        overwriteCS();
                      }
                    });
              }

            } else {
              // org.csstudio.diag.IOCremoteManagement.Activator.errorPrint ("Wrong instance");
              System.out.println("Wrong instance");
            }
            break;

          case EditableText:
            Text txt = new Text(varTable, SWT.SINGLE | SWT.BORDER);
            txt.setText(dataArray[i][j]);
            txt.addSelectionListener(
                new SelectionAdapter() {
                  public void widgetDefaultSelected(SelectionEvent e) {
                    Text t = (Text) e.widget;
                    valueChanged(t.getText());
                    System.out.println("DummyListenerText");
                  }
                });
            TableEditor editor = new TableEditor(varTable);
            editor.grabHorizontal = editor.grabVertical = true;
            editor.setEditor(txt, Sp[j], i);
            break;
            //				TODO jhatje: implement new datatypes
            //				case MB3_member:
            //					ListViewer listMB3 = new ListViewer(varTable, SWT.NONE);
            //					final String[] arr = new String[1];
            //					arr[0]=dataArray[i][j];
            //					listMB3.setContentProvider(new IStructuredContentProvider() {
            //					public void dispose() {
            //					}
            //					public Object[] getElements(Object inputElement) {
            //					IProcessVariable[] ipv = new IProcessVariable[1];
            //					ipv[0] = CentralItemFactory.createProcessVariable(arr[0]);
            //					return ipv;
            //					}
            //					public void inputChanged(Viewer viewer,Object oldInput, Object newInput) {
            //					}
            //					});
            //
            //					listMB3.setLabelProvider(new ILabelProvider() {
            //					public Image getImage(Object element) {
            //					return null;
            //					}
            //					public String getText(Object element) {
            //					IProcessVariable ipv = (IProcessVariable) element;
            //					return ipv.getName();
            //					}
            //					public void addListener(ILabelProviderListener listener) {
            //					}
            //					public void dispose() {
            //					}
            //					public boolean isLabelProperty(Object element,String property) {
            //					return false;
            //					}
            //					public void removeListener(
            //						ILabelProviderListener listener) {
            //					}
            //					});
            //					listMB3.setInput(arr);
            //					editor = new TableEditor(varTable);
            //					editor.grabHorizontal = editor.grabVertical = true;
            //
            //					List list =  listMB3.getList();
            //					list.setForeground(_display.getSystemColor(SWT.COLOR_BLUE));
            //					editor.setEditor( list, Sp[j], 1);
            //					new ProcessVariableDragSource (listMB3.getControl(), listMB3);
            //					makeContextMenu(listMB3);
            //				break;

          case Message:
            Group textGroup = new Group(_parent, SWT.NONE);
            GridLayout gridLayout = new GridLayout();
            textGroup.setLayout(gridLayout);
            gridLayout.numColumns = 1;
            textGroup.setLayoutData(
                new GridData(
                    /*GridData.GRAB_HORIZONTAL|GridData.HORIZONTAL_ALIGN_FILL|*/ GridData
                        .VERTICAL_ALIGN_FILL));
            textGroup.setText("Message:");
            Label labelWrap = new Label(textGroup, SWT.WRAP | SWT.BORDER);
            labelWrap.setText(dataArray[i][j]);
            labelWrap.setSize(20, 50);
            break;

          case String:
            break;
          default:
            // org.csstudio.diag.IOCremoteManagement.Activator.errorPrint ("Wrong switch");
            System.out.println("Wrong switch");
            break;
        }
      }
    }

    if (_warning) {
      varTable.setForeground(_display.getSystemColor(SWT.COLOR_RED));
      varTable.setBackground(_display.getSystemColor(SWT.COLOR_YELLOW));
    }

    if (debug) System.out.println("result is OK");
    // org.csstudio.diag.IOCremoteManagement.Activator.errorPrint ("result is OK");
    return true;
  }
Esempio n. 2
0
  /** Create the dialog area and place correctly the user interfaces widgets */
  @Override
  protected Control createDialogArea(Composite parent) {
    Composite comp = (Composite) super.createDialogArea(parent);
    GridLayout gridLayout = new GridLayout(1, false);
    comp.setLayout(gridLayout);
    GridData gridData = new GridData(GridData.FILL_BOTH);
    comp.setLayoutData(gridData);

    Group body = new Group(comp, SWT.SHADOW_ETCHED_IN);
    gridLayout = new GridLayout(1, false);
    body.setLayout(gridLayout);
    gridData = new GridData(GridData.FILL_BOTH);
    body.setLayoutData(gridData);

    Composite eventBody = new Composite(body, SWT.FILL);
    gridLayout = new GridLayout(2, false);
    eventBody.setLayout(gridLayout);
    gridData = new GridData(GridData.FILL_BOTH);
    eventBody.setLayoutData(gridData);

    Composite eBody = new Composite(eventBody, SWT.FILL);
    gridLayout = new GridLayout(2, false);
    eBody.setLayout(gridLayout);
    gridData = new GridData(GridData.FILL_VERTICAL);
    gridData.verticalAlignment = SWT.TOP;
    eBody.setLayoutData(gridData);

    // Events
    Label eventLbl = new Label(eBody, SWT.LEFT);
    eventLbl.setText("Event:");

    eventCbx = new Combo(eBody, SWT.NONE);
    fillEventTypesList();

    // Create a new Event
    if (event == null) {
      event = createEvent(eventCbx.getItem(0));
    } else {
      // We need to copy the original event in case the user cancels his changes
      event = WidgetCopier.copy(event);
    }
    eventCbx.setText(event.getEventName());

    eventCbx.addSelectionListener(
        new SelectionAdapter() {

          public void widgetSelected(SelectionEvent e) {
            String eventName = ((Combo) e.getSource()).getText();
            event.setEventName(eventName);
            createProperties();
            // DS-3322 - Page Designer - Refactoring - begin
            //                event.eAdapters().remove(localizable);
            //                localizable = (Localizable)
            // EventLocalizableAdapterFactory.INSTANCE.adapt(event, Localizable.class);
            //                editor.setLocalizable(localizable);
            //                editor.setReadOnly(isReadOnly(widget));
            // DS-3322 - Page Designer - Refactoring - end
            fillFunctionsList();
            String selection = null;
            if (fctList.getSelection().length > 0) selection = fctList.getSelection()[0];
            refreshParamControl(selection);
          }
        });

    // Functions
    Label functionsLbl = new Label(eBody, SWT.LEFT);
    functionsLbl.setText("Functions:");
    gridData = new GridData();
    gridData.verticalAlignment = GridData.VERTICAL_ALIGN_BEGINNING;
    functionsLbl.setLayoutData(gridData);

    fctList = new List(eBody, SWT.BORDER | SWT.SINGLE | SWT.V_SCROLL);
    gridData = new GridData(GridData.FILL_VERTICAL);
    gridData.heightHint = 120;
    gridData.widthHint = 120;
    fctList.setLayoutData(gridData);

    fillFunctionsList();

    fctList.addSelectionListener(
        new SelectionAdapter() {

          public void widgetSelected(SelectionEvent e) {
            String funcName = fctList.getSelection()[0];
            event.setFunctionName(funcName);
            createParameters();
            fillParametersList();
            refreshParamControl(funcName);
          }
        });

    // parameters group
    Group paramGroup = new Group(eventBody, SWT.SHADOW_ETCHED_IN | SWT.FILL);
    paramGroup.setText(" Parameters ");
    gridLayout = new GridLayout(1, false);
    paramGroup.setLayout(gridLayout);
    gridData = new GridData(GridData.FILL_BOTH);
    paramGroup.setLayoutData(gridData);
    userParamControl = new UserParameterControl(paramGroup, SWT.FILL);
    userParamControl.setInput(event, null);
    userParamControl.setEnabled(false);

    if (!StringUtils.isEmpty(event.getFunctionName())) {
      fctList.setSelection(new String[] {event.getFunctionName()});
      refreshParamControl(event.getFunctionName());
    }

    // attributes group
    Group def = new Group(body, SWT.SHADOW_ETCHED_IN);
    def.setText(" Attributes ");
    gridLayout = new GridLayout(1, false);
    def.setLayout(gridLayout);
    gridData = new GridData(GridData.FILL_BOTH);
    def.setLayoutData(gridData);

    // Parameters table
    paramsTbl = new Table(def, SWT.SINGLE);
    gridData = new GridData(GridData.FILL_BOTH);
    gridData.heightHint = 100;
    paramsTbl.setLayoutData(gridData);
    paramsTbl.setHeaderVisible(true);
    paramsTbl.setLinesVisible(true);
    addColumn(paramsTbl, "Attribute", 100);
    addColumn(paramsTbl, "Value", 300);
    paramsTbl.addListener(
        SWT.MeasureItem,
        new Listener() {

          public void handleEvent(org.eclipse.swt.widgets.Event event) {
            Double dou = new Double(event.gc.getFontMetrics().getHeight() * 1.12);
            event.height = dou.intValue();
          }
        });
    final TableEditor paramsTblEditor = new TableEditor(paramsTbl);
    // The editor must have the same size as the cell and must not be any
    // smaller than 50 pixels.
    paramsTblEditor.horizontalAlignment = SWT.LEFT;
    paramsTblEditor.grabHorizontal = true;
    paramsTblEditor.grabVertical = true;
    paramsTblEditor.minimumWidth = 50;
    paramsTbl.addListener(
        SWT.MouseDown,
        new Listener() {

          public void handleEvent(org.eclipse.swt.widgets.Event event) {
            int nbColumns = paramsTbl.getColumnCount();
            Rectangle clientArea = paramsTbl.getClientArea();
            Point pt = new Point(event.x, event.y);
            int index = paramsTbl.getTopIndex();
            while (index < paramsTbl.getItemCount()) {
              boolean visible = false;
              TableItem item = paramsTbl.getItem(index);
              for (int cx = 0; cx < nbColumns; cx++) {
                Rectangle rect = item.getBounds(cx);
                if (rect.contains(pt)) {
                  installCellEditor(paramsTblEditor, item, index, cx);
                }
                if (!visible && rect.intersects(clientArea)) {
                  visible = true;
                }
              }
              if (!visible) return;
              index++;
            }
          }
        });

    fillParametersList();

    def = new Group(body, SWT.SHADOW_ETCHED_IN);
    def.setText(" Confirmation Translations ");
    gridLayout = new GridLayout(1, false);
    def.setLayout(gridLayout);
    gridData = new GridData(GridData.FILL_BOTH);
    def.setLayoutData(gridData);

    createProperties();

    // DS-3322 - Page Designer - Refactoring - begin
    //        editor = LocalizableEditorSupportFactory.createLocalizableEditor(def, 2, false, true);
    //        localizable = (Localizable) EventLocalizableAdapterFactory.INSTANCE.adapt(event,
    // Localizable.class);
    //        editor.setLocalizable(localizable);
    //        editor.setReadOnly(isReadOnly(widget));
    //        addListeners();
    // DS-3322 - Page Designer - Refactoring - end

    return comp;
  }