Esempio n. 1
0
  private Table build(Composite parent) {
    table =
        new Table(parent, SWT.BORDER | SWT.WRAP | SWT.FULL_SELECTION | SWT.V_SCROLL | SWT.H_SCROLL);
    table.setHeaderVisible(true);
    table.setLinesVisible(true);

    cols = new TableColumn[9];
    cols[0] = UIUtil.create(table, SWT.LEFT, "Key", cols.length, 0, true, 150);
    cols[1] = UIUtil.create(table, SWT.NONE, "Value", cols.length, 1, true, 600);

    return table;
  }
  public void show(int serverId, Rectangle r) {
    dialog = setDialogLayout(serverId);
    dialog.pack();

    UIUtil.setDialogDefaultFunctions(dialog);

    getOldDescription();

    dialog.setSize(400, 150);
    dialog.setLocation(r.x + 100, r.y + 100);
    dialog.open();
  }
  private Shell setDialogLayout(int serverId) {
    final Shell dialog = new Shell(display, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL | SWT.RESIZE);
    dialog.setText("Add Description");

    dialog.setLayout(UIUtil.formLayout(5, 5));

    Label iconLbl = new Label(dialog, SWT.NONE);
    iconLbl.setImage(Images.COMMENT);
    iconLbl.setLayoutData(UIUtil.formData(0, 10, 0, 10, null, -1, null, -1));

    Label descLbl = new Label(dialog, SWT.WRAP);
    descLbl.setText("Add description to " + targetLocation.getName());
    descLbl.setLayoutData(UIUtil.formData(iconLbl, 10, 0, 10, 100, -10, null, -1));

    descTxt = new Text(dialog, SWT.BORDER);
    descTxt.setLayoutData(UIUtil.formData(0, 30, descLbl, 10, 100, -30, null, -1));

    Button confirmBtn = new Button(dialog, SWT.PUSH);
    confirmBtn.setLayoutData(UIUtil.formData(null, -1, descTxt, 10, 100, -30, null, -1, 150));
    confirmBtn.setText("Confirm");
    confirmBtn.addSelectionListener(
        new SelectionListener() {
          public void widgetSelected(SelectionEvent e) {
            String description = descTxt.getText();
            if (description != null && !"".equals(description)) {
              requestDescription(description);
            }
          }

          public void widgetDefaultSelected(SelectionEvent e) {}
        });

    dialog.setDefaultButton(confirmBtn);

    return dialog;
  }
 public void show(String title, final String message, List<StyleRange> srList) {
   final Shell dialog = new Shell(Display.getDefault(), SWT.DIALOG_TRIM | SWT.RESIZE);
   UIUtil.setDialogDefaultFunctions(dialog);
   dialog.setText(title);
   dialog.setLayout(new GridLayout(1, true));
   final StyledText text =
       new StyledText(dialog, SWT.MULTI | SWT.WRAP | SWT.BORDER | SWT.V_SCROLL);
   GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
   gd.widthHint = 400;
   gd.heightHint = 300;
   text.setLayoutData(gd);
   text.setText(message);
   text.addKeyListener(
       new KeyAdapter() {
         public void keyPressed(KeyEvent e) {
           if (e.stateMask == SWT.CTRL) {
             if (e.keyCode == 'a' || e.keyCode == 'A') {
               text.selectAll();
             }
           }
         }
       });
   if (srList != null && srList.size() > 0) {
     text.setStyleRanges(srList.toArray(new StyleRange[srList.size()]));
   }
   Button btn = new Button(dialog, SWT.PUSH);
   gd = new GridData(SWT.RIGHT, SWT.FILL, false, false);
   gd.widthHint = 100;
   btn.setLayoutData(gd);
   btn.setText("&Close");
   btn.addSelectionListener(
       new SelectionAdapter() {
         public void widgetSelected(SelectionEvent e) {
           dialog.close();
         }
       });
   dialog.pack();
   dialog.open();
 }
  private void createUpperMenu(Composite composite) {
    headerComp = new Composite(composite, SWT.NONE);
    headerComp.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
    headerComp.setLayout(UIUtil.formLayout(0, 0));

    long initialTime = TimeUtil.getCurrentTime(serverId) - DatePeriodUnit.A_DAY.getTime();

    applyBtn = new Button(headerComp, SWT.PUSH);
    applyBtn.setLayoutData(UIUtil.formData(null, -1, 0, 2, 100, -5, null, -1));
    applyBtn.setText("Apply");
    applyBtn.addListener(
        SWT.Selection,
        new Listener() {
          public void handleEvent(Event event) {
            switch (event.type) {
              case SWT.Selection:
                ((Button) event.widget).setEnabled(false);
                try {
                  setInput(sDate, eDate, objType, counter, serverId);
                } catch (Exception e) {
                  e.printStackTrace();
                }
                break;
            }
          }
        });

    Button manualBtn = new Button(headerComp, SWT.PUSH);
    manualBtn.setImage(Images.CTXMENU_RDC);
    manualBtn.setText("Manual");
    manualBtn.setLayoutData(UIUtil.formData(null, -1, 0, 2, applyBtn, -5, null, -1));
    manualBtn.addListener(
        SWT.Selection,
        new Listener() {
          public void handleEvent(Event event) {
            switch (event.type) {
              case SWT.Selection:
                Display display = Display.getCurrent();
                if (display == null) {
                  display = Display.getDefault();
                }

                calDialog = new LoadDualCalendarDialog(display, CounterPastLongDateTotalView.this);
                calDialog.show(UIUtil.getMousePosition());

                break;
            }
          }
        });

    periodCombo = new Combo(headerComp, SWT.VERTICAL | SWT.BORDER | SWT.READ_ONLY);
    periodCombo.setLayoutData(UIUtil.formData(null, -1, 0, 3, manualBtn, -5, null, -1));
    ArrayList<String> periodStrList = new ArrayList<String>();
    for (DatePeriodUnit minute : DatePeriodUnit.values()) {
      periodStrList.add(minute.getLabel());
    }
    periodCombo.setItems(periodStrList.toArray(new String[DatePeriodUnit.values().length]));
    periodCombo.select(2);
    periodCombo.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent e) {
            if (((Combo) e.widget).getSelectionIndex() == 0) {
              setStartEndDate(30);
            } else if (((Combo) e.widget).getSelectionIndex() == 1) {
              setStartEndDate(7);
            } else {
              setStartEndDate(1);
            }
          }

          private void setStartEndDate(int i) {
            long yesterday = TimeUtil.getCurrentTime(serverId) - DatePeriodUnit.A_DAY.getTime();
            long startDate =
                TimeUtil.getCurrentTime(serverId) - (DatePeriodUnit.A_DAY.getTime() * i);
            sDateText.setText(DateUtil.format(startDate, "yyyy-MM-dd"));
            eDateText.setText(DateUtil.format(yesterday, "yyyy-MM-dd"));

            sDate = DateUtil.format(startDate, "yyyyMMdd");
            eDate = DateUtil.format(yesterday, "yyyyMMdd");

            stime = DateUtil.getTime(sDate, "yyyyMMdd");
            etime = DateUtil.getTime(eDate, "yyyyMMdd") + DateUtil.MILLIS_PER_DAY;
          }
        });

    eDateText = new Label(headerComp, SWT.NONE);
    eDateText.setLayoutData(UIUtil.formData(null, -1, 0, 7, periodCombo, -5, null, -1));
    eDateText.setText(DateUtil.format(initialTime - 1, "yyyy-MM-dd"));

    Label windbarLabel = new Label(headerComp, SWT.NONE);
    windbarLabel.setLayoutData(UIUtil.formData(null, -1, 0, 7, eDateText, -5, null, -1));
    windbarLabel.setText("~");

    sDateText = new Label(headerComp, SWT.NONE);
    sDateText.setLayoutData(UIUtil.formData(null, -1, 0, 7, windbarLabel, -5, null, -1));
    sDateText.setText(DateUtil.format(initialTime, "yyyy-MM-dd"));

    serverText = new Label(headerComp, SWT.NONE | SWT.RIGHT);
    serverText.setLayoutData(UIUtil.formData(0, 0, 0, 7, sDateText, -5, null, -1));
    serverText.setText("ⓢ");
  }
  public void createPartControl(Composite parent) {
    window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();

    Composite composite = new Composite(parent, SWT.NONE);
    GridLayout gLayout = new GridLayout(1, true);
    gLayout.horizontalSpacing = 0;
    gLayout.marginHeight = 0;
    gLayout.marginWidth = 0;
    composite.setLayout(gLayout);
    createUpperMenu(composite);

    Composite chartComposite = new Composite(composite, SWT.NONE);
    chartComposite.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true));
    chartComposite.setLayout(UIUtil.formLayout(0, 0));
    this.marginTargetComposite = chartComposite;
    chartComposite.setBackground(ColorUtil.getInstance().getColor(SWT.COLOR_WHITE));

    canvas = new FigureCanvas(chartComposite);
    canvas.setScrollBarVisibility(FigureCanvas.NEVER);
    canvas.setBackground(ColorUtil.getInstance().getColor(SWT.COLOR_WHITE));

    canvas.setLayoutData(UIUtil.formData(0, leftMargin, 0, 0, 100, 0, 100, 0));

    canvas.addControlListener(
        new ControlListener() {
          boolean lock = false;

          public void controlResized(ControlEvent e) {
            org.eclipse.swt.graphics.Rectangle r = canvas.getClientArea();
            if (!lock) {
              lock = true;
              if (ChartUtil.isShowDescriptionAllowSize(r.height)) {
                CounterPastLongDateTotalView.this.setContentDescription(desc);
              } else {
                CounterPastLongDateTotalView.this.setContentDescription("");
              }
              r = canvas.getClientArea();
              lock = false;
            }
            xyGraph.setSize(r.width, r.height);
          }

          public void controlMoved(ControlEvent e) {}
        });
    xyGraph = new XYGraph();
    xyGraph.setShowLegend(false);

    canvas.setContents(xyGraph);

    xyGraph.primaryXAxis.setDateEnabled(true);
    xyGraph.primaryXAxis.setShowMajorGrid(true);

    xyGraph.primaryYAxis.setAutoScale(true);
    xyGraph.primaryYAxis.setShowMajorGrid(true);

    xyGraph.primaryXAxis.setTitle("");
    xyGraph.primaryYAxis.setTitle("");

    traceDataProvider = new CircularBufferDataProvider(true);
    //		traceDataProvider.setBufferSize(buffer);
    traceDataProvider.setCurrentXDataArray(new double[] {});
    traceDataProvider.setCurrentYDataArray(new double[] {});

    // create the trace
    trace = new Trace("TOTAL", xyGraph.primaryXAxis, xyGraph.primaryYAxis, traceDataProvider);

    // set trace property
    trace.setPointStyle(PointStyle.NONE);
    trace.getXAxis().setFormatPattern("yyyy-MM-dd\n  HH:mm:ss");
    trace.getYAxis().setFormatPattern("#,##0");

    trace.setLineWidth(PManager.getInstance().getInt(PreferenceConstants.P_CHART_LINE_WIDTH));
    trace.setTraceType(TraceType.AREA);
    trace.setTraceColor(ColorUtil.getInstance().TOTAL_CHART_COLOR);

    xyGraph.primaryXAxis.setTitle("");
    xyGraph.primaryYAxis.setTitle("");

    // add the trace to xyGraph
    xyGraph.addTrace(trace);
    ChartUtil.addSolidLine(xyGraph, traceDataProvider, ColorUtil.getInstance().TOTAL_CHART_COLOR);

    ScouterUtil.addShowTotalValueListener(canvas, xyGraph);

    man = getViewSite().getActionBars().getToolBarManager();

    canvas.addKeyListener(
        new KeyListener() {
          public void keyReleased(KeyEvent e) {}

          public void keyPressed(KeyEvent e) {
            if (e.keyCode == SWT.F5) {
              ExUtil.asyncRun(
                  new Runnable() {
                    public void run() {
                      try {
                        setInput(sDate, eDate, objType, counter, serverId);
                      } catch (Exception e) {
                        e.printStackTrace();
                      }
                    }
                  });
            }
          }
        });

    man.add(
        new Action("Reload", ImageUtil.getImageDescriptor(Images.refresh)) {
          public void run() {
            ExUtil.exec(
                new Runnable() {
                  public void run() {
                    try {
                      setInput(sDate, eDate, objType, counter, serverId);
                    } catch (Exception e) {
                      e.printStackTrace();
                    }
                  }
                });
          }
        });

    man.add(new Separator());
    man.add(
        new Action("Duplicate", ImageUtil.getImageDescriptor(Images.copy)) {
          public void run() {
            ExUtil.exec(
                new Runnable() {
                  public void run() {
                    duplicateView();
                  }
                });
          }
        });

    restoreState();
  }
