예제 #1
0
  /** {@inheritDoc} */
  @Override
  public void sceneSelectionModeChanged(final SceneSelectionModeEvent event) {
    final SelectionMode selectionMode = event.getSelectionMode();

    objectSelection.setSelection(selectionMode == SelectionMode.OBJECT);
    faceSelection.setSelection(selectionMode == SelectionMode.FACE);
    edgeSelection.setSelection(selectionMode == SelectionMode.EDGE);
    vertexSelection.setSelection(selectionMode == SelectionMode.VERTEX);
  }
예제 #2
0
 public void setProjection(final ProjectionMode projection) {
   switch (projection) {
     case ORTHOGRAPHIC:
       _projectionToggle.setSelection(false);
       _setOrthographicProjection.run();
       break;
     case PERSPECTIVE:
       _projectionToggle.setSelection(true);
       _setPerspectiveProjection.run();
       break;
   }
 }
예제 #3
0
  private void createToolBar(Composite parent) {
    ToolBar toolBar = new ToolBar(parent, SWT.FLAT);
    modeButton = new ToolItem(toolBar, SWT.CHECK);
    modeButton.setImage(HierarchyView.INHERITED_IMAGE);
    modeButton.setToolTipText("Show Inherited Members");
    modeButton.addSelectionListener(
        new SelectionListener() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            mode = !mode;
            getTreeViewer().refresh();
            getTreeViewer().expandToLevel(getDefaultLevel());
          }

          @Override
          public void widgetDefaultSelected(SelectionEvent e) {}
        });
    sortButton = new ToolItem(toolBar, SWT.CHECK);
    sortButton.setImage(SORT);
    sortButton.setToolTipText("Sort by Name");
    boolean sortChecker = getDialogSettings().getBoolean("sort");
    sortButton.setSelection(sortChecker);
    sortButton.addSelectionListener(
        new SelectionListener() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            lexicalSortingAction.setChecked(sortButton.getSelection());
            lexicalSortingAction.run();
          }

          @Override
          public void widgetDefaultSelected(SelectionEvent e) {}
        });
    hideButton = new ToolItem(toolBar, SWT.CHECK);
    hideButton.setImage(PUBLIC);
    hideButton.setToolTipText("Hide Unshared Declarations");
    boolean hideChecked = getDialogSettings().getBoolean("hideNonShared");
    hideButton.setSelection(hideChecked);
    hideButton.addSelectionListener(
        new SelectionListener() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            hideNonSharedAction.setChecked(hideButton.getSelection());
            hideNonSharedAction.run();
          }

          @Override
          public void widgetDefaultSelected(SelectionEvent e) {}
        });
  }
예제 #4
0
  @Override
  public void update(final ModelEvent event) {

    // Enable/Disable sort button
    if (event.part == ModelPart.OUTPUT
        || event.part == ModelPart.INPUT
        || event.part == ModelPart.SELECTED_VIEW_CONFIG) {

      if (model != null && model.getOutput() != null) {
        groupsButton.setEnabled(true);
        subsetButton.setEnabled(true);
      } else {
        groupsButton.setEnabled(false);
        subsetButton.setEnabled(false);
      }
    }

    // Update model
    if (event.part == ModelPart.MODEL) {
      model = (Model) event.data;
      reset();
    }

    if (event.part == ModelPart.SELECTED_VIEW_CONFIG) {
      subsetButton.setSelection(model.getViewConfig().isSubset());
    }

    if (event.part == ModelPart.SELECTED_ATTRIBUTE) {
      table.setSelectedAttribute((String) event.data);
    }
  }
예제 #5
0
 long /*int*/ menuItemSelected(long /*int*/ widget, ToolItem item) {
   Event event = new Event();
   switch (item.style) {
     case SWT.DROP_DOWN:
       /*
        * Feature in GTK. The DROP_DOWN item does not
        * contain arrow button in the overflow menu. So, it
        * is impossible to select the menu of that item.
        * The fix is to consider the item selection
        * as Arrow click, in order to popup the drop-down.
        */
       event.detail = SWT.ARROW;
       GtkAllocation allocation = new GtkAllocation();
       OS.gtk_widget_get_allocation(widget, allocation);
       event.x = allocation.x;
       if ((style & SWT.MIRRORED) != 0) event.x = getClientWidth() - allocation.width - event.x;
       event.y = allocation.y + allocation.height;
       break;
     case SWT.RADIO:
       if ((style & SWT.NO_RADIO_GROUP) == 0) item.selectRadio();
       break;
     case SWT.CHECK:
       boolean currentSelection = item.getSelection();
       item.setSelection(!currentSelection);
   }
   item.sendSelectionEvent(SWT.Selection, event, false);
   return 0;
 }
