Java Code Examples for org.eclipse.jface.viewers.IStructuredContentProvider

The following code examples are extracted from open source projects. You can click to vote up the examples that are useful to you.

Example 1

From project JGit, under directory /org.spearce.egit.ui/src/org/spearce/egit/ui/internal/history/.

Source file: CommitFileDiffViewer.java

  22 
vote

void doSelectAll(){
  final IStructuredContentProvider cp;
  final Object in=getInput();
  if (in == null)   return;
  cp=((IStructuredContentProvider)getContentProvider());
  final Object[] el=cp.getElements(in);
  if (el == null || el.length == 0)   return;
  setSelection(new StructuredSelection(el));
}
 

Example 2

From project dawn-common, under directory /org.dawb.common.ui/src/org/dawb/common/ui/views/monitor/.

Source file: MonitorView.java

  21 
vote

private void createContentProvider(){
  serverViewer.setContentProvider(new IStructuredContentProvider(){
    @Override public void dispose(){
    }
    @Override public void inputChanged(    Viewer viewer,    Object oldInput,    Object newInput){
    }
    @Override public Object[] getElements(    Object inputElement){
      return data.toArray();
    }
  }
);
}
 

Example 3

From project dawn-ui, under directory /org.dawb.workbench.plotting/src/org/dawb/workbench/plotting/tools/fitting/.

Source file: FittingTool.java

  21 
vote

private IContentProvider createContentProvider(){
  return new IStructuredContentProvider(){
    @Override public void dispose(){
    }
    @Override public void inputChanged(    Viewer viewer,    Object oldInput,    Object newInput){
    }
    @Override public Object[] getElements(    Object inputElement){
      if (fittedPeaks == null)       return new IPeak[]{new NullPeak()};
      if (fittedPeaks.size() < 1)       return new IPeak[]{new NullPeak()};
      return fittedPeaks.toArray();
    }
  }
;
}
 

Example 4

From project gda-common-rcp, under directory /uk.ac.gda.common.rcp/src/uk/ac/gda/ui/dialog/.

Source file: VisitIDDialog.java

  21 
vote

private void createContentProvider(){
  userTable.setContentProvider(new IStructuredContentProvider(){
    @Override public void dispose(){
    }
    @Override public void inputChanged(    Viewer viewer,    Object oldInput,    Object newInput){
    }
    @Override public Object[] getElements(    Object inputElement){
      return visits;
    }
  }
);
}
 

Example 5

From project JGit, under directory /org.spearce.egit.ui/src/org/spearce/egit/ui/internal/preferences/.

Source file: GitDecoratorPreferencePage.java

  21 
vote

/** 
 * Adds another variable to the given target text A ListSelectionDialog pops up and allow the user to choose the variable, which is then inserted at current position in <code>text</code>
 * @param target the target to add the variable to
 * @param bindings the map of bindings
 */
private void addVariables(Text target,Map bindings){
  final List<StringPair> variables=new ArrayList<StringPair>(bindings.size());
  ILabelProvider labelProvider=new LabelProvider(){
    public String getText(    Object element){
      return ((StringPair)element).s1 + " - " + ((StringPair)element).s2;
    }
  }
;
  IStructuredContentProvider contentsProvider=new IStructuredContentProvider(){
    public Object[] getElements(    Object inputElement){
      return variables.toArray(new StringPair[variables.size()]);
    }
    public void dispose(){
    }
    public void inputChanged(    Viewer viewer,    Object oldInput,    Object newInput){
    }
  }
;
  for (Iterator it=bindings.keySet().iterator(); it.hasNext(); ) {
    StringPair variable=new StringPair();
    variable.s1=(String)it.next();
    variable.s2=(String)bindings.get(variable.s1);
    variables.add(variable);
  }
  ListSelectionDialog dialog=new ListSelectionDialog(this.getShell(),this,contentsProvider,labelProvider,UIText.DecoratorPreferencesPage_selectVariablesToAdd);
  dialog.setTitle(UIText.DecoratorPreferencesPage_addVariablesTitle);
  if (dialog.open() != Window.OK)   return;
  Object[] result=dialog.getResult();
  for (int i=0; i < result.length; i++) {
    target.insert("{" + ((StringPair)result[i]).s1 + "}");
  }
}
 

Example 6