Esempio n. 7
0
  public void createPartControl(final Composite parent) {
    parent.setBackground(ColorUtil.getInstance().getColor(SWT.COLOR_WHITE));
    parent.setBackgroundMode(SWT.INHERIT_FORCE);
    parent.setLayout(UIUtil.formLayout(0, 0));
    GridLayout layout = new GridLayout(1, true);
    layout.marginHeight = MARGIN;
    layout.marginWidth = MARGIN;
    scroll = new ScrolledComposite(parent, SWT.H_SCROLL | SWT.V_SCROLL);
    scroll.setLayoutData(UIUtil.formData(0, 0, 0, 0, 100, 0, 100, 0));
    canvas = new Canvas(scroll, SWT.DOUBLE_BUFFERED);
    canvas.setLayout(layout);
    canvas.addPaintListener(
        new PaintListener() {
          public void paintControl(PaintEvent e) {
            try {
              area = canvas.getClientArea();
              winYSize = parent.getSize().y;
              drawEQImage(e.gc);
            } catch (Throwable t) {
            }
          }
        });
    canvas.addMouseListener(
        new MouseAdapter() {
          public void mouseDoubleClick(MouseEvent e) {
            if (unitHeight == 0 || datas == null) {
              return;
            }
            if (e.y <= AXIS_PADDING) {
              return;
            }
            int index = (e.y - AXIS_PADDING) / unitHeight;
            if (datas.length < index + 1 || datas[index].isAlive == false) {
              return;
            }
            AgentObject agent = AgentModelThread.getInstance().getAgentObject(datas[index].objHash);
            new OpenCxtmenuActiveServiceListAction(
                    getSite().getWorkbenchWindow(),
                    MenuStr.ACTIVE_SERVICE_LIST,
                    datas[index].objHash,
                    agent.getObjType(),
                    agent.getServerId())
                .run();
          }
        });

    scroll.setContent(canvas);
    scroll.setExpandVertical(true);
    scroll.setExpandHorizontal(true);

    scroll.addListener(
        SWT.MouseWheel,
        new Listener() {
          public void handleEvent(Event event) {
            Point origin = scroll.getOrigin();
            origin.y += (event.count * -1) * 10;
            scroll.setOrigin(origin);
          }
        });

    // canvas.setToolTipText("Double click to list active services");
    thread = new RefreshThread(this, REFRESH_INTERVAL);
    thread.start();
  }