예제 #6
0
  private void updateToolBar() {
    if (toolbar != null) {
      ResourceManager parentResourceManager = JFaceResources.getResources();
      LocalResourceManager localManager = new LocalResourceManager(parentResourceManager);

      for (int i = 0; i < toolbar.getItemCount(); i++) {
        ToolItem item = toolbar.getItem(i);
        IAction action = (IAction) actionMap.get(item);
        if (action != null) {
          ImageDescriptor image = null;
          if (action.isEnabled() && action.getImageDescriptor() != null)
            image = action.getImageDescriptor();
          else if (action.isEnabled() && action.getImageDescriptor() != null)
            image = action.getDisabledImageDescriptor();
          if (image != null) item.setImage(localManager.createImageWithDefault(image));

          item.setToolTipText(action.getToolTipText());
          if (IAction.AS_CHECK_BOX == action.getStyle()) {
            item.setSelection(action.isChecked());
          }
        }
      }

      disposeOldImages();
      imageManager = localManager;

      if (toolbar.isFocusControl()) toolbar.setFocus();
    }
  }
  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 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);
    }
  }
  private void addRadio(RuleAction.Choices choices) {
    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$

    assert icons != null;
    assert icons.size() == titles.size();

    for (int i = 0; i < icons.size(); i++) {
      URL iconUrl = icons.get(i);
      String title = titles.get(i);
      final String id = ids.get(i);
      final ToolItem item = new ToolItem(mLayoutToolBar, SWT.RADIO);
      item.setToolTipText(title);
      item.setImage(IconFactory.getInstance().getIcon(iconUrl));
      item.setData(choices);
      item.setData(ATTR_ID, id);
      item.addSelectionListener(
          new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e) {
              if (item.getSelection()) {
                RuleAction.Choices choices = (Choices) item.getData();
                choices.getCallback().action(choices, getSelectedNodes(), id, null);
                updateSelection();
              }
            }
          });
      boolean selected = current.equals(id);
      if (selected) {
        item.setSelection(true);
      }
    }
  }
예제 #10
0
 boolean setRadioSelection(boolean value) {
   if ((style & SWT.RADIO) == 0) return false;
   if (getSelection() != value) {
     setSelection(value);
     postEvent(SWT.Selection);
   }
   return true;
 }
예제 #11
0
 public void setShowPickLocation(final boolean showPickLoc) {
   _showPickLocToggle.setSelection(showPickLoc);
   if (showPickLoc) {
     _showPickLoc.run();
   } else {
     _hidePickLoc.run();
   }
 }
 private void selectPerspective(String id) {
   for (ToolItem item : bar.getItems()) item.setSelection(((String) item.getData()).equals(id));
   try {
     PlatformUI.getWorkbench()
         .showPerspective(id, PlatformUI.getWorkbench().getActiveWorkbenchWindow());
     DataOverviewView.reset();
   } catch (WorkbenchException e) {
     if (Log.error(this)) Log.error(this, "Unable to change perspective", e);
   }
 }
예제 #13
0
 void selectRadio() {
   int index = 0;
   ToolItem[] items = parent.getItems();
   while (index < items.length && items[index] != this) index++;
   int i = index - 1;
   while (i >= 0 && items[i].setRadioSelection(false)) --i;
   int j = index + 1;
   while (j < items.length && items[j].setRadioSelection(false)) j++;
   setSelection(true);
 }
 private void setChecked(boolean checked) {
   if (checkedState == checked) {
     return;
   }
   checkedState = checked;
   if (widget instanceof MenuItem) {
     ((MenuItem) widget).setSelection(checkedState);
   } else if (widget instanceof ToolItem) {
     ((ToolItem) widget).setSelection(checkedState);
   }
 }
