Beispiel #1
0
 public static CellEditor createPropertyEditor(
     final IServiceLocator serviceLocator,
     Composite parent,
     DBPPropertySource source,
     DBPPropertyDescriptor property) {
   if (source == null) {
     return null;
   }
   final Object object = source.getEditableValue();
   if (!property.isEditable(object)) {
     return null;
   }
   CellEditor cellEditor = UIUtils.createCellEditor(parent, object, property);
   if (cellEditor != null) {
     final Control editorControl = cellEditor.getControl();
     UIUtils.addFocusTracker(serviceLocator, UIUtils.INLINE_WIDGET_EDITOR_ID, editorControl);
     editorControl.addDisposeListener(
         new DisposeListener() {
           @Override
           public void widgetDisposed(DisposeEvent e) {
             UIUtils.removeFocusTracker(serviceLocator, editorControl);
           }
         });
   }
   return cellEditor;
 }
Beispiel #2
0
 public static boolean isParent(Control parent, Control child) {
   for (Control c = child; c != null; c = c.getParent()) {
     if (c == parent) {
       return true;
     }
   }
   return false;
 }
 /** Register the context menu for the viewer so that commands may be added to it. */
 private void registerContextMenu() {
   MenuManager contextMenu = new MenuManager();
   contextMenu.setRemoveAllWhenShown(true);
   getSite().registerContextMenu(contextMenu, mViewer);
   Control control = mViewer.getControl();
   Menu menu = contextMenu.createContextMenu(control);
   control.setMenu(menu);
 }
Beispiel #4
0
 public static void enableWithChildren(Composite composite, boolean enable) {
   composite.setEnabled(enable);
   for (Control child : composite.getChildren()) {
     if (child instanceof Composite) {
       enableWithChildren((Composite) child, enable);
     } else {
       child.setEnabled(enable);
     }
   }
 }
Beispiel #5
0
 /**
  * Determine whether this control or any of it's child has focus
  *
  * @param control control to check
  * @return true if it has focus
  */
 public static boolean hasFocus(Control control) {
   Control focusControl = control.getDisplay().getFocusControl();
   if (focusControl == null) {
     return false;
   }
   for (Control fc = focusControl; fc != null; fc = fc.getParent()) {
     if (fc == control) {
       return true;
     }
   }
   return false;
 }
 /* (non-Javadoc)
  * @see org.eclipse.pde.internal.core.IPluginModelListener#modelsChanged(org.eclipse.pde.internal.core.PluginModelDelta)
  */
 public void modelsChanged(PluginModelDelta delta) {
   final Control control = fPluginTable.getControl();
   if (!control.isDisposed()) {
     control
         .getDisplay()
         .asyncExec(
             new Runnable() {
               public void run() {
                 if (!control.isDisposed()) {
                   fPluginTable.refresh();
                   updateRemoveButtons(true, true);
                 }
               }
             });
   }
 }
Beispiel #7
0
 public static void postEvent(Control ownerControl, final Event event) {
   final Display display = ownerControl.getDisplay();
   display.asyncExec(
       new Runnable() {
         @Override
         public void run() {
           display.post(event);
         }
       });
 }
  private void createSourceViewer(Composite parent) {
    sourceFileViewer =
        new TreeViewer(new Tree(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER));
    sourceFileViewer.setContentProvider(new WorkbenchContentProvider());
    sourceFileViewer.setLabelProvider(new WorkbenchLabelProvider());
    sourceFileViewer.addSelectionChangedListener(
        new ISelectionChangedListener() {
          public void selectionChanged(SelectionChangedEvent event) {
            java.util.List list;
            ISelection selection = event.getSelection();
            boolean newFilesSelected = false;

            if (selection instanceof IStructuredSelection) {
              list = ((IStructuredSelection) selection).toList();
              for (Iterator i = list.iterator(); i.hasNext(); ) {
                IResource resource = (IResource) i.next();
                if (resource instanceof IFile) {
                  if (checkIfFileInTarget((IFile) resource) == false) newFilesSelected = true;
                }
              }
              setAddButtonEnabled(newFilesSelected);
            }
          }
        });
    sourceFileViewer.addDoubleClickListener(
        new IDoubleClickListener() {
          public void doubleClick(DoubleClickEvent event) {
            addSelectedFilesToTargetList();
          }
        });

    Control treeWidget = sourceFileViewer.getTree();
    GridData gd = new GridData(GridData.FILL_BOTH);
    gd.widthHint = SIZING_LISTS_WIDTH;
    gd.heightHint = SIZING_LISTS_HEIGHT;
    treeWidget.setLayoutData(gd);
  }
