private Composite createAvailableList(Composite parent) {
    Composite container = new Composite(parent, SWT.NONE);
    GridLayout layout = new GridLayout();
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    container.setLayout(layout);
    container.setLayoutData(new GridData());

    Label label = new Label(container, SWT.NONE);
    label.setText(PDEUIMessages.ImportWizard_DetailedPage_availableList);

    Table table = new Table(container, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL);
    GridData gd = new GridData(GridData.FILL_BOTH);
    gd.heightHint = 200;
    gd.widthHint = 225;
    table.setLayoutData(gd);

    fAvailableListViewer = new TableViewer(table);
    fAvailableListViewer.setLabelProvider(new PluginImportLabelProvider());
    fAvailableListViewer.setContentProvider(new ContentProvider());
    fAvailableListViewer.setInput(PDECore.getDefault().getModelManager());
    fAvailableListViewer.setComparator(ListUtil.PLUGIN_COMPARATOR);

    return container;
  }
 private void handleAdd() {
   IStructuredSelection ssel = (IStructuredSelection) fAvailableListViewer.getSelection();
   if (ssel.size() > 0) {
     Table table = fAvailableListViewer.getTable();
     int index = table.getSelectionIndices()[0];
     doAdd(ssel.toList());
     table.setSelection(index < table.getItemCount() ? index : table.getItemCount() - 1);
     pageChanged(true, false);
   }
 }
  private void updateButtons() {
    Object[] selected = ((IStructuredSelection) fPackageViewer.getSelection()).toArray();

    TablePart tablePart = getTablePart();
    tablePart.setButtonEnabled(ADD_INDEX, canAddExportedPackages());
    tablePart.setButtonEnabled(REMOVE_INDEX, isEditable() && selected.length > 0);
    tablePart.setButtonEnabled(PROPERTIES_INDEX, shouldEnableProperties(selected));
    tablePart.setButtonEnabled(
        CALCULATE_USE_INDEX, isEditable() && fPackageViewer.getTable().getItemCount() > 0);
  }
 @Override
 protected void refreshPage() {
   fAvailableListViewer.addFilter(fSourceFilter);
   fImportListViewer.getTable().removeAll();
   fSelected.clear();
   fAvailableFilter.setPattern("*"); // $NON-NLS-1$
   fSourceFilter.setState(fPage1.getState());
   fVersionFilter.setModel(fModels);
   fAvailableListViewer.refresh();
   pageChanged();
 }
  private void updateButtonEnablement(boolean doAddEnablement, boolean doRemoveEnablement) {
    updateCount();
    int availableCount = fAvailableListViewer.getTable().getItemCount();
    int importCount = fImportListViewer.getTable().getItemCount();

    if (doAddEnablement) updateSelectionBasedEnablement(fAvailableListViewer.getSelection(), true);
    if (doRemoveEnablement) updateSelectionBasedEnablement(fImportListViewer.getSelection(), false);

    fAddAllButton.setEnabled(availableCount > 0);
    fRemoveAllButton.setEnabled(importCount > 0);
    fAddRequiredButton.setEnabled(importCount > 0);
  }
 /** @param event */
 private void handleModelEventWorldChanged(IModelChangedEvent event) {
   // This section can get disposed if the configuration is changed from
   // plugins to features or vice versa.  Subsequently, the configuration
   // page is removed and readded.  In this circumstance, abort the
   // refresh
   if (fPluginTable.getTable().isDisposed()) {
     return;
   }
   // Reload the input
   fPluginTable.setInput(getProduct());
   // Perform the refresh
   refresh();
 }
  protected void handleAdd() {
    ElementListSelectionDialog dialog =
        new ElementListSelectionDialog(getShell(), new StyledBundleLabelProvider(false, false));

    try {
      dialog.setElements(getValidBundles());
    } catch (CoreException e) {
      dialog.setMessage(e.getMessage());
    }

    dialog.setTitle(PDEUIMessages.PluginSelectionDialog_title);
    dialog.setMessage(PDEUIMessages.PluginSelectionDialog_message);
    dialog.setMultipleSelection(true);
    if (dialog.open() == Window.OK) {

      Object[] models = dialog.getResult();
      ArrayList<NameVersionDescriptor> pluginsToAdd = new ArrayList<NameVersionDescriptor>();
      for (int i = 0; i < models.length; i++) {
        BundleInfo desc = ((BundleInfo) models[i]);
        pluginsToAdd.add(new NameVersionDescriptor(desc.getSymbolicName(), null));
      }
      Set<NameVersionDescriptor> allDependencies = new HashSet<NameVersionDescriptor>();
      allDependencies.addAll(pluginsToAdd);
      NameVersionDescriptor[] currentBundles = getTargetDefinition().getImplicitDependencies();
      if (currentBundles != null) {
        allDependencies.addAll(Arrays.asList(currentBundles));
      }
      getTargetDefinition()
          .setImplicitDependencies(
              allDependencies.toArray(new NameVersionDescriptor[allDependencies.size()]));
      fElementViewer.refresh();
      updateImpButtons();
    }
  }
 public boolean setFormInput(Object input) {
   if (input instanceof IProductPlugin) {
     fPluginTable.setSelection(new StructuredSelection(input), true);
     return true;
   }
   return super.setFormInput(input);
 }
 private void handleRemove() {
   LinkedList<NameVersionDescriptor> bundles = new LinkedList<NameVersionDescriptor>();
   bundles.addAll(Arrays.asList(getTargetDefinition().getImplicitDependencies()));
   Object[] removeBundles = ((IStructuredSelection) fElementViewer.getSelection()).toArray();
   if (removeBundles.length > 0) {
     for (int i = 0; i < removeBundles.length; i++) {
       if (removeBundles[i] instanceof NameVersionDescriptor) {
         bundles.remove(removeBundles[i]);
       }
     }
     getTargetDefinition()
         .setImplicitDependencies(bundles.toArray((new NameVersionDescriptor[bundles.size()])));
     fElementViewer.refresh();
     updateImpButtons();
   }
 }