예제 #15
0
 /** Creates the toolbar. Note: Only called by standalone. */
 private void createToolBar(Composite parent) {
   ToolBar toolbar = new ToolBar(parent, SWT.NONE);
   String group = null;
   for (int i = 0; i < PaintExample.tools.length; i++) {
     Tool tool = PaintExample.tools[i];
     if (group != null && !tool.group.equals(group)) new ToolItem(toolbar, SWT.SEPARATOR);
     group = tool.group;
     ToolItem item = addToolItem(toolbar, tool);
     if (i == PaintExample.Default_tool
         || i == PaintExample.Default_fill
         || i == PaintExample.Default_linestyle) item.setSelection(true);
   }
 }
예제 #16
0
 private void createToolBar(org.eclipse.swt.widgets.Composite parent) {
   org.eclipse.swt.widgets.ToolBar toolbar = new org.eclipse.swt.widgets.ToolBar(parent, SWT.NONE);
   java.lang.String group = null;
   for (int i = 0; i < tools.length; i++) {
     org.eclipse.swt.examples.paint.Tool tool = tools[i];
     if (group != null && !tool.group.equals(group)) {
       new org.eclipse.swt.widgets.ToolItem(toolbar, SWT.SEPARATOR);
     }
     group = tool.group;
     org.eclipse.swt.widgets.ToolItem item = addToolItem(toolbar, tool);
     if (i == Default_tool || i == Default_fill || i == Default_linestyle) {
       item.setSelection(true);
     }
   }
 }
예제 #17
0
  /** {@inheritDoc} */
  @Override
  public void createPartControl(final Composite parent) {
    toolBar = new ToolBar(parent, SWT.NONE);

    objectSelection = new ToolItem(toolBar, SWT.RADIO | SWT.NONE);
    objectSelection.setImage(MoreDreadUI.getDefault().getImage("/icons/SelectionModeObject.png"));
    objectSelection.setSelection(true);
    objectSelection.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(final SelectionEvent e) {
            MoreDreadUI.getDefault().getSceneHolder().setSelectionMode(SelectionMode.OBJECT);
          }
        });
    faceSelection = new ToolItem(toolBar, SWT.RADIO | SWT.NONE);
    faceSelection.setImage(MoreDreadUI.getDefault().getImage("/icons/SelectionModeFace.png"));
    faceSelection.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(final SelectionEvent e) {
            MoreDreadUI.getDefault().getSceneHolder().setSelectionMode(SelectionMode.FACE);
          }
        });
    faceSelection.setEnabled(false);
    edgeSelection = new ToolItem(toolBar, SWT.RADIO | SWT.NONE);
    edgeSelection.setImage(MoreDreadUI.getDefault().getImage("/icons/SelectionModeEdge.png"));
    edgeSelection.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(final SelectionEvent e) {
            MoreDreadUI.getDefault().getSceneHolder().setSelectionMode(SelectionMode.EDGE);
          }
        });
    edgeSelection.setEnabled(false);
    vertexSelection = new ToolItem(toolBar, SWT.RADIO | SWT.NONE);
    vertexSelection.setImage(MoreDreadUI.getDefault().getImage("/icons/SelectionModeVertex.png"));
    vertexSelection.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(final SelectionEvent e) {
            MoreDreadUI.getDefault().getSceneHolder().setSelectionMode(SelectionMode.VERTEX);
          }
        });
    vertexSelection.setEnabled(false);
    MoreDreadUI.getDefault().getSceneHolder().addSceneSelectionModeListener(this);
    MoreDreadUI.getDefault().getSceneHolder().addSceneSelectionChangeListener(this);
  }
