private void addPlainAction(RuleAction menuAction) {
    final ToolItem button = new ToolItem(mLayoutToolBar, SWT.PUSH);

    URL iconUrl = menuAction.getIconUrl();
    String title = menuAction.getTitle();
    if (iconUrl != null) {
      button.setImage(IconFactory.getInstance().getIcon(iconUrl));
      button.setToolTipText(title);
    } else {
      button.setText(title);
    }
    button.setData(menuAction);

    button.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            RuleAction menuAction = (RuleAction) button.getData();
            menuAction
                .getCallback()
                .action(menuAction, getSelectedNodes(), menuAction.getId(), false);
            updateSelection();
          }
        });
  }
  private void updateToolItem() {
    final ToolItem item = (ToolItem) this.widget;

    final boolean shouldBeEnabled = isEnabled();

    // disabled command + visibility follows enablement == disposed
    if (item.isDisposed()) {
      return;
    }

    final String text = this.label;
    if ((this.icon == null || (this.mode & MODE_FORCE_TEXT) == MODE_FORCE_TEXT) && text != null) {
      item.setText(text);
    }

    final String toolTipText = getToolTipText(text);
    item.setToolTipText(toolTipText);

    if (item.getSelection() != this.checkedState) {
      item.setSelection(this.checkedState);
    }

    if (item.getEnabled() != shouldBeEnabled) {
      item.setEnabled(shouldBeEnabled);
    }
  }
Ejemplo n.º 3
0
 private org.eclipse.swt.widgets.ToolItem addToolItem(
     final org.eclipse.swt.widgets.ToolBar toolbar,
     final org.eclipse.swt.examples.paint.Tool tool) {
   final java.lang.String id = tool.group + '.' + tool.name;
   org.eclipse.swt.widgets.ToolItem item =
       new org.eclipse.swt.widgets.ToolItem(toolbar, tool.type);
   item.setText(getResourceString(id + ".label"));
   item.setToolTipText(getResourceString(id + ".tooltip"));
   item.setImage(tool.image);
   item.addSelectionListener(
       new org.eclipse.swt.events.SelectionAdapter() {
         public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
           tool.action.run();
         }
       });
   final int childID = toolbar.indexOf(item);
   toolbar
       .getAccessible()
       .addAccessibleListener(
           new org.eclipse.swt.accessibility.AccessibleAdapter() {
             public void getName(org.eclipse.swt.accessibility.AccessibleEvent e) {
               if (e.childID == childID) {
                 e.result = getResourceString(id + ".description");
               }
             }
           });
   return item;
 }
  private void addToggle(Toggle toggle) {
    final ToolItem button = new ToolItem(mLayoutToolBar, SWT.CHECK);

    URL iconUrl = toggle.getIconUrl();
    String title = toggle.getTitle();
    if (iconUrl != null) {
      button.setImage(IconFactory.getInstance().getIcon(iconUrl));
      button.setToolTipText(title);
    } else {
      button.setText(title);
    }
    button.setData(toggle);

    button.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            Toggle toggle = (Toggle) button.getData();
            toggle
                .getCallback()
                .action(toggle, getSelectedNodes(), toggle.getId(), button.getSelection());
            updateSelection();
          }
        });
    if (toggle.isChecked()) {
      button.setSelection(true);
    }
  }
  private void addDropdown(RuleAction.Choices choices) {
    final ToolItem combo = new ToolItem(mLayoutToolBar, SWT.DROP_DOWN);
    URL iconUrl = choices.getIconUrl();
    if (iconUrl != null) {
      combo.setImage(IconFactory.getInstance().getIcon(iconUrl));
      combo.setToolTipText(choices.getTitle());
    } else {
      combo.setText(choices.getTitle());
    }
    combo.setData(choices);

    Listener menuListener =
        new Listener() {
          @Override
          public void handleEvent(Event event) {
            Menu menu = new Menu(mLayoutToolBar.getShell(), SWT.POP_UP);
            RuleAction.Choices choices = (Choices) combo.getData();
            List<URL> icons = choices.getIconUrls();
            List<String> titles = choices.getTitles();
            List<String> ids = choices.getIds();
            String current =
                choices.getCurrent() != null ? choices.getCurrent() : ""; // $NON-NLS-1$

            for (int i = 0; i < titles.size(); i++) {
              String title = titles.get(i);
              final String id = ids.get(i);
              URL itemIconUrl = icons != null && icons.size() > 0 ? icons.get(i) : null;
              MenuItem item = new MenuItem(menu, SWT.CHECK);
              item.setText(title);
              if (itemIconUrl != null) {
                Image itemIcon = IconFactory.getInstance().getIcon(itemIconUrl);
                item.setImage(itemIcon);
              }

              boolean selected = id.equals(current);
              if (selected) {
                item.setSelection(true);
              }

              item.addSelectionListener(
                  new SelectionAdapter() {
                    @Override
                    public void widgetSelected(SelectionEvent e) {
                      RuleAction.Choices choices = (Choices) combo.getData();
                      choices.getCallback().action(choices, getSelectedNodes(), id, null);
                      updateSelection();
                    }
                  });
            }

            Rectangle bounds = combo.getBounds();
            Point location = new Point(bounds.x, bounds.y + bounds.height);
            location = combo.getParent().toDisplay(location);
            menu.setLocation(location.x, location.y);
            menu.setVisible(true);
          }
        };
    combo.addListener(SWT.Selection, menuListener);
  }
Ejemplo n.º 6
0
 private void createToolBar(final Composite parent) {
   ToolBar toolBar = new ToolBar(parent, SWT.NONE);
   toolBar.setLayoutData(
       GridDataFactory.fillDefaults().align(SWT.FILL, SWT.TOP).grab(true, false).create());
   ToolItem toolItem = new ToolItem(toolBar, SWT.NONE);
   toolItem.setText("Camera Demo");
   Widgets.onToolItem(toolItem).useAsTitle();
 }
 private static ToolItem createToolItem(
     ToolBar toolBar, String text, String toolTipText, Image image, int style) {
   ToolItem toolItem = new ToolItem(toolBar, style);
   toolItem.setText(text);
   toolItem.setToolTipText(toolTipText);
   toolItem.setImage(image);
   return toolItem;
 }
 private void createFeedback() {
   dragShell = new Shell(SWT.NO_TRIM | SWT.NO_BACKGROUND);
   dragShell.setAlpha(175);
   ToolBar dragTB = new ToolBar(dragShell, SWT.RIGHT);
   ToolItem newTI = new ToolItem(dragTB, SWT.RADIO);
   newTI.setText(dragItem.getText());
   newTI.setImage(dragItem.getImage());
   dragTB.pack();
   dragShell.pack();
   dragShell.setVisible(true);
 }
 private void updateToolItem(ToolItem ti, String attName, Object newValue) {
   boolean showText =
       PrefUtil.getAPIPreferenceStore()
           .getBoolean(IWorkbenchPreferenceConstants.SHOW_TEXT_ON_PERSPECTIVE_BAR);
   if (showText && UIEvents.UILabel.LABEL.equals(attName)) {
     String newName = (String) newValue;
     ti.setText(newName);
   } else if (UIEvents.UILabel.TOOLTIP.equals(attName)) {
     String newTTip = (String) newValue;
     ti.setToolTipText(newTTip);
   }
 }
  /** This method initializes barCommands */
  private void createBarCommands() {
    ToolBar barCommands = new ToolBar(shell, SWT.HORIZONTAL);
    barCommands.setLayoutData(new GridData(SWT.END, SWT.FILL, true, false));

    ToolItem btnReplace = new ToolItem(barCommands, SWT.PUSH | SWT.BORDER);
    btnReplace.setText("Replace");
    btnReplace.addSelectionListener(
        new SelectionListener() {
          @Override
          public void widgetDefaultSelected(SelectionEvent e) {
            String runningUser = replaceRunningUserTableComposite.getTxtReplaceRunningUserString();
            if (deployDashboardProcess.replaceRunningUserWith(runningUser)) {
              shell.close();
            } else {
              replaceRunningUserTableComposite.enableErrorMessage();
            }
          }

          @Override
          public void widgetSelected(SelectionEvent e) {
            widgetDefaultSelected(e);
          }
        });

    ToolItem btnClose = new ToolItem(barCommands, SWT.PUSH | SWT.BORDER);
    btnClose.setText("Cancel");
    btnClose.addSelectionListener(
        new SelectionListener() {
          @Override
          public void widgetDefaultSelected(SelectionEvent e) {
            shell.close();
          }

          @Override
          public void widgetSelected(SelectionEvent e) {
            widgetDefaultSelected(e);
          }
        });
  }