Esempio n. 8
0
  public void show(long stime, long etime) {
    final Shell dialog = new Shell(display, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
    dialog.setLayout(new GridLayout(4, false));
    dialog.setText("Time Range");
    UIUtil.setDialogDefaultFunctions(dialog);

    Label label = new Label(dialog, SWT.NONE);
    label.setText("From");
    final DateTime startTime = new DateTime(dialog, SWT.TIME | SWT.SHORT);
    startTime.setHours(DateUtil.getHour(stime));
    startTime.setMinutes(DateUtil.getMin(stime));

    label = new Label(dialog, SWT.NONE);
    label.setText("To");
    final DateTime endTime = new DateTime(dialog, SWT.TIME | SWT.SHORT);
    endTime.setHours(DateUtil.getHour(etime));
    endTime.setMinutes(DateUtil.getMin(etime));

    Button okButton = new Button(dialog, SWT.PUSH);
    okButton.setText("&OK");
    okButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 2, 1));
    okButton.addListener(
        SWT.Selection,
        new Listener() {
          public void handleEvent(Event event) {
            switch (event.type) {
              case SWT.Selection:
                try {
                  String fromTime =
                      yyyymmdd
                          + (startTime.getHours() < 10 ? "0" : "")
                          + startTime.getHours()
                          + (startTime.getMinutes() < 10 ? "0" : "")
                          + startTime.getMinutes();
                  String toTime =
                      yyyymmdd
                          + (endTime.getHours() < 10 ? "0" : "")
                          + endTime.getHours()
                          + (endTime.getMinutes() < 10 ? "0" : "")
                          + endTime.getMinutes();
                  long stime = DateUtil.getTime(fromTime, "yyyyMMddHHmm");
                  long etime = DateUtil.getTime(toTime, "yyyyMMddHHmm");
                  if (etime <= stime) {
                    MessageDialog.openWarning(
                        dialog,
                        "Warning",
                        "Time range is incorrect. "
                            + DateUtil.timestamp(stime)
                            + " ~ "
                            + DateUtil.timestamp(etime));
                  } else {
                    callback.setTimeRange(stime, etime);
                    dialog.close();
                  }
                } catch (Exception e) {
                  e.printStackTrace();
                  MessageDialog.openError(dialog, "Error", "Date format error:" + e.getMessage());
                }
                break;
            }
          }
        });

    Button cancelButton = new Button(dialog, SWT.PUSH);
    cancelButton.setText("&Cancel");
    cancelButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 2, 1));
    cancelButton.addListener(
        SWT.Selection,
        new Listener() {
          public void handleEvent(Event event) {
            switch (event.type) {
              case SWT.Selection:
                dialog.close();
                break;
            }
          }
        });

    dialog.setDefaultButton(okButton);
    dialog.pack();
    dialog.open();
  }