Ejemplo n.º 10
0
 @Override
 protected CellEditor getCellEditor(Object element) {
   final TextCellEditor result = new TextCellEditor(viewer.getTable());
   result.setValidator(new NumberCellValidator());
   result.addListener(new CellEditorListener(shell, result));
   return result;
 }
  /**
   * 通过将检索结果结合中的记录分页加载的方法,实现控制检索结果记录的分页显示与快速加载
   *
   * @param facttable 显示检索结果的GUI表格对象
   * @param pagenum 显示在表格对象中的检索结果页码,从1开始计算
   */
  private void openCurrentTable(final int pagenum) {

    table.clearAll(); // 清空表格所有项目中的数据
    // 数据记录在检索结果结合中的下标开始值
    final int recordstart = (pagenum - 1) * pageSize;
    // 当前表格能显示的最后一条记录在检索结果集合中的索引号
    int end = recordstart + pageSize;
    // 若表格可显示的记录大于检索结果记录的总数,就只显示到最后一条检索结果记录
    final int recordend = Math.min(end, stationData.getRowCount()); // 显示的最后一条记录在检索结果集合中的索引号

    // 当前页面显示的检索结果记录数
    final int currentdispnum = recordend - recordstart;
    // 根据当前的页码,从检索结果集合中加载相应的数据到表的item域中
    tableViewer.setInput(stationData.getRow(recordstart, recordstart + currentdispnum)); // 自动输入数据
    tableViewer.refresh(); // 刷新表格false
  }