예제 #18
0
 void click(boolean dropDown, int state) {
   if ((style & SWT.RADIO) != 0) {
     selectRadio();
   } else {
     if ((style & SWT.CHECK) != 0) setSelection(!set);
   }
   Event event = new Event();
   if ((style & SWT.DROP_DOWN) != 0) {
     if (dropDown) {
       event.detail = SWT.ARROW;
       int[] argList = {OS.XmNx, 0, OS.XmNy, 0, OS.XmNheight, 0};
       OS.XtGetValues(handle, argList, argList.length / 2);
       event.x = (short) argList[1];
       event.y = (short) argList[3] + (short) argList[5];
     }
   }
   if (state != 0) setInputState(event, state);
   postEvent(SWT.Selection, event);
 }
        public void handleEvent(Event event) {
          if (psTB.isDisposed()) {
            return;
          }

          MUIElement changedElement = (MUIElement) event.getProperty(UIEvents.EventTags.ELEMENT);

          if (psME == null || !(changedElement instanceof MPerspectiveStack)) return;

          MWindow perspWin = modelService.getTopLevelWindowFor(changedElement);
          MWindow switcherWin = modelService.getTopLevelWindowFor(psME);
          if (perspWin != switcherWin) return;

          MPerspectiveStack perspStack = (MPerspectiveStack) changedElement;
          if (!perspStack.isToBeRendered()) return;

          MPerspective selElement = perspStack.getSelectedElement();
          for (ToolItem ti : psTB.getItems()) {
            ti.setSelection(ti.getData() == selElement);
          }
        }
 @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;
 }
예제 #21
0
 private ToolBar createLayoutToolBar(Composite parent) {
   ToolBar tb = new ToolBar(parent, SWT.NONE);
   ToolItem tabbed = new ToolItem(tb, SWT.RADIO);
   tabbed.setImage(imageCache.get(TABBED_ICON));
   tabbed.setToolTipText("Tabbed Request/Response layout");
   tabbed.setSelection(true);
   tabbed.addSelectionListener(
       new SelectionAdapter() {
         @Override
         public void widgetSelected(SelectionEvent e) {
           setTabbedMode();
         }
       });
   ToolItem horiz = new ToolItem(tb, SWT.RADIO);
   horiz.setImage(imageCache.get(HORIZONTAL_ICON));
   horiz.setToolTipText("Horizontal Request/Response layout");
   horiz.addSelectionListener(
       new SelectionAdapter() {
         @Override
         public void widgetSelected(SelectionEvent e) {
           setHorizontalSashMode();
         }
       });
   ToolItem vert = new ToolItem(tb, SWT.RADIO);
   vert.setImage(imageCache.get(VERTICAL_ICON));
   vert.setToolTipText("Vertical Request/Response layout");
   vert.addSelectionListener(
       new SelectionAdapter() {
         @Override
         public void widgetSelected(SelectionEvent e) {
           setVerticalSashMode();
         }
       });
   tb.pack();
   return tb;
 }