From project zest, under directory /org.eclipse.zest.cloudio/src/main/java/org/eclipse/zest/cloudio/.

Source file: TagCloudViewer.java

  21 
vote

@Override protected void inputChanged(Object input,Object oldInput){
  selection.clear();
  objectMap.clear();
  IStructuredContentProvider contentProvider=(IStructuredContentProvider)getContentProvider();
  Object[] elements=contentProvider.getElements(input);
  List<Word> words=new ArrayList<Word>();
  ICloudLabelProvider labelProvider=(ICloudLabelProvider)getLabelProvider();
  short i=0;
  for (  Object element : elements) {
    Word word=new Word(labelProvider.getLabel(element));
    word.setColor(labelProvider.getColor(element));
    word.weight=labelProvider.getWeight(element);
    word.setFontData(labelProvider.getFontData(element));
    word.angle=labelProvider.getAngle(element);
    word.data=element;
    Assert.isLegal(word.string != null,"Labelprovider must return a String for each element");
    Assert.isLegal(word.getColor() != null,"Labelprovider must return a Color for each element");
    Assert.isLegal(word.getFontData() != null,"Labelprovider must return a FontData for each element");
    Assert.isLegal(word.weight >= 0,"Labelprovider must return a weight between 0 and 1 (inclusive), but value was " + word.weight);
    Assert.isLegal(word.weight <= 1,"Labelprovider must return a weight between 0 and 1 (inclusive), but value was " + word.weight);
    Assert.isLegal(word.angle >= -90,"Angle of an element must be between -90 and +90 (inclusive), but was " + word.angle);
    Assert.isLegal(word.angle <= 90,"Angle of an element must be between -90 and +90 (inclusive), but was " + word.angle);
    words.add(word);
    i++;
    word.id=i;
    objectMap.put(element,word);
    if (i == maxWords)     break;
  }
  selection.clear();
  if (monitor != null) {
    monitor.subTask("Layouting...");
  }
  cloud.setWords(words,monitor);
}
 

Example 7

From project dawn-common, under directory /org.dawb.common.ui/src/org/dawb/common/ui/plot/function/.

Source file: FunctionEditTable.java

  20 
vote

/** 
 * Can be called also to change to editing a different function.
 * @param function
 * @param functionType - may be null
 */
public void setFunction(final AFunction function,final FunctionType functionType){
  this.setFunctionType(functionType);
  this.originalFunction=function != null ? function : null;
  this.function=function != null ? function : null;
  this.rows=createFunctionRows(function);
  functionTable.setContentProvider(new IStructuredContentProvider(){
    @Override public void inputChanged(    Viewer viewer,    Object oldInput,    Object newInput){
    }
    @Override public void dispose(){
    }
    @Override public Object[] getElements(    Object inputElement){
      return rows.toArray(new FunctionRow[rows.size()]);
    }
  }
);
  functionTable.setInput(rows.get(0));
}
 

Example 8

From project dawn-isenciaui, under directory /com.isencia.passerelle.workbench.model.editor.ui/src/main/java/com/isencia/passerelle/workbench/model/editor/ui/views/.

Source file: ActorAttributesView.java

  20 
vote

private void createTableModel(final List<Attribute> parameterList){
  if (parameterList != null)   Collections.sort(parameterList,new NamedObjComparator());
  try {
    viewer.setContentProvider(new IStructuredContentProvider(){
      @Override public void dispose(){
      }
      @Override public void inputChanged(      Viewer viewer,      Object oldInput,      Object newInput){
      }
      @Override public Object[] getElements(      Object inputElement){
        if (parameterList == null)         return new Parameter[]{};
        final List<Object> ret=new ArrayList<Object>(parameterList.size() + 1);
        final Director director=actor instanceof Actor ? (Director)((Actor)actor).getDirector() : null;
        if (actor instanceof Actor)         ret.add(new GeneralAttribute(GeneralAttribute.ATTRIBUTE_TYPE.TYPE,PaletteItemFactory.getInstance().getType(actor.getClass())));
        if (actor instanceof Actor && director != null && director.isExpertMode())         ret.add(new GeneralAttribute(GeneralAttribute.ATTRIBUTE_TYPE.CLASS,actor.getClass().getName()));
        ret.add(new GeneralAttribute(GeneralAttribute.ATTRIBUTE_TYPE.NAME,PaletteItemFactory.getInstance().getType(actor.getName())));
        ret.addAll(parameterList);
        return ret.toArray(new Object[ret.size()]);
      }
    }
);
    viewer.setInput(new Object());
    viewer.refresh();
  }
 catch (  Exception e) {
    logger.error("Cannot set input",e);
  }
}
 