Ejemplo n.º 12
0
  private void setContent() {
    CatFormInit init = new CatFormInit(cfg);

    Label lblName = init.lblName(this);
    txtName = init.txtName(this, lblName);
    Label lblAbbrev = init.lblAbbrev(this, lblName);
    txtAbbrev = init.txtAbbrev(this, lblAbbrev);
    virtCheck = init.virtCheck(this, txtAbbrev);
    Label lblRate = init.lblRate(this, lblAbbrev);

    Composite tableContainer = new Composite(this, SWT.SHADOW_ETCHED_IN);
    rateViewer = init.catRateViewer(tableContainer, getShell(), contentProvider);
    init.tableContainer(lblRate, tableContainer);
    tblRate = rateViewer.getTable();

    addBtn = init.addBtn(this, lblRate, tableContainer);
    delBtn = init.delBtn(this, lblRate, tableContainer);
    Label lblComment = init.lblComment(this, tableContainer);
    txtComment = init.txtComment(this, lblComment);

    txtName.addFocusListener(new RefreshFocusLsnr());
    txtAbbrev.addFocusListener(new RefreshFocusLsnr());
    txtComment.addFocusListener(new RefreshFocusLsnr());

    virtCheck.addListener(
        SWT.Selection,
        new Listener() {
          public void handleEvent(Event event) {
            tblRate.setEnabled(!virtCheck.getSelection());
            addBtn.setEnabled(!virtCheck.getSelection());
            delBtn.setEnabled(!virtCheck.getSelection());
            refreshListener.refresh(); // освежим данные в дереве и в базе
          }
        });

    addBtn.addListener(
        SWT.Selection,
        new Listener() {
          public void handleEvent(Event event) {
            contentProvider.append();
            rateViewer.refresh();
          }
        });

    delBtn.addListener(
        SWT.Selection,
        new Listener() {
          public void handleEvent(Event event) {
            int selIdx = rateViewer.getTable().getSelectionIndex();
            if (selIdx >= 0) {
              contentProvider.deleteAt(selIdx);
            }
            rateViewer.refresh();
            Table table = rateViewer.getTable();
            int lastPos = table.getItemCount() - 1;
            table.setSelection(lastPos);
          }
        });
  }
Ejemplo n.º 13
0
 /** 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);
 }
  /* (non-Javadoc)
   * @see org.eclipse.pde.internal.ui.editor.PDESection#createClient(org.eclipse.ui.forms.widgets.Section, org.eclipse.ui.forms.widgets.FormToolkit)
   */
  protected void createClient(Section section, FormToolkit toolkit) {

    section.setLayout(FormLayoutFactory.createClearGridLayout(false, 1));
    GridData sectionData = new GridData(GridData.FILL_BOTH);
    sectionData.verticalSpan = 2;
    section.setLayoutData(sectionData);

    Composite container = createClientContainer(section, 2, toolkit);
    createViewerPartControl(container, SWT.MULTI, 2, toolkit);
    container.setLayoutData(new GridData(GridData.FILL_BOTH));

    createOptionalDependenciesButton(container);

    TablePart tablePart = getTablePart();
    fPluginTable = tablePart.getTableViewer();
    fPluginTable.setContentProvider(new ContentProvider());
    fPluginTable.setLabelProvider(PDEPlugin.getDefault().getLabelProvider());
    fPluginTable.setComparator(
        new ViewerComparator() {
          public int compare(Viewer viewer, Object e1, Object e2) {
            IProductPlugin p1 = (IProductPlugin) e1;
            IProductPlugin p2 = (IProductPlugin) e2;
            return super.compare(viewer, p1.getId(), p2.getId());
          }
        });
    GridData data = (GridData) tablePart.getControl().getLayoutData();
    data.minimumWidth = 200;
    fPluginTable.setInput(getProduct());

    tablePart.setButtonEnabled(0, isEditable());
    tablePart.setButtonEnabled(1, isEditable());
    tablePart.setButtonEnabled(2, isEditable());

    // remove buttons will be updated on refresh

    tablePart.setButtonEnabled(5, isEditable());

    toolkit.paintBordersFor(container);
    section.setClient(container);

    section.setText(PDEUIMessages.Product_PluginSection_title);
    section.setDescription(PDEUIMessages.Product_PluginSection_desc);
    getModel().addModelChangedListener(this);
    createSectionToolbar(section, toolkit);
  }
 private void addPlugin(String id, String version) {
   IProduct product = getProduct();
   IProductModelFactory factory = product.getModel().getFactory();
   IProductPlugin plugin = factory.createPlugin();
   plugin.setId(id);
   plugin.setVersion(version);
   product.addPlugins(new IProductPlugin[] {plugin});
   fPluginTable.setSelection(new StructuredSelection(plugin));
 }
 private void handleDelete() {
   IStructuredSelection ssel = (IStructuredSelection) fPluginTable.getSelection();
   if (ssel.size() > 0) {
     Object[] objects = ssel.toArray();
     IProductPlugin[] plugins = new IProductPlugin[objects.length];
     System.arraycopy(objects, 0, plugins, 0, objects.length);
     getProduct().removePlugins(plugins);
     updateRemoveButtons(true, true);
   }
 }
  private void addViewerListeners() {
    fAvailableListViewer.addDoubleClickListener(
        new IDoubleClickListener() {
          @Override
          public void doubleClick(DoubleClickEvent event) {
            handleAdd();
          }
        });

    fImportListViewer.addDoubleClickListener(
        new IDoubleClickListener() {
          @Override
          public void doubleClick(DoubleClickEvent event) {
            handleRemove();
          }
        });

    fAvailableListViewer.addSelectionChangedListener(
        new ISelectionChangedListener() {
          @Override
          public void selectionChanged(SelectionChangedEvent event) {
            updateSelectionBasedEnablement(event.getSelection(), true);
          }
        });

    fImportListViewer.addSelectionChangedListener(
        new ISelectionChangedListener() {
          @Override
          public void selectionChanged(SelectionChangedEvent event) {
            updateSelectionBasedEnablement(event.getSelection(), false);
          }
        });

    fFilterText.addModifyListener(
        new ModifyListener() {
          @Override
          public void modifyText(ModifyEvent e) {
            fFilterJob.cancel();
            fFilterJob.schedule(200);
          }
        });
  }
 private void handleFilter() {
   boolean changed = false;
   String newFilter;
   if (fFilterText == null || (newFilter = fFilterText.getText().trim()).length() == 0)
     newFilter = "*"; // $NON-NLS-1$
   changed = fAvailableFilter.setPattern(newFilter);
   if (changed) {
     fAvailableListViewer.refresh();
     updateButtonEnablement(false, false);
   }
 }