예제 #22
0
  private Section createFileSection(Composite container) {
    Section filesSection =
        toolkit.createSection(
            container, ExpandableComposite.TITLE_BAR | ExpandableComposite.CLIENT_INDENT);
    GridDataFactory.fillDefaults().grab(true, true).applyTo(filesSection);
    Composite filesArea = toolkit.createComposite(filesSection);
    filesSection.setClient(filesArea);
    toolkit.paintBordersFor(filesArea);
    GridLayoutFactory.fillDefaults().extendedMargins(2, 2, 2, 2).applyTo(filesArea);

    ToolBar filesToolbar = new ToolBar(filesSection, SWT.FLAT);

    filesSection.setTextClient(filesToolbar);

    PatternFilter patternFilter =
        new PatternFilter() {
          @Override
          protected boolean isLeafMatch(Viewer viewer, Object element) {
            if (element instanceof CommitItem) {
              CommitItem commitItem = (CommitItem) element;
              return wordMatches(commitItem.path);
            }
            return super.isLeafMatch(viewer, element);
          }
        };
    patternFilter.setIncludeLeadingWildcard(true);
    FilteredCheckboxTree resourcesTreeComposite =
        new FilteredCheckboxTree(filesArea, toolkit, SWT.FULL_SELECTION, patternFilter) {
          @Override
          protected WorkbenchJob doCreateRefreshJob() {
            // workaround for file filter not having an explicit change
            // listener
            WorkbenchJob filterJob = super.doCreateRefreshJob();
            filterJob.addJobChangeListener(
                new JobChangeAdapter() {
                  public void done(IJobChangeEvent event) {
                    if (event.getResult().isOK()) {
                      getDisplay()
                          .asyncExec(
                              new Runnable() {
                                public void run() {
                                  updateFileSectionText();
                                }
                              });
                    }
                  }
                });
            return filterJob;
          }
        };
    Tree resourcesTree = resourcesTreeComposite.getViewer().getTree();
    resourcesTree.setData(FormToolkit.KEY_DRAW_BORDER, FormToolkit.TREE_BORDER);
    resourcesTreeComposite.setLayoutData(
        GridDataFactory.fillDefaults().hint(600, 200).grab(true, true).create());

    resourcesTree.addSelectionListener(new CommitItemSelectionListener());

    resourcesTree.setHeaderVisible(true);
    TreeColumn statCol = new TreeColumn(resourcesTree, SWT.LEFT);
    statCol.setText(UIText.CommitDialog_Status);
    statCol.setWidth(150);
    statCol.addSelectionListener(new HeaderSelectionListener(CommitItem.Order.ByStatus));

    TreeColumn resourceCol = new TreeColumn(resourcesTree, SWT.LEFT);
    resourceCol.setText(UIText.CommitDialog_Path);
    resourceCol.setWidth(415);
    resourceCol.addSelectionListener(new HeaderSelectionListener(CommitItem.Order.ByFile));

    filesViewer = resourcesTreeComposite.getCheckboxTreeViewer();
    new TreeViewerColumn(filesViewer, statCol).setLabelProvider(createStatusLabelProvider());
    new TreeViewerColumn(filesViewer, resourceCol).setLabelProvider(new CommitPathLabelProvider());
    ColumnViewerToolTipSupport.enableFor(filesViewer);
    filesViewer.setContentProvider(new CommitFileContentProvider());
    filesViewer.setUseHashlookup(true);
    IDialogSettings settings = org.eclipse.egit.ui.Activator.getDefault().getDialogSettings();
    if (settings.get(SHOW_UNTRACKED_PREF) != null) {
      // note, no matter how the dialog settings are, if
      // the preferences force us to include untracked files
      // we must show them
      showUntracked =
          Boolean.valueOf(settings.get(SHOW_UNTRACKED_PREF)).booleanValue()
              || getPreferenceStore().getBoolean(UIPreferences.COMMIT_DIALOG_INCLUDE_UNTRACKED);
    }

    filesViewer.addFilter(new CommitItemFilter());
    filesViewer.setInput(items.toArray());
    MenuManager menuManager = new MenuManager();
    menuManager.setRemoveAllWhenShown(true);
    menuManager.addMenuListener(createContextMenuListener());
    filesViewer.getTree().setMenu(menuManager.createContextMenu(filesViewer.getTree()));
    filesViewer.addCheckStateListener(
        new ICheckStateListener() {

          public void checkStateChanged(CheckStateChangedEvent event) {
            updateFileSectionText();
          }
        });

    showUntrackedItem = new ToolItem(filesToolbar, SWT.CHECK);
    Image showUntrackedImage = UIIcons.UNTRACKED_FILE.createImage();
    UIUtils.hookDisposal(showUntrackedItem, showUntrackedImage);
    showUntrackedItem.setImage(showUntrackedImage);
    showUntrackedItem.setToolTipText(UIText.CommitDialog_ShowUntrackedFiles);
    showUntrackedItem.setSelection(showUntracked);
    showUntrackedItem.addSelectionListener(
        new SelectionAdapter() {

          public void widgetSelected(SelectionEvent e) {
            showUntracked = showUntrackedItem.getSelection();
            filesViewer.refresh(true);
            updateFileSectionText();
            updateMessage();
          }
        });

    ToolItem checkAllItem = new ToolItem(filesToolbar, SWT.PUSH);
    Image checkImage = UIIcons.CHECK_ALL.createImage();
    UIUtils.hookDisposal(checkAllItem, checkImage);
    checkAllItem.setImage(checkImage);
    checkAllItem.setToolTipText(UIText.CommitDialog_SelectAll);
    checkAllItem.addSelectionListener(
        new SelectionAdapter() {

          public void widgetSelected(SelectionEvent e) {
            filesViewer.setAllChecked(true);
            updateFileSectionText();
            updateMessage();
          }
        });

    ToolItem uncheckAllItem = new ToolItem(filesToolbar, SWT.PUSH);
    Image uncheckImage = UIIcons.UNCHECK_ALL.createImage();
    UIUtils.hookDisposal(uncheckAllItem, uncheckImage);
    uncheckAllItem.setImage(uncheckImage);
    uncheckAllItem.setToolTipText(UIText.CommitDialog_DeselectAll);
    uncheckAllItem.addSelectionListener(
        new SelectionAdapter() {

          public void widgetSelected(SelectionEvent e) {
            filesViewer.setAllChecked(false);
            updateFileSectionText();
            updateMessage();
          }
        });

    if (!allowToChangeSelection) {
      amendingItem.setSelection(false);
      amendingItem.setEnabled(false);
      showUntrackedItem.setSelection(false);
      showUntrackedItem.setEnabled(false);
      checkAllItem.setEnabled(false);
      uncheckAllItem.setEnabled(false);

      filesViewer.addCheckStateListener(
          new ICheckStateListener() {

            public void checkStateChanged(CheckStateChangedEvent event) {
              if (!event.getChecked()) filesViewer.setAllChecked(true);
              updateFileSectionText();
            }
          });
      filesViewer.setAllChecked(true);
    } else {
      final boolean includeUntracked =
          getPreferenceStore().getBoolean(UIPreferences.COMMIT_DIALOG_INCLUDE_UNTRACKED);
      for (CommitItem item : items) {
        if (!preselectAll && !preselectedFiles.contains(item.path)) continue;
        if (item.status == Status.ASSUME_UNCHANGED) continue;
        if (!includeUntracked && item.status == Status.UNTRACKED) continue;
        filesViewer.setChecked(item, true);
      }
    }
    statCol.pack();
    resourceCol.pack();
    return filesSection;
  }
  /*
   * (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);
        }
      }
    }
  }
  /**
   * Attempts to update the existing toolbar actions, if the action list is similar to the current
   * list. Returns false if this cannot be done and the contents must be replaced.
   */
  private boolean updateActions(@NonNull List<RuleAction> actions) {
    List<RuleAction> before = mPrevActions;
    List<RuleAction> after = actions;

    if (before == null) {
      return false;
    }

    if (!before.equals(after) || after.size() > mLayoutToolBar.getItemCount()) {
      return false;
    }

    int actionIndex = 0;
    for (int i = 0, max = mLayoutToolBar.getItemCount(); i < max; i++) {
      ToolItem item = mLayoutToolBar.getItem(i);
      int style = item.getStyle();
      Object data = item.getData();
      if (data != null) {
        // One action can result in multiple toolbar items (e.g. a choice action
        // can result in multiple radio buttons), so we've have to replace all of
        // them with the corresponding new action
        RuleAction prevAction = before.get(actionIndex);
        while (prevAction != data) {
          actionIndex++;
          if (actionIndex == before.size()) {
            return false;
          }
          prevAction = before.get(actionIndex);
          if (prevAction == data) {
            break;
          } else if (!(prevAction instanceof RuleAction.Separator)) {
            return false;
          }
        }
        RuleAction newAction = after.get(actionIndex);
        assert newAction.equals(prevAction); // Maybe I can do this lazily instead?

        // Update action binding to the new action
        item.setData(newAction);

        // Sync button states: the checked state is not considered part of
        // RuleAction equality
        if ((style & SWT.CHECK) != 0) {
          assert newAction instanceof Toggle;
          Toggle toggle = (Toggle) newAction;
          item.setSelection(toggle.isChecked());
        } else if ((style & SWT.RADIO) != 0) {
          assert newAction instanceof Choices;
          Choices choices = (Choices) newAction;
          String current = choices.getCurrent();
          String id = (String) item.getData(ATTR_ID);
          boolean selected = Strings.nullToEmpty(current).equals(id);
          item.setSelection(selected);
        }
      } else {
        // Must be a separator, or a label (which we insert for nested widgets)
        assert (style & SWT.SEPARATOR) != 0 || !item.getText().isEmpty() : item;
      }
    }

    return true;
  }