Ejemplo n.º 11
0
 /**
  * Creates a top-level menu and adds it to the Riena menu bar.
  *
  * @param menuManager
  * @param listener
  */
 private ToolItem createAndAddMenu(
     final MenuManager menuManager, final ToolBarMenuListener listener) {
   if (menuManager.isVisible()) {
     final ToolItem toolItem = new ToolItem(menuToolBar, SWT.CHECK);
     toolItem.setText(menuManager.getMenuText());
     final MenuManagerHelper helper = new MenuManagerHelper();
     final Menu menu = helper.createMenu(menuToolBar, toolItem, menuManager);
     toolItem.setData(MENU_DATA_KEY, menu);
     calcSize(menuCoolItem);
     toolItem.addSelectionListener(listener);
     return toolItem;
   }
   return null;
 }
 private void makeEntry(final IContributionItem item) {
   IContributionItem tempItem = null;
   if (item instanceof SubContributionItem) {
     SubContributionItem subItem = (SubContributionItem) item;
     tempItem = subItem.getInnerItem();
   } else if (item instanceof MenuManager) {
     tempItem = item;
   }
   if (tempItem != null && tempItem instanceof MenuManager) {
     final MenuManager manager = (MenuManager) tempItem;
     int style = extractStyle(manager);
     final ToolItem toolItem = new ToolItem(toolbar, style);
     toolItem.setText(manager.getMenuText());
     toolItem.setData(WidgetUtil.CUSTOM_VARIANT, MENU_BAR_VARIANT);
     createMenu(manager, toolItem);
     // needed to clear all controls in case of an update
     toolItemList.add(toolItem);
   }
 }
  @Override
  protected void applyCSSProperty(
      Control control, String property, CSSValue value, String pseudo, CSSEngine engine)
      throws Exception {
    if (!(control instanceof ToolBar)) return;

    ToolBar toolBar = (ToolBar) control;
    if (ICathyConstants.PROPERTY_TOOL_ITEM_COLOR.equals(property)) {
      Color color = (Color) engine.convert(value, Color.class, toolBar.getDisplay());
      toolBar.setForeground(color);

      ToolItem[] items = toolBar.getItems();
      for (ToolItem each : items) {
        String text = each.getText();
        each.setText(text);
      }
    } else if (ICathyConstants.PROPERTY_VIEW_MENU.equals(property)) {
      if (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) {
        if (((CSSPrimitiveValue) value).getPrimitiveType() == CSSPrimitiveValue.CSS_URI) {
          String imageUrl = ((CSSPrimitiveValue) value).getStringValue();
          ImageDescriptor imageDescriptor =
              ImageDescriptor.createFromURL(new URL(imageUrl.toString()));
          Image image = JFaceResources.getResources().createImage(imageDescriptor);
          if (TOOLBAR_TAG_VIEW_MENU.equals(toolBar.getData())) {
            toolBar.getItem(0).setImage(image);
          }
        }
      }
    }
    //        else if ("xswt-view-properties-pin".equals(property)) {
    //            ToolItem[] items = toolBar.getItems();
    //            for (ToolItem each : items) {
    //                Object data = each.getData();
    //                if (data instanceof ActionContributionItem) {
    //                    String id = ((ActionContributionItem) data).getId();
    //                    if (id.contains("org.eclipse.ui.views.properties.PinPropertySheetAction"))
    // {
    //
    //                    }
    //                }
    //            }
    //        }
  }
  private void addActions(List<RuleAction> actions, int labelIndex, String label) {
    if (actions.size() > 0) {
      // Flag used to indicate that if there are any actions -after- this, it
      // should be separated from this current action (we don't unconditionally
      // add a separator at the end of these groups in case there are no more
      // actions at the end so that we don't have a trailing separator)
      boolean needSeparator = false;

      int index = 0;
      for (RuleAction action : actions) {
        if (index == labelIndex) {
          final ToolItem button = new ToolItem(mLayoutToolBar, SWT.PUSH);
          button.setText(label);
          needSeparator = false;
        }
        index++;

        if (action instanceof Separator) {
          addSeparator(mLayoutToolBar);
          needSeparator = false;
          continue;
        } else if (needSeparator) {
          addSeparator(mLayoutToolBar);
          needSeparator = false;
        }

        if (action instanceof RuleAction.Choices) {
          RuleAction.Choices choices = (Choices) action;
          if (!choices.isRadio()) {
            addDropdown(choices);
          } else {
            addSeparator(mLayoutToolBar);
            addRadio(choices);
            needSeparator = true;
          }
        } else if (action instanceof RuleAction.Toggle) {
          addToggle((Toggle) action);
        } else {
          addPlainAction(action);
        }
      }
    }
  }
 /**
  * Create the composite.
  *
  * @param parent a widget which will be the parent of the new instance (cannot be null)
  * @param style the style of widget to construct
  */
 public VisualisationDiffToolBar(Composite parent, int style) {
   super(parent, style);
   createActions();
   setLayout(new FormLayout());
   /** Left Tool Bar */
   Composite leftToolBarComposite = new Composite(this, SWT.NONE);
   leftToolBarComposite.setLayout(new FormLayout());
   FormData fdleftToolBarComposite = new FormData();
   fdleftToolBarComposite.top = new FormAttachment(0);
   fdleftToolBarComposite.left = new FormAttachment(0);
   leftToolBarComposite.setLayoutData(fdleftToolBarComposite);
   ToolBar leftToolBar = new ToolBar(leftToolBarComposite, SWT.FLAT | SWT.RIGHT);
   FormData fdleftToolBar = new FormData();
   fdleftToolBar.top = new FormAttachment(0);
   leftToolBar.setLayoutData(fdleftToolBar);
   visualizationType = new ToolItem(leftToolBar, SWT.NONE);
   visualizationType.setImage(
       ResourceManager.getPluginImage(
           "org.eclipse.emf.compare.ui.2", "iconsMainTBar/differencesIcon.gif"));
   visualizationType.setText("Visualizatin of Structural Differences");
   // lblNewLabel.setImage(ResourceManager.getPluginImage("org.eclipse.emf.compare.ui.2",
   // "icons/next_nav_into.gif"));
   leftToolBar.update();
   /** RighToolBar */
   ToolBar righToolBar = new ToolBar(this, SWT.FLAT | SWT.RIGHT);
   FormData fdRighToolBar = new FormData();
   fdRighToolBar.top = new FormAttachment(0);
   fdRighToolBar.right = new FormAttachment(100);
   righToolBar.setLayoutData(fdRighToolBar);
   ToolBarManager righToolBarManager = new ToolBarManager(righToolBar);
   createAncestorPaneManagerAction(righToolBarManager, EMFCompareConfiguration.fThreeWay);
   righToolBarManager.add(copyAlltoRight);
   righToolBarManager.add(copyAlltoLeft);
   righToolBarManager.add(copyLeftTorRight);
   righToolBarManager.add(copyRightToLeft);
   righToolBarManager.add(new Separator());
   righToolBarManager.add(nextChange);
   righToolBarManager.add(previousChange);
   righToolBar.update();
   righToolBarManager.update(true);
 }
 @Override
 protected Control createControl(Composite parent) {
   bar = new ToolBar(parent, SWT.HORIZONTAL | SWT.FLAT | SWT.RIGHT);
   ToolItem item;
   for (IPerspectiveDescriptor desc :
       PlatformUI.getWorkbench().getPerspectiveRegistry().getPerspectives()) {
     item = new ToolItem(bar, SWT.CHECK);
     item.setImage(desc.getImageDescriptor().createImage());
     item.setText(desc.getLabel());
     item.setToolTipText(desc.getDescription());
     item.setSelection(
         desc.getId()
             .equals(PlatformUI.getWorkbench().getPerspectiveRegistry().getDefaultPerspective()));
     item.setData(desc.getId());
     item.addSelectionListener(
         new SelectionListenerWithData<String>(desc.getId()) {
           public void widgetSelected(SelectionEvent e) {
             selectPerspective(data());
           }
         });
   }
   return bar;
 }
  private ToolItem addPerspectiveItem(MPerspective persp) {
    int perspIndex = persp.getParent().getChildren().indexOf(persp);

    int index = perspIndex + 2; // HACK !! accounts for the 'open' and the
    // separator
    final ToolItem psItem =
        index < psTB.getItemCount()
            ? new ToolItem(psTB, SWT.RADIO, index)
            : new ToolItem(psTB, SWT.RADIO);
    psItem.setData(persp);
    IPerspectiveDescriptor descriptor = getDescriptorFor(persp.getElementId());
    boolean foundImage = false;
    if (descriptor != null) {
      ImageDescriptor desc = descriptor.getImageDescriptor();
      if (desc != null) {
        final Image image = desc.createImage(false);
        if (image != null) {
          psItem.setImage(image);

          psItem.addListener(
              SWT.Dispose,
              new Listener() {
                public void handleEvent(org.eclipse.swt.widgets.Event event) {
                  image.dispose();
                }
              });
          foundImage = true;
          psItem.setToolTipText(persp.getLocalizedLabel());
        }
      }
    }
    if (!foundImage
        || PrefUtil.getAPIPreferenceStore()
            .getBoolean(IWorkbenchPreferenceConstants.SHOW_TEXT_ON_PERSPECTIVE_BAR)) {
      psItem.setText(persp.getLocalizedLabel());
      psItem.setToolTipText(persp.getLocalizedTooltip());
    }

    psItem.setSelection(persp == persp.getParent().getSelectedElement());

    psItem.addSelectionListener(
        new SelectionListener() {
          public void widgetSelected(SelectionEvent e) {
            MPerspective persp = (MPerspective) e.widget.getData();
            persp.getParent().setSelectedElement(persp);
          }

          public void widgetDefaultSelected(SelectionEvent e) {
            MPerspective persp = (MPerspective) e.widget.getData();
            persp.getParent().setSelectedElement(persp);
          }
        });

    psItem.addListener(
        SWT.MenuDetect,
        new Listener() {
          public void handleEvent(org.eclipse.swt.widgets.Event event) {
            MPerspective persp = (MPerspective) event.widget.getData();
            openMenuFor(psItem, persp);
          }
        });

    // update the size
    fixSize();

    return psItem;
  }
  public void display() throws Exception {
    /*
     * Create the display and shell.
     */
    display = new Display();
    final Shell shell = new Shell(display);
    GridLayout layout = new GridLayout();
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    layout.verticalSpacing = 3;
    shell.setLayout(layout);
    /*
     * Create a toolbar
     */
    {
      ToolBar toolbar = new ToolBar(shell, SWT.FLAT | SWT.RIGHT | SWT.NO_FOCUS);
      toolbar.setForeground(display.getSystemColor(SWT.COLOR_RED));
      toolbar.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL));
      ToolItem item = new ToolItem(toolbar, SWT.PUSH);
      item.setText("File");
      item = new ToolItem(toolbar, SWT.PUSH);
      item.setText("Edit");
      item = new ToolItem(toolbar, SWT.PUSH);
      item.setText("Help");
    }

    if (styleSheetStream == null) {
      // Create Styles themes
      createThemesStyleComposite(shell);
    }

    /*
     * Create a sash form.
     */
    SashForm form = new SashForm(shell, SWT.NONE);
    form.setLayoutData(new GridData(GridData.FILL_BOTH));
    /*
     * Create the buddylist tree.
     */
    {
      tree = new Tree(form, SWT.SINGLE);
      tree.addSelectionListener(
          new SelectionListener() {
            public void widgetDefaultSelected(SelectionEvent e) {
              if (((TreeItem) e.item).getParentItem() != null) {
                try {
                  createChatControl(e.item);
                } catch (Exception ex) {
                  ex.printStackTrace();
                }
              }
            }

            public void widgetSelected(SelectionEvent e) {}
          });
      for (int i = 0; i < GROUPS.length; i++) {
        String g = GROUPS[i];
        TreeItem parentItem = new TreeItem(tree, SWT.NONE);
        parentItem.setText(g);
        for (int j = 0; j < NAMES.length; j++) {
          String n = NAMES[j];
          TreeItem item = new TreeItem(parentItem, SWT.NONE);
          item.setText(n);
        }
        parentItem.setExpanded(true);
      }
    }
    /*
     * Add the tabfolder
     */
    {
      tabFolder = new CTabFolder(form, SWT.CLOSE);
      tabFolder.setUnselectedCloseVisible(true);
      tabFolder.setUnselectedImageVisible(true);
      form.setWeights(new int[] {30, 70});
      // open a couple chats
      createChatControl(tree.getItem(0).getItems()[0]);
      createChatControl(tree.getItem(0).getItems()[1]);
      tabFolder.setSelection(tabFolder.getItem(0));
    }
    /*
     * Create a statusbar
     */
    {
      CLabel statusbar = new CLabel(shell, SWT.NONE);
      GridData gd = new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL);
      statusbar.setLayoutData(gd);
      statusbar.setText("Samantha Daryn is online");
    }
    /*
     * StyleHelper is used to parse and apply styles.
     */
    engine = getCSSEngine();
    if (styleSheetStream != null) {
      engine.parseStyleSheet(styleSheetStream);
      engine.applyStyles(shell, true);
    }
    /*
     * Now we open the shell.
     */
    shell.setSize(new Point(600, 600));
    shell.open();
    shell.setText("CSS Instant Messaging");
    while (!shell.isDisposed()) {
      if (!display.readAndDispatch()) display.sleep();
    }
    display.dispose();
  }