Ejemplo n.º 19
0
 public void setCatCurrent(CatRbEntity catCurrent) {
   EntityManager em = DbHelper.getEm();
   this.catCurrent = catCurrent;
   txtName.setText(catCurrent.getName());
   txtAbbrev.setText(catCurrent.getAbbrev());
   txtComment.setText(catCurrent.getComment());
   setVirtual(catCurrent.getVirtual() == 1);
   Query query = em.createQuery("select c from CatRateLinkEntity c where c.cat = ?1");
   query.setParameter(1, catCurrent);
   rateViewer.setInput(query.getResultList());
 }
  @Override
  protected void createClient(Section section, FormToolkit toolkit) {
    section.setText(PDEUIMessages.ExportPackageSection_title);
    if (isFragment()) section.setDescription(PDEUIMessages.ExportPackageSection_descFragment);
    else section.setDescription(PDEUIMessages.ExportPackageSection_desc);

    Composite container = createClientContainer(section, 2, toolkit);
    createViewerPartControl(container, SWT.MULTI, 2, toolkit);
    TablePart tablePart = getTablePart();
    fPackageViewer = tablePart.getTableViewer();
    fPackageViewer.setContentProvider(new ExportPackageContentProvider());
    fPackageViewer.setLabelProvider(PDEPlugin.getDefault().getLabelProvider());
    fPackageViewer.setComparator(
        new ViewerComparator() {
          @Override
          public int compare(Viewer viewer, Object e1, Object e2) {
            String s1 = e1.toString();
            String s2 = e2.toString();
            if (s1.indexOf(" ") != -1) // $NON-NLS-1$
            s1 = s1.substring(0, s1.indexOf(" ")); // $NON-NLS-1$
            if (s2.indexOf(" ") != -1) // $NON-NLS-1$
            s2 = s2.substring(0, s2.indexOf(" ")); // $NON-NLS-1$
            return super.compare(viewer, s1, s2);
          }
        });
    toolkit.paintBordersFor(container);
    section.setClient(container);
    GridData gd = new GridData(GridData.FILL_BOTH);
    if (((ManifestEditor) getPage().getEditor()).isEquinox()) {
      gd.verticalSpan = 2;
      gd.minimumWidth = 300;
    }
    section.setLayout(FormLayoutFactory.createClearGridLayout(false, 1));
    section.setLayoutData(gd);
    makeActions();

    IBundleModel model = getBundleModel();
    fPackageViewer.setInput(model);
    model.addModelChangedListener(this);
    updateButtons();
  }
  private void handleAddAll() {
    TableItem[] items = fAvailableListViewer.getTable().getItems();

    ArrayList<Object> data = new ArrayList<>();
    for (int i = 0; i < items.length; i++) {
      data.add(items[i].getData());
    }
    if (data.size() > 0) {
      doAdd(data);
      pageChanged(true, false);
    }
  }