예제 #25
0
 public void menuHidden(final MenuEvent e) {
   if (e.getSource() == menu && !toolItem.isDisposed()) {
     toolItem.setSelection(false);
   }
 }
  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;
  }
  protected void showContent(String type) {
    IExpressionProvider provider =
        ExpressionEditorService.getInstance().getExpressionProvider(type);

    Assert.isNotNull(provider);

    for (Control c : contentComposite.getChildren()) {
      c.dispose();
    }

    if (currentExpressionEditor != null) {
      currentExpressionEditor.dispose();
    }

    currentExpressionEditor = provider.getExpressionEditor(inputExpression, context);
    currentExpressionEditor.setIsPageFlowContext(isPageFlowContext);
    if (currentExpressionEditor != null) {
      currentExpressionEditor.createExpressionEditor(contentComposite, isPassword);
      contentComposite.layout(true, true);
      if (helpControl != null) {
        //				helpControl.setVisible(currentExpressionEditor.provideDialogTray());
        helpControl.setVisible(false);
        if (currentExpressionEditor.provideDialogTray()) {
          ToolItem item = ((ToolBar) helpControl).getItem(0);
          item.setSelection(true);
          openTrayListener.handleEvent(new Event());
        } else if (getTray() != null) {
          closeTray();
        }
      }
      if (dataBindingContext != null) {
        dataBindingContext.dispose();
      }
      dataBindingContext = new EMFDataBindingContext();

      UpdateValueStrategy selectionToExpressionType = new UpdateValueStrategy();
      IConverter convert =
          new Converter(IExpressionProvider.class, String.class) {

            @Override
            public Object convert(Object arg0) {
              return ((IExpressionProvider) arg0).getExpressionType();
            }
          };
      selectionToExpressionType.setConverter(convert);

      if (domain != null) {
        domain
            .getCommandStack()
            .execute(
                SetCommand.create(
                    domain, inputExpression, ExpressionPackage.Literals.EXPRESSION__TYPE, type));
      } else {
        inputExpression.setType(type);
      }
      currentExpressionEditor.bindExpression(
          dataBindingContext, context, inputExpression, viewerTypeFilters, expressionViewer);
      currentExpressionEditor.addListener(
          new Listener() {
            @Override
            public void handleEvent(Event event) {
              Button okButton = getButton(OK);
              if (okButton != null && !okButton.isDisposed()) {
                okButton.setEnabled(currentExpressionEditor.canFinish());
              }
            }
          });
      DialogSupport.create(this, dataBindingContext);
    }
  }