Ejemplo n.º 19
0
  void show(
      boolean owned,
      org.eclipse.swt.graphics.Point location,
      org.eclipse.swt.graphics.Point size,
      boolean addressBar,
      boolean menuBar,
      boolean statusBar,
      boolean toolBar) {
    final org.eclipse.swt.widgets.Shell shell = browser.getShell();
    if (owned) {
      if (location != null) {
        shell.setLocation(location);
      }
      if (size != null) {
        shell.setSize(shell.computeSize(size.x, size.y));
      }
    }
    org.eclipse.swt.layout.FormData data = null;
    if (toolBar) {
      toolbar = new org.eclipse.swt.widgets.ToolBar(parent, SWT.NONE);
      data = new org.eclipse.swt.layout.FormData();
      data.top = new org.eclipse.swt.layout.FormAttachment(0, 5);
      toolbar.setLayoutData(data);
      itemBack = new org.eclipse.swt.widgets.ToolItem(toolbar, SWT.PUSH);
      itemBack.setText(getResourceString("Back"));
      itemForward = new org.eclipse.swt.widgets.ToolItem(toolbar, SWT.PUSH);
      itemForward.setText(getResourceString("Forward"));
      final org.eclipse.swt.widgets.ToolItem itemStop =
          new org.eclipse.swt.widgets.ToolItem(toolbar, SWT.PUSH);
      itemStop.setText(getResourceString("Stop"));
      final org.eclipse.swt.widgets.ToolItem itemRefresh =
          new org.eclipse.swt.widgets.ToolItem(toolbar, SWT.PUSH);
      itemRefresh.setText(getResourceString("Refresh"));
      final org.eclipse.swt.widgets.ToolItem itemGo =
          new org.eclipse.swt.widgets.ToolItem(toolbar, SWT.PUSH);
      itemGo.setText(getResourceString("Go"));
      itemBack.setEnabled(browser.isBackEnabled());
      itemForward.setEnabled(!browser.isForwardEnabled());
      org.eclipse.swt.widgets.Listener listener =
          new org.eclipse.swt.widgets.Listener() {
            public void handleEvent(org.eclipse.swt.widgets.Event event) {
              org.eclipse.swt.widgets.ToolItem item =
                  (org.eclipse.swt.widgets.ToolItem) event.widget;
              if (item == itemBack) {
                browser.back();
              } else {
                if (item == itemForward) {
                  browser.forward();
                } else {
                  if (item == itemStop) {
                    browser.stop();
                  } else {
                    if (item == itemRefresh) {
                      browser.refresh();
                    } else {
                      if (item == itemGo) {
                        browser.setUrl(locationBar.getText());
                      }
                    }
                  }
                }
              }
            }
          };
      itemBack.addListener(SWT.Selection, listener);
      itemForward.addListener(SWT.Selection, listener);
      itemStop.addListener(SWT.Selection, listener);
      itemRefresh.addListener(SWT.Selection, listener);
      itemGo.addListener(SWT.Selection, listener);
      canvas = new org.eclipse.swt.widgets.Canvas(parent, SWT.NO_BACKGROUND);
      data = new org.eclipse.swt.layout.FormData();
      data.width = 24;
      data.height = 24;
      data.top = new org.eclipse.swt.layout.FormAttachment(0, 5);
      data.right = new org.eclipse.swt.layout.FormAttachment(100, -5);
      canvas.setLayoutData(data);
      final org.eclipse.swt.graphics.Rectangle rect = images[0].getBounds();
      canvas.addListener(
          SWT.Paint,
          new org.eclipse.swt.widgets.Listener() {
            public void handleEvent(org.eclipse.swt.widgets.Event e) {
              org.eclipse.swt.graphics.Point pt =
                  ((org.eclipse.swt.widgets.Canvas) e.widget).getSize();
              e.gc.drawImage(images[index], 0, 0, rect.width, rect.height, 0, 0, pt.x, pt.y);
            }
          });
      canvas.addListener(
          SWT.MouseDown,
          new org.eclipse.swt.widgets.Listener() {
            public void handleEvent(org.eclipse.swt.widgets.Event e) {
              browser.setUrl(getResourceString("Startup"));
            }
          });
      final org.eclipse.swt.widgets.Display display = parent.getDisplay();
      display.asyncExec(
          new java.lang.Runnable() {
            public void run() {
              if (canvas.isDisposed()) {
                return;
              }
              if (busy) {
                index++;
                if (index == images.length) {
                  index = 0;
                }
                canvas.redraw();
              }
              display.timerExec(150, this);
            }
          });
    }
    if (addressBar) {
      locationBar = new org.eclipse.swt.widgets.Text(parent, SWT.BORDER);
      data = new org.eclipse.swt.layout.FormData();
      if (toolbar != null) {
        data.top = new org.eclipse.swt.layout.FormAttachment(toolbar, 0, SWT.TOP);
        data.left = new org.eclipse.swt.layout.FormAttachment(toolbar, 5, SWT.RIGHT);
        data.right = new org.eclipse.swt.layout.FormAttachment(canvas, -5, SWT.DEFAULT);
      } else {
        data.top = new org.eclipse.swt.layout.FormAttachment(0, 0);
        data.left = new org.eclipse.swt.layout.FormAttachment(0, 0);
        data.right = new org.eclipse.swt.layout.FormAttachment(100, 0);
      }
      locationBar.setLayoutData(data);
      locationBar.addListener(
          SWT.DefaultSelection,
          new org.eclipse.swt.widgets.Listener() {
            public void handleEvent(org.eclipse.swt.widgets.Event e) {
              browser.setUrl(locationBar.getText());
            }
          });
    }
    if (statusBar) {
      status = new org.eclipse.swt.widgets.Label(parent, SWT.NONE);
      progressBar = new org.eclipse.swt.widgets.ProgressBar(parent, SWT.NONE);
      data = new org.eclipse.swt.layout.FormData();
      data.left = new org.eclipse.swt.layout.FormAttachment(0, 5);
      data.right = new org.eclipse.swt.layout.FormAttachment(progressBar, 0, SWT.DEFAULT);
      data.bottom = new org.eclipse.swt.layout.FormAttachment(100, -5);
      status.setLayoutData(data);
      data = new org.eclipse.swt.layout.FormData();
      data.right = new org.eclipse.swt.layout.FormAttachment(100, -5);
      data.bottom = new org.eclipse.swt.layout.FormAttachment(100, -5);
      progressBar.setLayoutData(data);
      browser.addStatusTextListener(
          new org.eclipse.swt.browser.StatusTextListener() {
            public void changed(org.eclipse.swt.browser.StatusTextEvent event) {
              status.setText(event.text);
            }
          });
    }
    parent.setLayout(new org.eclipse.swt.layout.FormLayout());
    org.eclipse.swt.widgets.Control aboveBrowser =
        toolBar
            ? (org.eclipse.swt.widgets.Control) canvas
            : addressBar ? (org.eclipse.swt.widgets.Control) locationBar : null;
    data = new org.eclipse.swt.layout.FormData();
    data.left = new org.eclipse.swt.layout.FormAttachment(0, 0);
    data.top =
        aboveBrowser != null
            ? new org.eclipse.swt.layout.FormAttachment(aboveBrowser, 5, SWT.DEFAULT)
            : new org.eclipse.swt.layout.FormAttachment(0, 0);
    data.right = new org.eclipse.swt.layout.FormAttachment(100, 0);
    data.bottom =
        status != null
            ? new org.eclipse.swt.layout.FormAttachment(status, -5, SWT.DEFAULT)
            : new org.eclipse.swt.layout.FormAttachment(100, 0);
    browser.setLayoutData(data);
    if (statusBar || toolBar) {
      browser.addProgressListener(
          new org.eclipse.swt.browser.ProgressListener() {
            public void changed(org.eclipse.swt.browser.ProgressEvent event) {
              if (event.total == 0) {
                return;
              }
              int ratio = event.current * 100 / event.total;
              if (progressBar != null) {
                progressBar.setSelection(ratio);
              }
              busy = event.current != event.total;
              if (!busy) {
                index = 0;
                if (canvas != null) {
                  canvas.redraw();
                }
              }
            }

            public void completed(org.eclipse.swt.browser.ProgressEvent event) {
              if (progressBar != null) {
                progressBar.setSelection(0);
              }
              busy = false;
              index = 0;
              if (canvas != null) {
                itemBack.setEnabled(browser.isBackEnabled());
                itemForward.setEnabled(browser.isForwardEnabled());
                canvas.redraw();
              }
            }
          });
    }
    if (addressBar || statusBar || toolBar) {
      browser.addLocationListener(
          new org.eclipse.swt.browser.LocationListener() {
            public void changed(org.eclipse.swt.browser.LocationEvent event) {
              busy = true;
              if (event.top && locationBar != null) {
                locationBar.setText(event.location);
              }
            }

            public void changing(org.eclipse.swt.browser.LocationEvent event) {}
          });
    }
    if (title) {
      browser.addTitleListener(
          new org.eclipse.swt.browser.TitleListener() {
            public void changed(org.eclipse.swt.browser.TitleEvent event) {
              shell.setText(event.title + " - " + getResourceString("window.title"));
            }
          });
    }
    parent.layout(true);
    if (owned) {
      shell.open();
    }
  }