Ejemplo n.º 22
0
 @Override
 protected void setValue(Object element, Object value) {
   CatRateLinkEntity linkEntity = (CatRateLinkEntity) element;
   String valueStr = (String) value;
   try {
     linkEntity.setDefValue(Integer.valueOf(valueStr));
     DbHelper.merge(linkEntity);
     viewer.update(element, null);
   } catch (Exception e) {
     Util.dbError(shell, e);
   }
 }
Ejemplo n.º 23
0
 @SuppressWarnings({"unchecked"})
 @Override
 protected CellEditor getCellEditor(Object element) {
   EntityManager em = DbHelper.getEm();
   Query query = em.createQuery("select r from RateRbEntity r");
   rates = query.getResultList();
   String rNames[] = new String[rates.size()];
   for (int i = 0; i < rates.size(); ++i) {
     rNames[i] = rates.get(i).getName();
   }
   return new ComboBoxCellEditor(viewer.getTable(), rNames);
 }
  @Override
  public void modelChanged(IModelChangedEvent event) {
    if (event.getChangeType() == IModelChangedEvent.WORLD_CHANGED) {
      fHeader = null;
      markStale();
      return;
    }

    if (getExportedPackageHeader().equals(event.getChangedProperty())) {
      refresh();
      // Bug 171896
      // Since the model sends a CHANGE event instead of
      // an INSERT event on the very first addition to the empty table
      // Selection should fire here to take this first insertion into account
      Object lastElement =
          fPackageViewer.getElementAt(fPackageViewer.getTable().getItemCount() - 1);
      if (lastElement != null) {
        fPackageViewer.setSelection(new StructuredSelection(lastElement));
      }

      return;
    }

    Object[] objects = event.getChangedObjects();
    for (Object changedObject : objects) {
      if (changedObject instanceof ExportPackageObject) {
        ExportPackageObject object = (ExportPackageObject) changedObject;
        switch (event.getChangeType()) {
          case IModelChangedEvent.INSERT:
            fPackageViewer.add(object);
            fPackageViewer.setSelection(new StructuredSelection(object), false);
            fPackageViewer.getTable().setFocus();
            break;
          case IModelChangedEvent.REMOVE:
            Table table = fPackageViewer.getTable();
            int index = table.getSelectionIndex();
            fPackageViewer.remove(object);
            table.setSelection(index < table.getItemCount() ? index : table.getItemCount() - 1);
            break;
          default:
            fPackageViewer.refresh(object);
        }
      }
    }
  }
 private void handleProperties() {
   IStructuredSelection ssel = (IStructuredSelection) fPluginTable.getSelection();
   if (ssel.size() == 1) {
     IProductPlugin plugin = (IProductPlugin) ssel.toArray()[0];
     VersionDialog dialog =
         new VersionDialog(PDEPlugin.getActiveWorkbenchShell(), isEditable(), plugin.getVersion());
     dialog.create();
     SWTUtil.setDialogSize(dialog, 400, 200);
     if (dialog.open() == Window.OK) {
       plugin.setVersion(dialog.getVersion());
     }
   }
 }
 @Override
 protected void fillContextMenu(IMenuManager manager) {
   ISelection selection = fPackageViewer.getSelection();
   manager.add(fAddAction);
   boolean singleSelection =
       selection instanceof IStructuredSelection && ((IStructuredSelection) selection).size() == 1;
   if (singleSelection) manager.add(fGoToAction);
   manager.add(new Separator());
   if (!selection.isEmpty()) manager.add(fRemoveAction);
   getPage().getPDEEditor().getContributor().contextMenuAboutToShow(manager);
   if (singleSelection)
     manager.add(
         new Action(PDEUIMessages.ExportPackageSection_findReferences) {
           @Override
           public void run() {
             doSearch(fPackageViewer.getSelection());
           }
         });
   if (shouldEnableProperties(((IStructuredSelection) fPackageViewer.getSelection()).toArray())) {
     manager.add(new Separator());
     manager.add(fPropertiesAction);
   }
 }
  private void addFilters() {
    fVersionFilter = new VersionFilter();
    fVersionFilter.setModel(fModels);
    fSourceFilter = new SourcePluginFilter(fPage1.getState());
    fAvailableFilter = new AvailableFilter();
    fAvailableListViewer.addFilter(fAvailableFilter);
    if (fFilterOldVersionButton.getSelection()) {
      fAvailableListViewer.addFilter(fVersionFilter);
    }
    fAvailableListViewer.addFilter(fSourceFilter);
    fRepositoryFilter = new RepositoryFilter();
    fAvailableListViewer.addFilter(fRepositoryFilter);

    fFilterJob =
        new WorkbenchJob("FilterJob") { // $NON-NLS-1$
          @Override
          public IStatus runInUIThread(IProgressMonitor monitor) {
            handleFilter();
            return Status.OK_STATUS;
          }
        };
    fFilterJob.setSystem(true);
  }