Beispiel #9
0
  public static void enableHostEditorKeyBindingsSupport(
      final IWorkbenchPartSite partSite, Control control) {
    if (!(partSite.getPart() instanceof AbstractTextEditor)) {
      return;
    }

    final boolean[] activated = new boolean[] {false};
    control.addFocusListener(
        new FocusListener() {
          @Override
          public void focusGained(FocusEvent e) {
            if (!activated[0]) {
              UIUtils.enableHostEditorKeyBindings(partSite, false);
              activated[0] = true;
            }
          }

          @Override
          public void focusLost(FocusEvent e) {
            if (activated[0]) {
              UIUtils.enableHostEditorKeyBindings(partSite, true);
              activated[0] = false;
            }
          }
        });
    control.addDisposeListener(
        new DisposeListener() {
          @Override
          public void widgetDisposed(DisposeEvent e) {
            if (activated[0]) {
              UIUtils.enableHostEditorKeyBindings(partSite, true);
              activated[0] = false;
            }
          }
        });
  }
  @Override
  protected Control createControl(Composite parent) {
    Composite propertyComposite = new Composite(parent, SWT.BORDER);
    GridLayout layout = new GridLayout(1, false);
    layout.marginWidth = layout.marginHeight = 0;
    propertyComposite.setLayout(layout);
    if (mPage instanceof Page) {
      ((Page) mPage)
          .init(
              new IPageSite() {
                public void registerContextMenu(
                    String menuId, MenuManager menuManager, ISelectionProvider selectionProvider) {}

                public IActionBars getActionBars() {
                  return null;
                }

                public IWorkbenchPage getPage() {
                  return getWorkbenchWindow().getActivePage();
                }

                public ISelectionProvider getSelectionProvider() {
                  return null;
                }

                public Shell getShell() {
                  return getWorkbenchWindow().getShell();
                }

                public IWorkbenchWindow getWorkbenchWindow() {
                  return PlatformUI.getWorkbench().getActiveWorkbenchWindow();
                }

                public void setSelectionProvider(ISelectionProvider provider) {}

                @SuppressWarnings("unchecked")
                public Object getAdapter(Class adapter) {
                  return null;
                }

                @SuppressWarnings("unchecked")
                public Object getService(Class api) {
                  return null;
                }

                @SuppressWarnings("unchecked")
                public boolean hasService(Class api) {
                  return false;
                }
              });
    }
    if (mPage instanceof PropertySheetPage) {
      ((PropertySheetPage) mPage).setPropertySourceProvider(this);
    }
    mPage.createControl(propertyComposite);
    mPage.setActionBars(new DummyActionBars());
    final Control control = mPage.getControl();
    GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
    if (control instanceof Tree) {
      final Tree tree = (Tree) control;
      data.heightHint =
          tree.getItemHeight() * 13
              + (tree.getLinesVisible() ? 12 * tree.getGridLineWidth() : 0)
              + (tree.getHeaderVisible() ? tree.getHeaderHeight() : 0)
              + 2 * tree.getBorderWidth()
              + (tree.getHorizontalBar() != null ? tree.getHorizontalBar().getSize().x : 0);
      tree.addControlListener(
          new ControlAdapter() {
            @Override
            public void controlResized(ControlEvent e) {
              Rectangle area = tree.getClientArea();
              TreeColumn[] columns = tree.getColumns();
              if (area.width > 0) {
                columns[0].setWidth(area.width * 40 / 100);
                columns[1].setWidth(area.width - columns[0].getWidth() - 4);
              }
            }
          });
    } else if (control instanceof Composite) {
      control.addControlListener(
          new ControlAdapter() {
            @Override
            public void controlResized(ControlEvent e) {
              ((Composite) control).layout(true, true);
            }
          });
    }
    control.setLayoutData(data);
    ISelection selection;
    if (mCurrentWidget == null) {
      Collection<InstallOptionsModelTypeDef> typeDefs =
          InstallOptionsModel.INSTANCE.getControlTypeDefs();
      if (typeDefs.size() > 0) {
        InstallOptionsModelTypeDef typeDef = typeDefs.iterator().next();
        InstallOptionsElementFactory factory =
            InstallOptionsElementFactory.getFactory(typeDef.getType());
        mCurrentWidget = (InstallOptionsWidget) factory.getNewObject();
        mDialog.addChild(mCurrentWidget);
      }
    }

    if (mCurrentWidget != null) {
      mCurrentWidget.addModelCommandListener(InstallOptionsWidgetEditorDialog.this);
      mCurrentWidget.addPropertyChangeListener(InstallOptionsWidgetEditorDialog.this);
      if (mCurrentWidget.getParent() != null) {
        mCurrentWidget.getParent().addPropertyChangeListener(InstallOptionsWidgetEditorDialog.this);
      }
      selection = new StructuredSelection(mCurrentWidget);
    } else {
      selection = StructuredSelection.EMPTY;
    }

    mPage.selectionChanged(null, selection);
    PlatformUI.getWorkbench().getHelpSystem().setHelp(mPage.getControl(), HELP_CONTEXT);
    PlatformUI.getWorkbench().getHelpSystem().setHelp(propertyComposite, HELP_CONTEXT);

    return propertyComposite;
  }
Beispiel #11
0
 public static void drawMessageOverControl(
     Control control, PaintEvent e, String message, int offset) {
   Rectangle bounds = control.getBounds();
   Point ext = e.gc.textExtent(message);
   e.gc.drawText(message, (bounds.width - ext.x) / 2, bounds.height / 3 + offset);
 }
Beispiel #12
0
 public static boolean isInDialog(Control control) {
   return control.getShell().getData() instanceof org.eclipse.jface.dialogs.Dialog;
 }