Ejemplo n.º 20
0
  /*
   * (non-Javadoc)
   *
   * @see
   * org.eclipse.ui.views.properties.tabbed.AbstractPropertySection#createControls
   * (org.eclipse.swt.widgets.Composite,
   * org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage)
   */
  @Override
  public void createControls(
      final Composite parent, TabbedPropertySheetPage aTabbedPropertySheetPage) {

    this.parent = parent;
    this.toolkit = new FormToolkit(parent.getDisplay());
    super.createControls(parent, aTabbedPropertySheetPage);

    if (form != null && !form.isDisposed()) {
      try {
        form.dispose();
      } catch (Exception e) {
        // ignore any expose exceptions
      }
    }
    form = null;

    if (parent.isDisposed()) return;

    parent.setLayout(new GridLayout());
    // parent.setLayout(new GridLayout(1, false));
    parent.setLayoutData(new GridData(GridData.FILL_BOTH));

    form = toolkit.createForm(parent);
    form.setLayoutData(new GridData(GridData.FILL_BOTH));
    form.setText(EditorMessages.propertiesDocumentationTitle);
    toolkit.decorateFormHeading(form);

    form.getBody().setLayout(new GridLayout(1, false));

    Composite sbody = form.getBody();

    ToolBar navBar = new ToolBar(sbody, SWT.NONE);
    toolkit.adapt(navBar);
    navBar.setLayoutData(
        new GridData(GridData.FILL_HORIZONTAL | GridData.HORIZONTAL_ALIGN_BEGINNING));
    final ToolItem back = new ToolItem(navBar, SWT.PUSH);
    back.setText("<");
    back.setEnabled(false);
    final ToolItem forward = new ToolItem(navBar, SWT.PUSH);
    forward.setText(">");
    forward.setEnabled(false);

    back.addListener(
        SWT.Selection,
        new Listener() {
          public void handleEvent(Event event) {
            browser.back();
          }
        });
    forward.addListener(
        SWT.Selection,
        new Listener() {
          public void handleEvent(Event event) {
            browser.forward();
          }
        });

    final LocationListener locationListener =
        new LocationListener() {
          public void changed(LocationEvent event) {
            Browser browser = (Browser) event.widget;
            back.setEnabled(browser.isBackEnabled());
            forward.setEnabled(browser.isForwardEnabled());
          }

          public void changing(LocationEvent event) {}
        };

    browser = new Browser(sbody, SWT.NONE);
    GridData data = new GridData(GridData.FILL_BOTH);
    browser.setLayoutData(data);
    IWorkbenchHelpSystem helpSystem = PlatformUI.getWorkbench().getHelpSystem();
    URL url = helpSystem.resolve("org.fusesource.ide.help/index.html", true);
    browser.setUrl(url.toExternalForm());
    browser.addLocationListener(locationListener);

    // section.pack();
    // form.pack();
    form.layout(true, true);
    parent.layout(true, true);

    // in case of timing issues, lets do another layout just in case...
    Display.getCurrent()
        .asyncExec(
            new Runnable() {
              @Override
              public void run() {
                if (form != null && !form.isDisposed()) {
                  form.layout(true, true);
                }
                if (parent != null && !parent.isDisposed()) {
                  parent.layout(true, true);
                }
              }
            });
  }