Example 9

From project dawn-ui, under directory /org.dawb.workbench.plotting/src/org/dawb/workbench/plotting/tools/.

Source file: EllipseFittingTool.java

  20 
vote

@Override public void createControl(Composite parent){
  composite=new Composite(parent,SWT.NONE);
  composite.setLayout(new FillLayout());
  viewer=new TableViewer(composite,SWT.FULL_SELECTION | SWT.SINGLE | SWT.H_SCROLL| SWT.V_SCROLL| SWT.BORDER);
  createColumns(viewer);
  Table t=viewer.getTable();
  t.setLinesVisible(true);
  t.setHeaderVisible(true);
  createActions();
  getSite().setSelectionProvider(viewer);
  viewer.setContentProvider(new IStructuredContentProvider(){
    @Override public void inputChanged(    Viewer viewer,    Object oldInput,    Object newInput){
    }
    @Override public void dispose(){
    }
    @Override public Object[] getElements(    Object inputElement){
      return ellipses.toArray();
    }
  }
);
  viewer.setInput(ellipses);
  parent.layout();
}
 

Example 10

From project dawn-workflow, under directory /org.dawb.passerelle.actors/src/org/dawb/passerelle/editors/.

Source file: SubstitutionEditor.java

  20 
vote

private IContentProvider createActorContentProvider(){
  return new IStructuredContentProvider(){
    @Override public void dispose(){
    }
    @Override public void inputChanged(    Viewer viewer,    Object oldInput,    Object newInput){
    }
    @Override public Object[] getElements(    Object inputElement){
      if (actor == null)       return new Object[]{"-"};
      final List<IVariable> vars=actor.getInputVariables();
      if (vars != null && !vars.isEmpty())       return vars.toArray();
      return new Object[]{"-"};
    }
  }
;
}
 

Example 11

From project dawn-workflow, under directory /org.dawb.passerelle.actors/src/org/dawb/passerelle/editors/.

Source file: XMLSubstitutionEditor.java

  20 
vote

private IContentProvider createActorContentProvider(){
  return new IStructuredContentProvider(){
    @Override public void dispose(){
    }
    @Override public void inputChanged(    Viewer viewer,    Object oldInput,    Object newInput){
    }
    @Override public Object[] getElements(    Object inputElement){
      if (actor == null)       return new Object[]{"-"};
      final List<IVariable> vars=actor.getInputVariables();
      if (vars != null && !vars.isEmpty())       return vars.toArray();
      return new Object[]{"-"};
    }
  }
;
}
 

Example 12

From project eclipse-integration-cloudfoundry, under directory /org.cloudfoundry.ide.eclipse.server.ui/src/org/cloudfoundry/ide/eclipse/internal/server/ui/wizards/.

Source file: TunnelDisplayPart.java

  20 
vote

public Control createControl(Composite parent){
  Composite tableArea=new Composite(parent,SWT.NONE);
  GridLayoutFactory.fillDefaults().numColumns(1).spacing(0,0).applyTo(tableArea);
  GridDataFactory.fillDefaults().grab(true,true).applyTo(tableArea);
  Table table=new Table(tableArea,SWT.BORDER | SWT.MULTI);
  table.setSize(new Point(400,400));
  GridDataFactory.fillDefaults().grab(true,true).applyTo(table);
  servicesViewer=new TableViewer(table);
  servicesViewer.setContentProvider(new IStructuredContentProvider(){
    public void dispose(){
    }
    public void inputChanged(    Viewer viewer,    Object oldInput,    Object newInput){
    }
    public Object[] getElements(    Object inputElement){
      if (inputElement instanceof Collection) {
        return ((Collection<?>)inputElement).toArray(new Object[0]);
      }
      return null;
    }
  }
);
  servicesViewer.setLabelProvider(new TreeLabelProvider(servicesViewer));
  configureViewer(servicesViewer);
  servicesViewer.getTable().addControlListener(new ControlListener(){
    public void controlResized(    ControlEvent e){
      resizeTable();
    }
    public void controlMoved(    ControlEvent e){
    }
  }
);
  addTableActions();
  setInput();
  resizeTable();
  return tableArea;
}
 