예제 #28
0
  private Composite createMessageAndPersonArea(Composite container) {

    Composite messageAndPersonArea = toolkit.createComposite(container);
    GridDataFactory.fillDefaults().grab(true, true).applyTo(messageAndPersonArea);
    GridLayoutFactory.swtDefaults().margins(0, 0).spacing(0, 0).applyTo(messageAndPersonArea);

    Section messageSection =
        toolkit.createSection(
            messageAndPersonArea,
            ExpandableComposite.TITLE_BAR | ExpandableComposite.CLIENT_INDENT);
    messageSection.setText(UIText.CommitDialog_CommitMessage);
    Composite messageArea = toolkit.createComposite(messageSection);
    GridLayoutFactory.fillDefaults().spacing(0, 0).extendedMargins(2, 2, 2, 2).applyTo(messageArea);
    toolkit.paintBordersFor(messageArea);
    GridDataFactory.fillDefaults().grab(true, true).applyTo(messageSection);
    GridLayoutFactory.swtDefaults().applyTo(messageSection);

    Composite headerArea = new Composite(messageSection, SWT.NONE);
    GridLayoutFactory.fillDefaults().spacing(0, 0).numColumns(2).applyTo(headerArea);

    ToolBar messageToolbar = new ToolBar(headerArea, SWT.FLAT | SWT.HORIZONTAL);
    GridDataFactory.fillDefaults()
        .align(SWT.END, SWT.FILL)
        .grab(true, false)
        .applyTo(messageToolbar);

    addMessageDropDown(headerArea);

    messageSection.setTextClient(headerArea);

    final CommitProposalProcessor commitProposalProcessor =
        new CommitProposalProcessor() {
          @Override
          protected Collection<String> computeFileNameProposals() {
            return getFileList();
          }

          @Override
          protected Collection<String> computeMessageProposals() {
            return CommitMessageHistory.getCommitHistory();
          }
        };
    commitText =
        new CommitMessageArea(messageArea, commitMessage, SWT.NONE) {
          @Override
          protected CommitProposalProcessor getCommitProposalProcessor() {
            return commitProposalProcessor;
          }
        };
    commitText.setData(FormToolkit.KEY_DRAW_BORDER, FormToolkit.TEXT_BORDER);
    messageSection.setClient(messageArea);
    Point size = commitText.getTextWidget().getSize();
    int minHeight = commitText.getTextWidget().getLineHeight() * 3;
    commitText.setLayoutData(
        GridDataFactory.fillDefaults()
            .grab(true, true)
            .hint(size)
            .minSize(size.x, minHeight)
            .align(SWT.FILL, SWT.FILL)
            .create());

    UIUtils.addBulbDecorator(commitText.getTextWidget(), UIText.CommitDialog_ContentAssist);

    Composite personArea = toolkit.createComposite(messageAndPersonArea);
    toolkit.paintBordersFor(personArea);
    GridLayoutFactory.swtDefaults().numColumns(2).applyTo(personArea);
    GridDataFactory.fillDefaults().grab(true, false).applyTo(personArea);

    toolkit
        .createLabel(personArea, UIText.CommitDialog_Author)
        .setForeground(toolkit.getColors().getColor(IFormColors.TB_TOGGLE));
    authorText = toolkit.createText(personArea, null);
    authorText.setData(FormToolkit.KEY_DRAW_BORDER, FormToolkit.TEXT_BORDER);
    authorText.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());
    if (repository != null
        && repository.getRepositoryState().equals(RepositoryState.CHERRY_PICKING_RESOLVED))
      authorText.setEnabled(false);

    toolkit
        .createLabel(personArea, UIText.CommitDialog_Committer)
        .setForeground(toolkit.getColors().getColor(IFormColors.TB_TOGGLE));
    committerText = toolkit.createText(personArea, null);
    committerText.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());
    if (committer != null) committerText.setText(committer);

    amendingItem = new ToolItem(messageToolbar, SWT.CHECK);
    amendingItem.setSelection(amending);
    if (amending) amendingItem.setEnabled(false); // if already set, don't allow any
    // changes
    else if (!amendAllowed) amendingItem.setEnabled(false);
    amendingItem.setToolTipText(UIText.CommitDialog_AmendPreviousCommit);
    Image amendImage = UIIcons.AMEND_COMMIT.createImage();
    UIUtils.hookDisposal(amendingItem, amendImage);
    amendingItem.setImage(amendImage);

    signedOffItem = new ToolItem(messageToolbar, SWT.CHECK);

    signedOffItem.setToolTipText(UIText.CommitDialog_AddSOB);
    Image signedOffImage = UIIcons.SIGNED_OFF.createImage();
    UIUtils.hookDisposal(signedOffItem, signedOffImage);
    signedOffItem.setImage(signedOffImage);

    changeIdItem = new ToolItem(messageToolbar, SWT.CHECK);
    Image changeIdImage = UIIcons.GERRIT.createImage();
    UIUtils.hookDisposal(changeIdItem, changeIdImage);
    changeIdItem.setImage(changeIdImage);
    changeIdItem.setToolTipText(UIText.CommitDialog_AddChangeIdLabel);

    final ICommitMessageComponentNotifications listener =
        new ICommitMessageComponentNotifications() {

          public void updateSignedOffToggleSelection(boolean selection) {
            signedOffItem.setSelection(selection);
          }

          public void updateChangeIdToggleSelection(boolean selection) {
            changeIdItem.setSelection(selection);
          }

          public void statusUpdated() {
            updateMessage();
          }
        };

    commitMessageComponent = new CommitMessageComponent(repository, listener);
    commitMessageComponent.enableListeners(false);
    commitMessageComponent.setDefaults();
    commitMessageComponent.attachControls(commitText, authorText, committerText);
    commitMessageComponent.setCommitMessage(commitMessage);
    commitMessageComponent.setAuthor(author);
    commitMessageComponent.setCommitter(committer);
    commitMessageComponent.setAmending(amending);
    commitMessageComponent.setFilesToCommit(getFileList());

    amendingItem.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent arg0) {
            commitMessageComponent.setAmendingButtonSelection(amendingItem.getSelection());
          }
        });

    changeIdItem.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent arg0) {
            commitMessageComponent.setChangeIdButtonSelection(changeIdItem.getSelection());
          }
        });

    signedOffItem.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent arg0) {
            commitMessageComponent.setSignedOffButtonSelection(signedOffItem.getSelection());
          }
        });

    commitMessageComponent.updateUI();
    commitMessageComponent.enableListeners(true);

    return messageAndPersonArea;
  }