Ejemplo n.º 21
0
 public void createPartControl(org.eclipse.swt.widgets.Composite frame) {
   final org.eclipse.swt.examples.hoverhelp.HoverHelp.ToolTipHandler tooltip =
       new org.eclipse.swt.examples.hoverhelp.HoverHelp.ToolTipHandler(frame.getShell());
   org.eclipse.swt.layout.GridLayout layout = new org.eclipse.swt.layout.GridLayout();
   layout.numColumns = 3;
   frame.setLayout(layout);
   java.lang.String platform = SWT.getPlatform();
   java.lang.String helpKey = "F1";
   if (platform.equals("gtk")) {
     helpKey = "Ctrl+F1";
   }
   if (platform.equals("carbon") || platform.equals("cocoa")) {
     helpKey = "Help";
   }
   org.eclipse.swt.widgets.ToolBar bar = new org.eclipse.swt.widgets.ToolBar(frame, SWT.BORDER);
   for (int i = 0; i < 5; i++) {
     org.eclipse.swt.widgets.ToolItem item = new org.eclipse.swt.widgets.ToolItem(bar, SWT.PUSH);
     item.setText(
         getResourceString("ToolItem.text", new java.lang.Object[] {new java.lang.Integer(i)}));
     item.setData(
         "TIP_TEXT",
         getResourceString("ToolItem.tooltip", new java.lang.Object[] {item.getText(), helpKey}));
     item.setData(
         "TIP_HELPTEXTHANDLER",
         new org.eclipse.swt.examples.hoverhelp.HoverHelp.ToolTipHelpTextHandler() {
           public java.lang.String getHelpText(org.eclipse.swt.widgets.Widget widget) {
             org.eclipse.swt.widgets.Item item = (org.eclipse.swt.widgets.Item) widget;
             return getResourceString("ToolItem.help", new java.lang.Object[] {item.getText()});
           }
         });
   }
   org.eclipse.swt.layout.GridData gridData = new org.eclipse.swt.layout.GridData();
   gridData.horizontalSpan = 3;
   bar.setLayoutData(gridData);
   tooltip.activateHoverHelp(bar);
   org.eclipse.swt.widgets.Table table = new org.eclipse.swt.widgets.Table(frame, SWT.BORDER);
   for (int i = 0; i < 4; i++) {
     org.eclipse.swt.widgets.TableItem item =
         new org.eclipse.swt.widgets.TableItem(table, SWT.PUSH);
     item.setText(getResourceString("Item", new java.lang.Object[] {new java.lang.Integer(i)}));
     item.setData("TIP_IMAGE", images[hhiInformation]);
     item.setText(
         getResourceString("TableItem.text", new java.lang.Object[] {new java.lang.Integer(i)}));
     item.setData(
         "TIP_TEXT",
         getResourceString("TableItem.tooltip", new java.lang.Object[] {item.getText(), helpKey}));
     item.setData(
         "TIP_HELPTEXTHANDLER",
         new org.eclipse.swt.examples.hoverhelp.HoverHelp.ToolTipHelpTextHandler() {
           public java.lang.String getHelpText(org.eclipse.swt.widgets.Widget widget) {
             org.eclipse.swt.widgets.Item item = (org.eclipse.swt.widgets.Item) widget;
             return getResourceString("TableItem.help", new java.lang.Object[] {item.getText()});
           }
         });
   }
   table.setLayoutData(new org.eclipse.swt.layout.GridData(GridData.VERTICAL_ALIGN_FILL));
   tooltip.activateHoverHelp(table);
   org.eclipse.swt.widgets.Tree tree = new org.eclipse.swt.widgets.Tree(frame, SWT.BORDER);
   for (int i = 0; i < 4; i++) {
     org.eclipse.swt.widgets.TreeItem item = new org.eclipse.swt.widgets.TreeItem(tree, SWT.PUSH);
     item.setText(getResourceString("Item", new java.lang.Object[] {new java.lang.Integer(i)}));
     item.setData("TIP_IMAGE", images[hhiWarning]);
     item.setText(
         getResourceString("TreeItem.text", new java.lang.Object[] {new java.lang.Integer(i)}));
     item.setData(
         "TIP_TEXT",
         getResourceString("TreeItem.tooltip", new java.lang.Object[] {item.getText(), helpKey}));
     item.setData(
         "TIP_HELPTEXTHANDLER",
         new org.eclipse.swt.examples.hoverhelp.HoverHelp.ToolTipHelpTextHandler() {
           public java.lang.String getHelpText(org.eclipse.swt.widgets.Widget widget) {
             org.eclipse.swt.widgets.Item item = (org.eclipse.swt.widgets.Item) widget;
             return getResourceString("TreeItem.help", new java.lang.Object[] {item.getText()});
           }
         });
   }
   tree.setLayoutData(new org.eclipse.swt.layout.GridData(GridData.VERTICAL_ALIGN_FILL));
   tooltip.activateHoverHelp(tree);
   org.eclipse.swt.widgets.Button button = new org.eclipse.swt.widgets.Button(frame, SWT.PUSH);
   button.setText(getResourceString("Hello.text"));
   button.setData("TIP_TEXT", getResourceString("Hello.tooltip"));
   tooltip.activateHoverHelp(button);
 }