Example 13

From project gda-common-rcp, under directory /uk.ac.gda.common.rcp/src/uk/ac/gda/richbeans/components/selector/.

Source file: GridListEditor.java

  20 
vote

private void createContentProvider(){
  if (gridTable == null)   return;
  final Integer[] vals=new Integer[rows];
  for (int i=0; i < vals.length; i++)   vals[i]=i;
  gridTable.setContentProvider(new IStructuredContentProvider(){
    @Override public void dispose(){
    }
    @Override public void inputChanged(    Viewer viewer,    Object oldInput,    Object newInput){
    }
    @Override public Object[] getElements(    Object inputElement){
      return vals;
    }
  }
);
}
 

Example 14

From project radrails, under directory /plugins/org.radrails.server.ui/src/org/radrails/server/internal/ui/wizards/pages/.

Source file: WizardNewServerPage.java

  20 
vote

/** 
 * Opens a list dialog populated with all the Rails projects in the workspace. The name of the selected project is placed in the text field when the dialog is closed.
 */
protected void handleProjectSelectButtonPressed(){
  ListDialog dialog=new ListDialog(getShell());
  dialog.setContentProvider(new IStructuredContentProvider(){
    public void inputChanged(    Viewer viewer,    Object oldInput,    Object newInput){
    }
    public void dispose(){
    }
    public Object[] getElements(    Object inputElement){
      return ((IWorkspaceRoot)inputElement).getProjects();
    }
  }
);
  dialog.setLabelProvider(new DecoratingRubyLabelProvider(new AppearanceAwareLabelProvider()));
  IWorkspaceRoot wsroot=ResourcesPlugin.getWorkspace().getRoot();
  NewProjectBasedResourceWizard wizard=(NewProjectBasedResourceWizard)getWizard();
  dialog.setInitialSelections(new IProject[]{wizard.getProjectForName(getProjectName())});
  dialog.setInput(wsroot);
  dialog.setMessage("Choose a project:");
  dialog.setTitle("Project Selection");
  dialog.create();
  dialog.open();
  Object[] result=dialog.getResult();
  if (result != null) {
    IProject project=((IProject)result[0]);
    projectNameText.setText(project.getName());
  }
}
 

Example 15

From project scisoft-ui, under directory /uk.ac.diamond.sda.meta/src/uk/ac/diamond/sda/meta/views/.

Source file: MetadataTableView.java

  20 
vote

@Override public IStatus runInUIThread(IProgressMonitor monitor){
  if (table.getControl().isDisposed()) {
    logger.warn("The header table is disposed, cannot update table");
    return Status.CANCEL_STATUS;
  }
  table.setContentProvider(new IStructuredContentProvider(){
    @Override public void inputChanged(    Viewer viewer,    Object oldInput,    Object newInput){
    }
    @Override public void dispose(){
    }
    @Override public Object[] getElements(    Object inputElement){
      try {
        Collection<String> names=meta == null ? null : meta.getMetaNames();
        return names == null ? new Object[]{""} : names.toArray(new Object[names.size()]);
      }
 catch (      Exception e) {
        return new Object[]{""};
      }
    }
  }
);
  if (table.getControl().isDisposed())   return Status.CANCEL_STATUS;
  table.setInput(new String());
  return Status.OK_STATUS;
}
 

Example 16

From project zest, under directory /org.eclipse.zest.examples.cloudio/src/main/java/org/eclipse/zest/examples/cloudio/snippets/.

Source file: TagCloudViewerSnippet.java

  20 
vote