Ejemplo n.º 28
0
 @Override
 protected void setValue(Object element, Object value) {
   if ((Integer) value > -1) {
     RateRbEntity rateEntity = rates.get((Integer) value);
     CatRateLinkEntity entity = (CatRateLinkEntity) element;
     try {
       entity.setRate(rateEntity);
       DbHelper.merge(entity);
       viewer.update(element, null);
     } catch (Exception e) {
       Util.dbError(shell, e);
     }
   }
 }
  /* (non-Javadoc)
   * @see org.eclipse.pde.internal.ui.editor.PDESection#modelChanged(org.eclipse.pde.core.IModelChangedEvent)
   */
  public void modelChanged(IModelChangedEvent e) {
    // No need to call super, handling world changed event here
    if (e.getChangeType() == IModelChangedEvent.WORLD_CHANGED) {
      handleModelEventWorldChanged(e);
      return;
    }
    Object[] objects = e.getChangedObjects();
    if (e.getChangeType() == IModelChangedEvent.INSERT) {
      for (int i = 0; i < objects.length; i++) {
        if (objects[i] instanceof IProductPlugin) fPluginTable.add(objects[i]);
      }
    } else if (e.getChangeType() == IModelChangedEvent.REMOVE) {

      Table table = fPluginTable.getTable();
      int index = table.getSelectionIndex();

      for (int i = 0; i < objects.length; i++) {
        if (objects[i] instanceof IProductPlugin) fPluginTable.remove(objects[i]);
      }

      // Update Selection

      int count = table.getItemCount();

      if (count == 0) {
        // Nothing to select
      } else if (index < count) {
        table.setSelection(index);
      } else {
        table.setSelection(count - 1);
      }

    } else if (e.getChangeType() == IModelChangedEvent.CHANGE) {
      fPluginTable.refresh();
    }
    updateRemoveButtons(false, true);
  }
  private void updateCount() {
    if (fCountTotal <= 0) {
      // Since we filter the list of available plug-ins the total may differ from the model count
      fCountTotal = fAvailableListViewer.getTable().getItemCount();
    }

    fCountLabel.setText(
        NLS.bind(
            PDEUIMessages.ImportWizard_DetailedPage_count,
            (new String[] {
              Integer.toString(fImportListViewer.getTable().getItemCount()),
              Integer.toString(fCountTotal)
            })));
    fCountLabel.getParent().layout();
  }