Ejemplo n.º 22
0
  public static void main(String[] args) {
    Display display = new Display();
    final Shell shell = new Shell(display);
    GridLayout gridLayout = new GridLayout();
    gridLayout.numColumns = 3;
    shell.setLayout(gridLayout);
    ToolBar toolbar = new ToolBar(shell, SWT.NONE);
    ToolItem itemBack = new ToolItem(toolbar, SWT.PUSH);
    itemBack.setText("Back");
    ToolItem itemForward = new ToolItem(toolbar, SWT.PUSH);
    itemForward.setText("Forward");
    ToolItem itemStop = new ToolItem(toolbar, SWT.PUSH);
    itemStop.setText("Stop");
    ToolItem itemRefresh = new ToolItem(toolbar, SWT.PUSH);
    itemRefresh.setText("Refresh");
    ToolItem itemGo = new ToolItem(toolbar, SWT.PUSH);
    itemGo.setText("Go");

    GridData data = new GridData();
    data.horizontalSpan = 3;
    toolbar.setLayoutData(data);

    Label labelAddress = new Label(shell, SWT.NONE);
    labelAddress.setText("Address");

    final Text location = new Text(shell, SWT.BORDER);
    data = new GridData();
    data.horizontalAlignment = GridData.FILL;
    data.horizontalSpan = 2;
    data.grabExcessHorizontalSpace = true;
    location.setLayoutData(data);

    final Browser browser;
    try {
      browser = new Browser(shell, SWT.NONE);
    } catch (SWTError e) {
      System.out.println("Could not instantiate Browser: " + e.getMessage());
      display.dispose();
      return;
    }
    data = new GridData();
    data.horizontalAlignment = GridData.FILL;
    data.verticalAlignment = GridData.FILL;
    data.horizontalSpan = 3;
    data.grabExcessHorizontalSpace = true;
    data.grabExcessVerticalSpace = true;
    browser.setLayoutData(data);

    final Label status = new Label(shell, SWT.NONE);
    data = new GridData(GridData.FILL_HORIZONTAL);
    data.horizontalSpan = 2;
    status.setLayoutData(data);

    final ProgressBar progressBar = new ProgressBar(shell, SWT.NONE);
    data = new GridData();
    data.horizontalAlignment = GridData.END;
    progressBar.setLayoutData(data);

    /* event handling */
    Listener listener =
        new Listener() {
          @Override
          public void handleEvent(Event event) {
            ToolItem item = (ToolItem) event.widget;
            String string = item.getText();
            if (string.equals("Back")) browser.back();
            else if (string.equals("Forward")) browser.forward();
            else if (string.equals("Stop")) browser.stop();
            else if (string.equals("Refresh")) browser.refresh();
            else if (string.equals("Go")) browser.setUrl(location.getText());
          }
        };
    browser.addProgressListener(
        new ProgressListener() {
          @Override
          public void changed(ProgressEvent event) {
            if (event.total == 0) return;
            int ratio = event.current * 100 / event.total;
            progressBar.setSelection(ratio);
          }

          @Override
          public void completed(ProgressEvent event) {
            progressBar.setSelection(0);
          }
        });
    browser.addStatusTextListener(
        new StatusTextListener() {
          @Override
          public void changed(StatusTextEvent event) {
            status.setText(event.text);
          }
        });
    browser.addLocationListener(
        new LocationListener() {
          @Override
          public void changed(LocationEvent event) {
            if (event.top) location.setText(event.location);
          }

          @Override
          public void changing(LocationEvent event) {}
        });
    itemBack.addListener(SWT.Selection, listener);
    itemForward.addListener(SWT.Selection, listener);
    itemStop.addListener(SWT.Selection, listener);
    itemRefresh.addListener(SWT.Selection, listener);
    itemGo.addListener(SWT.Selection, listener);
    location.addListener(
        SWT.DefaultSelection,
        new Listener() {
          @Override
          public void handleEvent(Event e) {
            browser.setUrl(location.getText());
          }
        });

    shell.open();
    browser.setUrl("http://eclipse.org");

    while (!shell.isDisposed()) {
      if (!display.readAndDispatch()) display.sleep();
    }
    display.dispose();
  }
  /**
   * Create contents of the dialog.
   *
   * @param parent
   */
  @Override
  protected Control createDialogArea(Composite parent) {
    setTitle("");
    parent.setToolTipText("hghkhj");
    Composite area = (Composite) super.createDialogArea(parent);
    Composite container = new Composite(area, SWT.NONE);
    container.setLayout(new GridLayout(1, false));
    container.setLayoutData(new GridData(GridData.FILL_BOTH));

    CTabFolder tabFolder = new CTabFolder(container, SWT.BORDER);
    tabFolder.setTabHeight(22);
    tabFolder.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    tabFolder.setSelectionBackground(
        Display.getCurrent().getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT));

    CTabItem tbtmNewItem = new CTabItem(tabFolder, SWT.NONE);
    tbtmNewItem.setText("Main");

    Composite composite = new Composite(tabFolder, SWT.NONE);
    tbtmNewItem.setControl(composite);
    composite.setLayout(new GridLayout(2, false));

    Label lblNewLabel = new Label(composite, SWT.NONE);
    lblNewLabel.setText("Id:");

    idText = new Text(composite, SWT.BORDER);

    idText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));

    Label lblNewLabel_1 = new Label(composite, SWT.NONE);
    lblNewLabel_1.setText("Source Ref:");

    sourceRefViewer = new ComboViewer(composite, SWT.READ_ONLY);
    Combo combo = sourceRefViewer.getCombo();
    combo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    sourceRefViewer.setContentProvider(new ArrayContentProvider());
    sourceRefViewer.setLabelProvider(new IDataLabelProvider());

    Label lblNewLabel_2 = new Label(composite, SWT.NONE);
    lblNewLabel_2.setText("Target Ref:");

    targetRefViewer = new ComboViewer(composite, SWT.READ_ONLY);
    Combo combo_1 = targetRefViewer.getCombo();
    combo_1.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    targetRefViewer.setContentProvider(new ArrayContentProvider());
    targetRefViewer.setLabelProvider(new IDataLabelProvider());

    Label lblNewLabel_3 = new Label(composite, SWT.NONE);
    lblNewLabel_3.setText("Transformation:");

    transformationText = new Text(composite, SWT.BORDER | SWT.WRAP | SWT.MULTI);
    transformationText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 2));

    CTabItem tbtmNewItem_1 = new CTabItem(tabFolder, SWT.NONE);
    tbtmNewItem_1.setText("Assignments");

    Composite composite_1 = new Composite(tabFolder, SWT.NONE);
    tbtmNewItem_1.setControl(composite_1);
    composite_1.setLayout(new GridLayout(1, true));

    ToolBar toolBar = new ToolBar(composite_1, SWT.FLAT | SWT.RIGHT);
    toolBar.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false, 1, 1));

    ToolItem addItem = new ToolItem(toolBar, SWT.NONE);
    addItem.addSelectionListener(
        new SelectionAdapter() {
          @SuppressWarnings("unchecked")
          @Override
          public void widgetSelected(SelectionEvent e) {
            Shell newshell = new Shell(getParentShell(), SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
            AssignmentDialog dialog = new AssignmentDialog(newshell);
            String determinedId =
                IdUtil.getNextParentedIdInList(
                    (List<BaseElement>) assignmentsViewer.getInput(), "A", idText.getText());
            dialog.setDeterminedId(determinedId);
            if (dialog.open() == Window.OK) {
              ((List<Assignment>) assignmentsViewer.getInput()).add(dialog.getResult());
              try {
                idHandler.addId(dialog.getResult());
              } catch (IdAlreadyExistException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
              }
              assignmentsViewer.refresh(true);
            }
          }
        });

    addItem.setText("New");

    final ToolItem editItem = new ToolItem(toolBar, SWT.NONE);
    editItem.addSelectionListener(
        new SelectionAdapter() {
          @SuppressWarnings("unchecked")
          @Override
          public void widgetSelected(SelectionEvent e) {
            AssignmentDialog dialog = new AssignmentDialog(getShell());
            String determinedId =
                IdUtil.getNextParentedIdInList(
                    (List<BaseElement>) assignmentsViewer.getInput(), "A", idText.getText());
            dialog.setDeterminedId(determinedId);
            IStructuredSelection selection =
                (IStructuredSelection) assignmentsViewer.getSelection();
            if (dialog.open((Assignment) selection.getFirstElement()) == Window.OK) {
              int index = assignmentsViewer.getTable().getSelectionIndex();
              try {
                idHandler.removeId((BaseElement) selection.getFirstElement());
              } catch (IdNotFoundException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
              }
              ((List<Assignment>) assignmentsViewer.getInput()).remove(selection.getFirstElement());

              ((List<Assignment>) assignmentsViewer.getInput()).add(index, dialog.getResult());
              try {
                idHandler.addId(dialog.getResult());
              } catch (IdAlreadyExistException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
              }
              assignmentsViewer.refresh(true);
              // ModelIdProcessor.refreshModelIds(EcoreUtil.getURI(getDiagram()));
            }
          }
        });
    editItem.setText("Edit");
    editItem.setEnabled(false);

    final ToolItem deleteItem = new ToolItem(toolBar, SWT.NONE);
    deleteItem.addSelectionListener(
        new SelectionAdapter() {
          @SuppressWarnings("unchecked")
          @Override
          public void widgetSelected(SelectionEvent e) {
            IStructuredSelection selection =
                (IStructuredSelection) assignmentsViewer.getSelection();
            try {
              idHandler.removeId((BaseElement) selection.getFirstElement());
            } catch (IdNotFoundException e1) {
              // TODO Auto-generated catch block
              e1.printStackTrace();
            }
            ((List<Assignment>) assignmentsViewer.getInput()).remove(selection.getFirstElement());
            assignmentsViewer.refresh(true);
            // ModelIdProcessor.refreshModelIds(EcoreUtil.getURI(getDiagram()));
          }
        });
    deleteItem.setText("Delete");
    deleteItem.setEnabled(false);

    final ToolItem upItem = new ToolItem(toolBar, SWT.NONE);
    upItem.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            IStructuredSelection selection =
                (IStructuredSelection) assignmentsViewer.getSelection();
            Assignment selected = (Assignment) selection.getFirstElement();
            List<Assignment> list = (List<Assignment>) assignmentsViewer.getInput();
            int index = list.indexOf(selected);
            list.remove(selected);
            list.add(index - 1, selected);
            assignmentsViewer.setSelection(new StructuredSelection(selected));
            assignmentsViewer.refresh(true);
          }
        });
    upItem.setEnabled(false);
    upItem.setText("Up");

    final ToolItem downItem = new ToolItem(toolBar, SWT.NONE);
    downItem.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            IStructuredSelection selection =
                (IStructuredSelection) assignmentsViewer.getSelection();
            Assignment selected = (Assignment) selection.getFirstElement();
            List<Assignment> list = (List<Assignment>) assignmentsViewer.getInput();
            int index = list.indexOf(selected);
            list.remove(selected);
            list.add(index + 1, selected);
            assignmentsViewer.setSelection(new StructuredSelection(selected));
            assignmentsViewer.refresh(true);
          }
        });
    downItem.setEnabled(false);
    downItem.setText("Down");

    Composite composite_2 = new Composite(composite_1, SWT.NONE);
    composite_2.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    // composite_2.setLayout(new GridLayout(1, false));

    assignmentsViewer = new TableViewer(composite_2, SWT.BORDER | SWT.FULL_SELECTION);
    assignmentsViewer.addSelectionChangedListener(
        new ISelectionChangedListener() {
          public void selectionChanged(SelectionChangedEvent event) {
            if (event.getSelection() == null) {
              editItem.setEnabled(false);
              deleteItem.setEnabled(false);
              upItem.setEnabled(false);
              downItem.setEnabled(false);
            } else {
              editItem.setEnabled(true);
              deleteItem.setEnabled(true);
              List<Assignment> list = (List<Assignment>) assignmentsViewer.getInput();
              Assignment selected =
                  (Assignment) (((StructuredSelection) event.getSelection()).getFirstElement());
              if (list.indexOf(selected) == 0) {
                upItem.setEnabled(false);
                downItem.setEnabled(true);
              } else if (list.indexOf(selected) == list.size() - 1) {
                upItem.setEnabled(true);
                downItem.setEnabled(false);
              } else {
                upItem.setEnabled(true);
                downItem.setEnabled(true);
              }
            }
          }
        });
    table = assignmentsViewer.getTable();
    table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 0, 1));
    table.setLinesVisible(true);
    table.setHeaderVisible(true);

    TableViewerColumn tableViewerColumn = new TableViewerColumn(assignmentsViewer, SWT.NONE);
    TableColumn tblclmnNewColumn = tableViewerColumn.getColumn();
    tblclmnNewColumn.setWidth(new Double(table.getSize().x * 0.2).intValue());
    tblclmnNewColumn.setResizable(true);
    tblclmnNewColumn.setText("Id");

    TableViewerColumn tableViewerColumn_1 = new TableViewerColumn(assignmentsViewer, SWT.NONE);
    TableColumn tblclmnNewColumn_1 = tableViewerColumn_1.getColumn();
    tblclmnNewColumn_1.setWidth(new Double(table.getSize().x * 0.4).intValue());
    tblclmnNewColumn_1.setResizable(true);
    tblclmnNewColumn_1.setText("From");

    TableViewerColumn tableViewerColumn_2 = new TableViewerColumn(assignmentsViewer, SWT.NONE);
    TableColumn tblclmnNewColumn_2 = tableViewerColumn_2.getColumn();
    tblclmnNewColumn_2.setResizable(true);
    tblclmnNewColumn_2.setWidth(new Double(table.getSize().x * 0.4).intValue());
    tblclmnNewColumn_2.setText("To");
    TableColumnLayout tableColumnLayout = new TableColumnLayout();

    tableColumnLayout.setColumnData(tblclmnNewColumn, new ColumnWeightData(20, 50, true));
    tableColumnLayout.setColumnData(tblclmnNewColumn_1, new ColumnWeightData(40, 50, true));
    tableColumnLayout.setColumnData(tblclmnNewColumn_2, new ColumnWeightData(40, 50, true));
    composite_2.setLayout(tableColumnLayout);

    assignmentsViewer.setContentProvider(new ArrayContentProvider());
    assignmentsViewer.setLabelProvider(new AssignmentLabelProvider());

    VariableSupport.decorateTextWithVariableSupport(transformationText);
    transformationText.setFont(FontUtil.INSTANCE.getExpressionFont());
    new Label(composite, SWT.NONE);
    init();
    return area;
  }