public static void main(String[] args){
  final Display display=new Display();
  final Shell shell=new Shell(display);
  TagCloud cloud=new TagCloud(shell,SWT.NONE);
  final TagCloudViewer viewer=new TagCloudViewer(cloud);
  viewer.setContentProvider(new IStructuredContentProvider(){
    @Override public void dispose(){
    }
    @Override public void inputChanged(    Viewer viewer,    Object oldInput,    Object newInput){
    }
    @Override public Object[] getElements(    Object inputElement){
      return ((List<?>)inputElement).toArray();
    }
  }
);
  viewer.setLabelProvider(new CustomLabelProvider(cloud.getFont()));
  viewer.addSelectionChangedListener(new ISelectionChangedListener(){
    @Override public void selectionChanged(    SelectionChangedEvent event){
      IStructuredSelection selection=(IStructuredSelection)viewer.getSelection();
      System.out.println("Selection: " + selection);
    }
  }
);
  List<String> data=new ArrayList<String>();
  data.add("Hello");
  data.add("World");
  data.add("Hello Cloudio");
  shell.setBounds(50,50,300,300);
  cloud.setBounds(0,0,shell.getBounds().width,shell.getBounds().height);
  viewer.setInput(data);
  viewer.setSelection(new StructuredSelection(Arrays.asList("Hello Cloudio")));
  shell.open();
  while (!shell.isDisposed()) {
    if (!display.readAndDispatch())     display.sleep();
  }
  display.dispose();
}
 

Example 17

From project Diver, under directory /ca.uvic.chisel.javasketch/src/ca/uvic/chisel/javasketch/ui/internal/presentation/commands/.

Source file: FocusInHandler.java

  19 
vote

@Override public Object execute(ExecutionEvent event) throws ExecutionException {
  IJavaSketchPresenter presenter=getPresenter(false);
  ITraceModel element=getSelectedTraceModel(getWorkbenchSelection());
  UMLSequenceViewer viewer=presenter.getSequenceChartViewer();
  if (viewer.isVisible(element)) {
    if (element instanceof IActivation) {
      viewer.setRootActivation(element);
      return null;
    }
  }
  LinkedList<Object> pathToRoot=new LinkedList<Object>();
  Object input=viewer.getInput();
  if (input == null)   return null;
  ISequenceContentExtension2 provider=(ISequenceContentExtension2)viewer.getContentProvider();
  Object[] roots=((IStructuredContentProvider)provider).getElements(input);
  if (roots.length <= 0)   return null;
  Object currentRoot=roots[0];
  Object currentParent=element;
  while (currentParent != null && !currentParent.equals(currentRoot)) {
    pathToRoot.addFirst(currentParent);
    Object call=provider.getCall(currentParent);
    if (call != null) {
      currentParent=provider.getOriginActivation(call);
    }
 else {
      currentParent=null;
    }
  }
  pathToRoot.addFirst(currentRoot);
  TimeTriggeredProgressMonitorDialog progress=new TimeTriggeredProgressMonitorDialog(viewer.getControl().getShell(),1000);
  try {
    progress.run(false,true,new ExpandToRootRunnable(viewer,pathToRoot,true));
  }
 catch (  InvocationTargetException ex) {
    SketchPlugin.getDefault().log(ex);
  }
catch (  InterruptedException e1) {
  }
  return null;
}
 

Example 18

From project Diver, under directory /org.eclipse.zest.custom.sequence/src/org/eclipse/zest/custom/uml/viewers/.

Source file: BreadCrumbViewer.java

  19 
vote

@Override public void refresh(){
  for (  Widget child : linksComposite.getChildren()) {
    child.dispose();
  }
  links.clear();
  Object[] elements=((IStructuredContentProvider)getContentProvider()).getElements(getInput());
  for (int i=0; i < elements.length - 1; i++) {
    BreadCrumbItem linkLabel=new BreadCrumbItem(linksComposite);
    linkLabel.setCursor(linkLabel.getDisplay().getSystemCursor(SWT.CURSOR_HAND));
    linkLabel.addListener(SWT.KeyDown,labelSelectionListener);
    linkLabel.addListener(SWT.MouseUp,labelSelectionListener);
    linkLabel.setBackground(linksComposite.getBackground());
    update(linkLabel,elements[i]);
    links.add(linkLabel);
    Label arrow=new Label(linksComposite,SWT.NONE);
    arrow.setText("->");
    arrow.setBackground(control.getBackground());
  }
  if (elements.length > 0) {
    BreadCrumbItem linkLabel=new BreadCrumbItem(linksComposite);
    linkLabel.setCursor(linkLabel.getDisplay().getSystemCursor(SWT.CURSOR_HAND));
    linkLabel.addListener(SWT.KeyDown,labelSelectionListener);
    linkLabel.addListener(SWT.MouseUp,labelSelectionListener);
    linkLabel.setBackground(control.getBackground());
    update(linkLabel,elements[elements.length - 1]);
    links.add(linkLabel);
  }
  linksComposite.layout(true,true);
  control.layout(true,true);
}