Ejemplo n.º 24
0
  public void createToolBar(final Composite parent, IAppWindow window) {
    GridLayout gridLayout;

    Composite container = new Composite(parent, SWT.NONE);
    gridLayout = new GridLayout(2, false);
    gridLayout.horizontalSpacing = 0;
    gridLayout.verticalSpacing = 0;
    gridLayout.marginWidth = 3;
    gridLayout.marginHeight = 1;
    container.setLayout(gridLayout);

    ToolBar toolBar = new ToolBar(container, SWT.FLAT | SWT.RIGHT);
    toolBar.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));

    IAppWindow.Type type = window.getType();
    if (type != IAppWindow.Type.ARENA) {
      ToolItem arenaWindowItem = new ToolItem(toolBar, SWT.PUSH);
      arenaWindowItem.setText("アリーナ");
      arenaWindowItem.setToolTipText("部屋の検索やロビーのチャット");
      arenaWindowItem.setImage(imageRegistry.get(ICON_TOOLBAR_ARENA));
      arenaWindowItem.addListener(
          SWT.Selection,
          new Listener() {
            @Override
            public void handleEvent(Event event) {
              arenaWindow.show();
            }
          });
    }
    if (type != IAppWindow.Type.ROOM) {
      ToolItem roomWindowItem = new ToolItem(toolBar, SWT.PUSH);
      roomWindowItem.setText("ルーム");
      roomWindowItem.setToolTipText("ルーム内で通信プレイができます");
      roomWindowItem.setImage(imageRegistry.get(ICON_TOOLBAR_ROOM));
      roomWindowItem.addListener(
          SWT.Selection,
          new Listener() {
            @Override
            public void handleEvent(Event event) {
              getRoomWindow().show();
            }
          });
    }

    ToolItem configWindowItem = new ToolItem(toolBar, SWT.PUSH);
    configWindowItem.setText("設定");
    configWindowItem.setToolTipText("アプリケーションの設定をします");
    configWindowItem.setImage(imageRegistry.get(ICON_TOOLBAR_CONFIG));
    configWindowItem.addListener(
        SWT.Selection,
        new Listener() {
          @Override
          public void handleEvent(Event event) {
            if (openConfigDialog(parent.getShell(), null)) {
              if (arenaWindow != null) arenaWindow.settingChanged();
              if (roomWindow != null) roomWindow.settingChanged();
            }
          }
        });

    ToolItem wikiItem = new ToolItem(toolBar, SWT.PUSH);
    wikiItem.setText("Wiki");
    wikiItem.setToolTipText(AppConstants.APP_NAME + "のWikiページを表示します");
    wikiItem.setImage(imageRegistry.get(ICON_TOOLBAR_WIKI));
    wikiItem.addListener(
        SWT.Selection,
        new Listener() {
          @Override
          public void handleEvent(Event event) {
            Program.launch("http://wiki.team-monketsu.net/");
          }
        });

    ToolItem exitItem = new ToolItem(toolBar, SWT.PUSH);
    exitItem.setText("終了");
    exitItem.setToolTipText(AppConstants.APP_NAME + "を終了します");
    exitItem.setImage(imageRegistry.get(ICON_TOOLBAR_EXIT));
    exitItem.addListener(
        SWT.Selection,
        new Listener() {
          @Override
          public void handleEvent(Event event) {
            if (openShutdownConfirmDialog(parent.getShell())) {
              isRunning = false;
            }
          }
        });

    Composite appVersionContainer = new Composite(container, SWT.NONE);
    appVersionContainer.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, true, false));
    RowLayout rowLayout = new RowLayout();
    rowLayout.center = true;
    rowLayout.marginTop = 0;
    rowLayout.marginBottom = 0;
    rowLayout.marginLeft = 0;
    rowLayout.marginRight = 0;
    appVersionContainer.setLayout(rowLayout);

    Label statusApplicationVersionLabel = new Label(appVersionContainer, SWT.NONE);
    statusApplicationVersionLabel.setText("バージョン:");
    initControl(statusApplicationVersionLabel);

    Label statusApplicationVersionNumber = new Label(appVersionContainer, SWT.NONE);
    statusApplicationVersionNumber.setText(AppConstants.VERSION);
    statusApplicationVersionNumber.setForeground(colorRegistry.get(COLOR_APP_NUMBER));
    initControl(statusApplicationVersionNumber);

    Label statusApplicationProtocolLabel = new Label(appVersionContainer, SWT.NONE);
    statusApplicationProtocolLabel.setText("プロトコル:");
    initControl(statusApplicationProtocolLabel);

    Label statusApplicationProtocolNumber = new Label(appVersionContainer, SWT.NONE);
    statusApplicationProtocolNumber.setText(IProtocol.NUMBER);
    statusApplicationProtocolNumber.setForeground(colorRegistry.get(COLOR_APP_NUMBER));
    initControl(statusApplicationProtocolNumber);

    Label statusApplicationSsidLabel = new Label(appVersionContainer, SWT.NONE);
    statusApplicationSsidLabel.setText("SSID機能:");
    initControl(statusApplicationSsidLabel);

    Label statusApplicationSsidLibrary = new Label(appVersionContainer, SWT.NONE);
    toolbarSsidLibraryLabels.add(statusApplicationSsidLibrary);
    initControl(statusApplicationSsidLibrary);

    updateWlanLibraryStatus();
  }
  /*
   * (non-Javadoc)
   *
   * @see org.eclipse.jface.action.ContributionItem#update(java.lang.String)
   */
  public void update(String id) {
    if (widget != null) {
      if (widget instanceof MenuItem) {
        MenuItem item = (MenuItem) widget;

        String text = label;
        if (text == null) {
          if (command != null) {
            try {
              text = command.getCommand().getName();
            } catch (NotDefinedException e) {
              WorkbenchPlugin.log(
                  "Update item failed " //$NON-NLS-1$
                      + getId(),
                  e);
            }
          }
        }
        // TODO: [bm] key bindings
        //				text = updateMnemonic(text);
        //
        //				String keyBindingText = null;
        //				if (command != null) {
        //					TriggerSequence[] bindings = bindingService
        //							.getActiveBindingsFor(command);
        //					if (bindings.length > 0) {
        //						keyBindingText = bindings[0].format();
        //					}
        //				}
        //				if (text != null) {
        //					if (keyBindingText == null) {
        item.setText(text);
        //					} else {
        //						item.setText(text + '\t' + keyBindingText);
        //					}
        //				}

        updateIcons();
        if (item.getSelection() != checkedState) {
          item.setSelection(checkedState);
        }

        boolean shouldBeEnabled = isEnabled();
        if (item.getEnabled() != shouldBeEnabled) {
          item.setEnabled(shouldBeEnabled);
        }
      } else if (widget instanceof ToolItem) {
        ToolItem item = (ToolItem) widget;

        if (icon != null) {
          updateIcons();
        } else if (label != null) {
          item.setText(label);
        }

        if (tooltip != null) item.setToolTipText(tooltip);
        else {
          String text = label;
          if (text == null) {
            if (command != null) {
              try {
                text = command.getCommand().getName();
              } catch (NotDefinedException e) {
                WorkbenchPlugin.log(
                    "Update item failed " //$NON-NLS-1$
                        + getId(),
                    e);
              }
            }
          }
          if (text != null) {
            item.setToolTipText(text);
          }
        }

        if (item.getSelection() != checkedState) {
          item.setSelection(checkedState);
        }

        boolean shouldBeEnabled = isEnabled();
        if (item.getEnabled() != shouldBeEnabled) {
          item.setEnabled(shouldBeEnabled);
        }
      }
    }
  }