org.eclipse.pde.ds.ui_1.0.100.v20111213-1754

&& 
          (!table.isSelected(table.getItems().length - 1)));
      }
      
      private void handleRemove()
      {
        IStructuredSelection ssel = (IStructuredSelection)fPropertiesTable
          .getSelection();
        if (ssel.size() > 0)
        {
          Iterator iter = ssel.iterator();
          while (iter.hasNext())
          {
            Object object = iter.next();
            if ((object instanceof IDSProperties)) {
              getDSModel().getDSComponent().removePropertiesElement(
                (IDSProperties)object);
            }
            if ((object instanceof IDSProperty)) {
              getDSModel().getDSComponent().removePropertyElement(
                (IDSProperty)object);
            }
          }
        }
      }
      
      private void handleAddProperties()
      {
        doOpenSelectionDialogProperties();
      }
      
      private void doOpenSelectionDialogProperties()
      {
        IProject project = getProject();
        ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(
          Activator.getActiveWorkbenchShell(), 
          new WorkbenchLabelProvider(), new WorkbenchContentProvider());
        dialog.setInput(project.getWorkspace());
        dialog.addFilter(new ViewerFilter()
        {
          private final IProject val$project;
          
          public boolean select(Viewer viewer, Object parentElement, Object element)
          {
            if ((element instanceof IProject)) {
              return ((IProject)element).equals(val$project);
            }
            return true;
          }
        });
        dialog.setAllowMultiple(false);
        dialog.setTitle(Messages.DSPropertiesDetails_dialogTitle);
        dialog.setMessage(Messages.DSPropertiesDetails_dialogMessage);
        dialog.setValidator(new ISelectionStatusValidator()
        {
          public IStatus validate(Object[] selection)
          {
            if ((selection != null) && (selection.length > 0) && 
              ((selection[0] instanceof IFile))) {
              return new Status(0, "org.eclipse.pde.ds.ui", 
                0, "", null);
            }
            return new Status(4, "org.eclipse.pde.ds.ui", 
              4, "", null);
          }
        });
        if (dialog.open() == 0)
        {
          IResource res = (IResource)dialog.getFirstResult();
          IPath path = res.getProjectRelativePath();
          if ((res instanceof IContainer)) {
            path = path.addTrailingSeparator();
          }
          String value = path.toString();
          addProperties(value);
        }
      }
      
      private void addProperties(String entry)
      {
        IDSDocumentFactory factory = getDSModel().getFactory();
        IDSComponent component = getDSModel().getDSComponent();
        
        IDSProperties properties = factory.createProperties();
        
        properties.setEntry(entry);
        
        component.addPropertiesElement(properties);
      }
      
      private IDSProperty createPropertyElement()
      {
        IDSDocumentFactory factory = getDSModel().getFactory();
        
        IDSProperty property = factory.createProperty();
        
        return property;
      }
      
      public void modelChanged(IModelChangedEvent e)
      {
        if (e.getChangeType() == 99)
        {
          markStale();
        }
        else if (e.getChangeType() == 2)
        {
          Object[] objects = e.getChangedObjects();
          for (int i = 0; i < objects.length; i++)
          {
            Table table = fPropertiesTable.getTable();
            if ((objects[i] instanceof IDSProperties))
            {
              int index = table.getSelectionIndex();
              fPropertiesTable.remove(objects[i]);
              if (canSelect()) {
                table.setSelection(index < table.getItemCount() ? index : 
                  table.getItemCount() - 1);
              }
            }
            if ((objects[i] instanceof IDSProperty))
            {
              int index = table.getSelectionIndex();
              fPropertiesTable.remove(objects[i]);
              if (canSelect()) {
                table.setSelection(index < table.getItemCount() ? index : 
                  table.getItemCount() - 1);
              }
            }
          }
          updateButtons();
        }
        else if (e.getChangeType() == 1)
        {
          Object[] objects = e.getChangedObjects();
          if (objects.length > 0)
          {
            fPropertiesTable.refresh();
            fPropertiesTable.setSelection(new StructuredSelection(
              objects[(objects.length - 1)]));
          }
          updateButtons();
        }
        else
        {
          fPropertiesTable.refresh();
          updateButtons();
        }
        fPropertiesTable.getTable().getDisplay().asyncExec(new Runnable()
        {
          public void run()
          {
            if (!fPropertiesTable.getTable().isDisposed()) {
              DSPropertiesSection.this.updateTitle();
            }
          }
        });
      }
      
      private DSInputContext getDSContext()
      {
        InputContextManager manager = getPage().getPDEEditor()
          .getContextManager();
        return (DSInputContext)manager.findContext("ds-context");
      }
      
      private IDSModel getDSModel()
      {
        DSInputContext context = getDSContext();
        return context == null ? null : (IDSModel)context.getModel();
      }
      
      public boolean doGlobalAction(String actionId)
      {
        if (!isEditable()) {
          return false;
        }
        if (actionId.equals(ActionFactory.DELETE.getId()))
        {
          handleRemove();
          return true;
        }
        return false;
      }
      
      protected void selectionChanged(IStructuredSelection selection)
      {
        getPage().getPDEEditor().setSelection(selection);
        updateButtons();
      }
    }

/* Location:
 * Qualified Name:     org.eclipse.pde.internal.ds.ui.editor.sections.DSPropertiesSection
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.pde.internal.ds.ui.editor.sections;

import org.eclipse.jface.action.Action;

class DSProvideSection$1
  extends Action
{
  final DSProvideSection this$0;
  
  DSProvideSection$1(DSProvideSection paramDSProvideSection, String $anonymous0)
  {
    super($anonymous0);this$0 = paramDSProvideSection;
  }
  
  public void run()
  {
    DSProvideSection.access$0(this$0);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.pde.internal.ds.ui.editor.sections.DSProvideSection.1
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.pde.internal.ds.ui.editor.sections;

import org.eclipse.jface.action.Action;

class DSProvideSection$2
  extends Action
{
  final DSProvideSection this$0;
  
  DSProvideSection$2(DSProvideSection paramDSProvideSection, String $anonymous0)
  {
    super($anonymous0);this$0 = paramDSProvideSection;
  }
  
  public void run()
  {
    DSProvideSection.access$1(this$0);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.pde.internal.ds.ui.editor.sections.DSProvideSection.2
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.pde.internal.ds.ui.editor.sections;

import org.eclipse.jface.action.Action;

class DSProvideSection$3
  extends Action
{
  final DSProvideSection this$0;
  
  DSProvideSection$3(DSProvideSection paramDSProvideSection, String $anonymous0)
  {
    super($anonymous0);this$0 = paramDSProvideSection;
  }
  
  public void run()
  {
    DSProvideSection.access$1(this$0);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.pde.internal.ds.ui.editor.sections.DSProvideSection.3
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.pde.internal.ds.ui.editor.sections;

import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.pde.internal.ds.core.IDSComponent;
import org.eclipse.pde.internal.ds.core.IDSModel;
import org.eclipse.pde.internal.ds.core.IDSService;

class DSProvideSection$ContentProvider
  implements IStructuredContentProvider
{
  final DSProvideSection this$0;
  
  DSProvideSection$ContentProvider(DSProvideSection paramDSProvideSection)
  {
    this$0 = paramDSProvideSection;
  }
  
  public Object[] getElements(Object inputElement)
  {
    if ((inputElement instanceof IDSModel))
    {
      IDSModel model = (IDSModel)inputElement;
      IDSComponent component = model.getDSComponent();
      if (component != null)
      {
        IDSService service = component.getService();
        if (service != null) {
          return service.getProvidedServices();
        }
      }
    }
    return new Object[0];
  }
  
  public void dispose() {}
  
  public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {}
}

/* Location:
 * Qualified Name:     org.eclipse.pde.internal.ds.ui.editor.sections.DSProvideSection.ContentProvider
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.pde.internal.ds.ui.editor.sections;

import java.util.Iterator;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.search.SearchEngine;
import org.eclipse.jdt.ui.JavaUI;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.viewers.DoubleClickEvent;
import org.eclipse.jface.viewers.IDoubleClickListener;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerComparator;
import org.eclipse.osgi.util.NLS;
import org.eclipse.pde.core.IModelChangedEvent;
import org.eclipse.pde.internal.ds.core.IDSComponent;
import org.eclipse.pde.internal.ds.core.IDSDocumentFactory;
import org.eclipse.pde.internal.ds.core.IDSModel;
import org.eclipse.pde.internal.ds.core.IDSProvide;
import org.eclipse.pde.internal.ds.core.IDSService;
import org.eclipse.pde.internal.ds.ui.Activator;
import org.eclipse.pde.internal.ds.ui.Messages;
import org.eclipse.pde.internal.ds.ui.editor.DSInputContext;
import org.eclipse.pde.internal.ds.ui.editor.DSLabelProvider;
import org.eclipse.pde.internal.ds.ui.editor.DSTypeSelectionExtension;
import org.eclipse.pde.internal.ds.ui.editor.FormLayoutFactory;
import org.eclipse.pde.internal.ds.ui.editor.dialogs.DSEditProvideDialog;
import org.eclipse.pde.internal.ui.editor.PDEFormEditor;
import org.eclipse.pde.internal.ui.editor.PDEFormPage;
import org.eclipse.pde.internal.ui.editor.TableSection;
import org.eclipse.pde.internal.ui.editor.context.InputContextManager;
import org.eclipse.pde.internal.ui.parts.EditableTablePart;
import org.eclipse.pde.internal.ui.parts.TablePart;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.actions.ActionFactory;
import org.eclipse.ui.dialogs.SelectionDialog;
import org.eclipse.ui.forms.editor.FormEditor;
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.eclipse.ui.forms.widgets.Section;

public class DSProvideSection
  extends TableSection
  implements IDoubleClickListener
{
  private TableViewer fProvidesTable;
  private Action fRemoveAction;
  private Action fAddAction;
  private Action fEditAction;
  
  class ContentProvider
    implements IStructuredContentProvider
  {
    ContentProvider() {}
    
    public Object[] getElements(Object inputElement)
    {
      if ((inputElement instanceof IDSModel))
      {
        IDSModel model = (IDSModel)inputElement;
        IDSComponent component = model.getDSComponent();
        if (component != null)
        {
          IDSService service = component.getService();
          if (service != null) {
            return service.getProvidedServices();
          }
        }
      }
      return new Object[0];
    }
    
    public void dispose() {}
    
    public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {}
  }
  
  public DSProvideSection(PDEFormPage page, Composite parent)
  {
    super(page, parent, 130, new String[] {Messages.DSProvideSection_add, Messages.DSProvideSection_remove, Messages.DSProvideSection_edit });
    createClient(getSection(), page.getEditor().getToolkit());
  }
  
  protected void createClient(Section section, FormToolkit toolkit)
  {
    section.setDescription(Messages.DSProvideSection_description);
    section.setExpanded(true);
    section.setLayout(FormLayoutFactory.createClearGridLayout(false, 1));
    
    GridData data = new GridData(1808);
    grabExcessVerticalSpace = true;
    section.setLayoutData(data);
    
    Composite container = createClientContainer(section, 2, toolkit);
    EditableTablePart tablePart = getTablePart();
    tablePart.setEditable(isEditable());
    
    createViewerPartControl(container, 65538, 2, 
      toolkit);
    fProvidesTable = tablePart.getTableViewer();
    fProvidesTable.setContentProvider(new ContentProvider());
    fProvidesTable.setLabelProvider(new DSLabelProvider());
    fProvidesTable.setComparator(new ViewerComparator());
    fProvidesTable.addDoubleClickListener(this);
    
    makeActions();
    
    IDSModel model = getDSModel();
    if (model != null)
    {
      fProvidesTable.setInput(model);
      model.addModelChangedListener(this);
    }
    toolkit.paintBordersFor(container);
    section.setClient(container);
    updateTitle();
  }
  
  public void dispose()
  {
    IDSModel model = getDSModel();
    if (model != null) {
      model.removeModelChangedListener(this);
    }
  }
  
  public void refresh()
  {
    fProvidesTable.refresh();
    updateButtons();
    updateTitle();
  }
  
  protected void buttonSelected(int index)
  {
    switch (index)
    {
    case 0: 
      handleAdd();
      break;
    case 1: 
      handleRemove();
      break;
    case 2: 
      handleEdit();
    }
  }
  
  private void handleEdit()
  {
    ISelection selection = fProvidesTable.getSelection();
    if (selection != null)
    {
      int selectionIndex = fProvidesTable.getTable().getSelectionIndex();
      if (selectionIndex != -1)
      {
        DSEditProvideDialog dialog = new DSEditProvideDialog(
          Activator.getActiveWorkbenchShell(), 
          (IDSProvide)fProvidesTable.getElementAt(selectionIndex), this);
        dialog.create();
        dialog.getShell().setSize(500, 200);
        dialog.open();
      }
    }
  }
  
  private void makeActions()
  {
    fAddAction = new Action(Messages.DSProvideSection_add)
    {
      public void run()
      {
        DSProvideSection.this.handleAdd();
      }
    };
    fAddAction.setEnabled(isEditable());
    
    fRemoveAction = new Action(Messages.DSProvideSection_remove)
    {
      public void run()
      {
        DSProvideSection.this.handleRemove();
      }
    };
    fRemoveAction.setEnabled(isEditable());
    
    fEditAction = new Action(Messages.DSProvideSection_edit)
    {
      public void run()
      {
        DSProvideSection.this.handleRemove();
      }
    };
    fEditAction.setEnabled(isEditable());
  }
  
  private void updateButtons()
  {
    Table table = fProvidesTable.getTable();
    TablePart tablePart = getTablePart();
    tablePart.setButtonEnabled(0, isEditable());
    tablePart.setButtonEnabled(1, (isEditable()) && 
      (table.getSelection().length > 0));
    tablePart.setButtonEnabled(2, (isEditable()) && 
      (table.getSelection().length == 1));
  }
  
  private void handleRemove()
  {
    IStructuredSelection ssel = (IStructuredSelection)fProvidesTable
      .getSelection();
    if (ssel.size() > 0)
    {
      Iterator iter = ssel.iterator();
      IDSService service = getDSModel().getDSComponent().getService();
      while (iter.hasNext())
      {
        Object object = iter.next();
        if ((object instanceof IDSProvide)) {
          service.removeProvidedService((IDSProvide)object);
        }
      }
      if (service.getProvidedServices().length == 0) {
        getDSModel().getDSComponent().removeService(service);
      }
    }
  }
  
  private void handleAdd()
  {
    doOpenSelectionDialog(512);
  }
  
  private void doOpenSelectionDialog(int scopeType)
  {
    try
    {
      String filter = "";
      filter = filter.substring(filter.lastIndexOf(".") + 1);
      SelectionDialog dialog = JavaUI.createTypeDialog(
        Activator.getActiveWorkbenchShell(), PlatformUI.getWorkbench()
        .getProgressService(), SearchEngine.createWorkspaceScope(), 
        scopeType, true, filter, new DSTypeSelectionExtension(
        getDSModel()));
      dialog.setTitle(Messages.DSProvideDetails_selectType);
      if (dialog.open() == 0)
      {
        Object[] result = dialog.getResult();
        for (int i = 0; i < result.length; i++)
        {
          IType type = (IType)result[i];
          String fullyQualifiedName = type.getFullyQualifiedName('$');
          addProvide(fullyQualifiedName);
        }
      }
    }
    catch (CoreException localCoreException) {}
  }
  
  private void addProvide(String fullyQualifiedName)
  {
    IDSDocumentFactory factory = getDSModel().getFactory();
    IDSComponent component = getDSModel().getDSComponent();
    
    IDSService service = component.getService();
    if (service == null)
    {
      service = factory.createService();
      component.setService(service);
    }
    IDSProvide provide = factory.createProvide();
    
    provide.setInterface(fullyQualifiedName);
    
    service.addProvidedService(provide);
  }
  
  public void modelChanged(IModelChangedEvent e)
  {
    if (e.getChangeType() == 99)
    {
      markStale();
    }
    else if (e.getChangeType() == 2)
    {
      Object[] objects = e.getChangedObjects();
      for (int i = 0; i < objects.length; i++)
      {
        Table table = fProvidesTable.getTable();
        if ((objects[i] instanceof IDSProvide))
        {
          int index = table.getSelectionIndex();
          fProvidesTable.remove(objects[i]);
          if (canSelect()) {
            table.setSelection(index < table.getItemCount() ? index : 
              table.getItemCount() - 1);
          }
        }
      }
      updateButtons();
      updateTitle();
    }
    else if (e.getChangeType() == 1)
    {
      Object[] objects = e.getChangedObjects();
      if (objects.length > 0)
      {
        fProvidesTable.refresh();
        fProvidesTable.setSelection(new StructuredSelection(
          objects[(objects.length - 1)]));
      }
      updateButtons();
      updateTitle();
    }
    else
    {
      fProvidesTable.refresh();
      updateButtons();
    }
  }
  
  private DSInputContext getDSContext()
  {
    InputContextManager manager = getPage().getPDEEditor()
      .getContextManager();
    return (DSInputContext)manager.findContext("ds-context");
  }
  
  private IDSModel getDSModel()
  {
    DSInputContext context = getDSContext();
    return context == null ? null : (IDSModel)context.getModel();
  }
  
  public boolean doGlobalAction(String actionId)
  {
    if (!isEditable()) {
      return false;
    }
    if (actionId.equals(ActionFactory.DELETE.getId()))
    {
      handleRemove();
      return true;
    }
    return false;
  }
  
  protected void selectionChanged(IStructuredSelection selection)
  {
    getPage().getPDEEditor().setSelection(selection);
    updateButtons();
  }
  
  private void updateTitle()
  {
    int itemCount = fProvidesTable.getTable().getItemCount();
    getSection().setText(
      NLS.bind(Messages.DSProvideSection_title, 
      new Integer(
      itemCount)));
  }
  
  public void doubleClick(DoubleClickEvent event)
  {
    IDSProvide provide = (IDSProvide)((IStructuredSelection)fProvidesTable
      .getSelection()).getFirstElement();
    String value = provide.getInterface();
    IProject project = getProject();
    try
    {
      if ((project != null) && (project.hasNature("org.eclipse.jdt.core.javanature")))
      {
        IJavaProject javaProject = JavaCore.create(project);
        IJavaElement element = javaProject.findType(value.replace('$', 
          '.'));
        if (element != null) {
          JavaUI.openInEditor(element);
        }
      }
    }
    catch (PartInitException e)
    {
      Activator.logException(e);
    }
    catch (CoreException e)
    {
      Activator.logException(e);
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.pde.internal.ds.ui.editor.sections.DSProvideSection
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.pde.internal.ds.ui.editor.sections;

import org.eclipse.jface.action.Action;

class DSReferenceSection$1
  extends Action
{
  final DSReferenceSection this$0;
  
  DSReferenceSection$1(DSReferenceSection paramDSReferenceSection, String $anonymous0)
  {
    super($anonymous0);this$0 = paramDSReferenceSection;
  }
  
  public void run()
  {
    DSReferenceSection.access$0(this$0);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.pde.internal.ds.ui.editor.sections.DSReferenceSection.1
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.pde.internal.ds.ui.editor.sections;

import org.eclipse.jface.action.Action;

class DSReferenceSection$2
  extends Action
{
  final DSReferenceSection this$0;
  
  DSReferenceSection$2(DSReferenceSection paramDSReferenceSection, String $anonymous0)
  {
    super($anonymous0);this$0 = paramDSReferenceSection;
  }
  
  public void run()
  {
    DSReferenceSection.access$1(this$0);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.pde.internal.ds.ui.editor.sections.DSReferenceSection.2
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.pde.internal.ds.ui.editor.sections;

import org.eclipse.jface.action.Action;

class DSReferenceSection$3
  extends Action
{
  final DSReferenceSection this$0;
  
  DSReferenceSection$3(DSReferenceSection paramDSReferenceSection, String $anonymous0)
  {
    super($anonymous0);this$0 = paramDSReferenceSection;
  }
  
  public void run()
  {
    DSReferenceSection.access$2(this$0);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.pde.internal.ds.ui.editor.sections.DSReferenceSection.3
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.pde.internal.ds.ui.editor.sections;

import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.pde.internal.ds.core.IDSComponent;
import org.eclipse.pde.internal.ds.core.IDSModel;

class DSReferenceSection$ContentProvider
  implements IStructuredContentProvider
{
  final DSReferenceSection this$0;
  
  DSReferenceSection$ContentProvider(DSReferenceSection paramDSReferenceSection)
  {
    this$0 = paramDSReferenceSection;
  }
  
  public Object[] getElements(Object inputElement)
  {
    if ((inputElement instanceof IDSModel))
    {
      IDSModel model = (IDSModel)inputElement;
      IDSComponent component = model.getDSComponent();
      if (component != null) {
        return component.getReferences();
      }
    }
    return new Object[0];
  }
  
  public void dispose() {}
  
  public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {}
}

/* Location:
 * Qualified Name:     org.eclipse.pde.internal.ds.ui.editor.sections.DSReferenceSection.ContentProvider
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.pde.internal.ds.ui.editor.sections;

import org.eclipse.jface.viewers.StyledCellLabelProvider;
import org.eclipse.jface.viewers.StyledString;
import org.eclipse.jface.viewers.ViewerCell;
import org.eclipse.pde.internal.ds.core.IDSReference;
import org.eclipse.pde.internal.ds.ui.editor.DSLabelProvider;

class DSReferenceSection$ReferenceLabelProvider
  extends StyledCellLabelProvider
{
  private DSLabelProvider labelProvider;
  final DSReferenceSection this$0;
  
  DSReferenceSection$ReferenceLabelProvider(DSReferenceSection paramDSReferenceSection)
  {
    this$0 = paramDSReferenceSection;
    
    labelProvider = new DSLabelProvider();
  }
  
  public void update(ViewerCell cell)
  {
    Object element = cell.getElement();
    IDSReference reference = (IDSReference)element;
    String name = reference.getReferenceName();
    if ((name == null) || (name.length() == 0)) {
      name = reference.getReferenceInterface();
    }
    if (name == null) {
      name = "";
    }
    StyledString styledString = new StyledString(name);
    String bind = reference.getReferenceBind();
    String unbind = reference.getReferenceUnbind();
    bind = (bind == null) || (bind.length() == 0) ? "<none>" : bind;
    unbind = (unbind == null) || (unbind.length() == 0) ? "<none>" : unbind;
    styledString
      .append(
      " [" + bind + "," + unbind + "]", StyledString.DECORATIONS_STYLER);
    
    String target = reference.getReferenceTarget();
    if (target != null) {
      styledString.append(" " + target, 
        StyledString.QUALIFIER_STYLER);
    }
    cell.setText(styledString.toString());
    cell.setStyleRanges(styledString.getStyleRanges());
    cell.setImage(labelProvider.getImage(reference));
    super.update(cell);
  }
  
  public void dispose()
  {
    super.dispose();
    labelProvider.dispose();
  }
}

/* Location:
 * Qualified Name:     org.eclipse.pde.internal.ds.ui.editor.sections.DSReferenceSection.ReferenceLabelProvider
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.pde.internal.ds.ui.editor.sections;

import java.util.Iterator;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.search.SearchEngine;
import org.eclipse.jdt.ui.JavaUI;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.viewers.DoubleClickEvent;
import org.eclipse.jface.viewers.IDoubleClickListener;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.viewers.StyledCellLabelProvider;
import org.eclipse.jface.viewers.StyledString;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerCell;
import org.eclipse.osgi.util.NLS;
import org.eclipse.pde.core.IModelChangedEvent;
import org.eclipse.pde.internal.core.text.IDocumentElementNode;
import org.eclipse.pde.internal.ds.core.IDSComponent;
import org.eclipse.pde.internal.ds.core.IDSDocumentFactory;
import org.eclipse.pde.internal.ds.core.IDSModel;
import org.eclipse.pde.internal.ds.core.IDSReference;
import org.eclipse.pde.internal.ds.ui.Activator;
import org.eclipse.pde.internal.ds.ui.Messages;
import org.eclipse.pde.internal.ds.ui.editor.DSInputContext;
import org.eclipse.pde.internal.ds.ui.editor.DSLabelProvider;
import org.eclipse.pde.internal.ds.ui.editor.FormLayoutFactory;
import org.eclipse.pde.internal.ds.ui.editor.dialogs.DSEditReferenceDialog;
import org.eclipse.pde.internal.ui.editor.PDEFormEditor;
import org.eclipse.pde.internal.ui.editor.PDEFormPage;
import org.eclipse.pde.internal.ui.editor.TableSection;
import org.eclipse.pde.internal.ui.editor.context.InputContextManager;
import org.eclipse.pde.internal.ui.parts.EditableTablePart;
import org.eclipse.pde.internal.ui.parts.TablePart;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.actions.ActionFactory;
import org.eclipse.ui.dialogs.SelectionDialog;
import org.eclipse.ui.forms.editor.FormEditor;
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.eclipse.ui.forms.widgets.Section;

public class DSReferenceSection
  extends TableSection
  implements IDoubleClickListener
{
  private TableViewer fReferencesTable;
  private Action fRemoveAction;
  private Action fAddAction;
  private Action fEditAction;
  
  class ReferenceLabelProvider
    extends StyledCellLabelProvider
  {
    private DSLabelProvider labelProvider = new DSLabelProvider();
    
    ReferenceLabelProvider() {}
    
    public void update(ViewerCell cell)
    {
      Object element = cell.getElement();
      IDSReference reference = (IDSReference)element;
      String name = reference.getReferenceName();
      if ((name == null) || (name.length() == 0)) {
        name = reference.getReferenceInterface();
      }
      if (name == null) {
        name = "";
      }
      StyledString styledString = new StyledString(name);
      String bind = reference.getReferenceBind();
      String unbind = reference.getReferenceUnbind();
      bind = (bind == null) || (bind.length() == 0) ? "<none>" : bind;
      unbind = (unbind == null) || (unbind.length() == 0) ? "<none>" : unbind;
      styledString
        .append(
        " [" + bind + "," + unbind + "]", StyledString.DECORATIONS_STYLER);
      
      String target = reference.getReferenceTarget();
      if (target != null) {
        styledString.append(" " + target, 
          StyledString.QUALIFIER_STYLER);
      }
      cell.setText(styledString.toString());
      cell.setStyleRanges(styledString.getStyleRanges());
      cell.setImage(labelProvider.getImage(reference));
      super.update(cell);
    }
    
    public void dispose()
    {
      super.dispose();
      labelProvider.dispose();
    }
  }
  
  class ContentProvider
    implements IStructuredContentProvider
  {
    ContentProvider() {}
    
    public Object[] getElements(Object inputElement)
    {
      if ((inputElement instanceof IDSModel))
      {
        IDSModel model = (IDSModel)inputElement;
        IDSComponent component = model.getDSComponent();
        if (component != null) {
          return component.getReferences();
        }
      }
      return new Object[0];
    }
    
    public void dispose() {}
    
    public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {}
  }
  
  public DSReferenceSection(PDEFormPage page, Composite parent)
  {
    super(page, parent, 130, new String[] {Messages.DSReferenceSection_add, Messages.DSReferenceSection_remove, Messages.DSReferenceSection_edit, Messages.DSReferenceSection_up, Messages.DSReferenceSection_down });
    createClient(getSection(), page.getEditor().getToolkit());
  }
  
  protected void createClient(Section section, FormToolkit toolkit)
  {
    section.setDescription(Messages.DSReferenceSection_description);
    section.setExpanded(true);
    section.setLayout(FormLayoutFactory.createClearGridLayout(false, 1));
    
    GridData data = new GridData(1808);
    grabExcessVerticalSpace = true;
    section.setLayoutData(data);
    
    Composite container = createClientContainer(section, 2, toolkit);
    EditableTablePart tablePart = getTablePart();
    tablePart.setEditable(isEditable());
    
    createViewerPartControl(container, 65538, 2, 
      toolkit);
    fReferencesTable = tablePart.getTableViewer();
    
    fReferencesTable.setContentProvider(new ContentProvider());
    fReferencesTable.setLabelProvider(new ReferenceLabelProvider());
    fReferencesTable.addDoubleClickListener(this);
    
    makeActions();
    
    IDSModel model = getDSModel();
    if (model != null)
    {
      fReferencesTable.setInput(model);
      model.addModelChangedListener(this);
    }
    toolkit.paintBordersFor(container);
    section.setClient(container);
    updateTitle();
  }
  
  public void dispose()
  {
    IDSModel model = getDSModel();
    if (model != null) {
      model.removeModelChangedListener(this);
    }
  }
  
  public void refresh()
  {
    fReferencesTable.refresh();
    updateButtons();
    updateTitle();
  }
  
  protected void buttonSelected(int index)
  {
    switch (index)
    {
    case 0: 
      handleAdd();
      break;
    case 1: 
      handleRemove();
      break;
    case 2: 
      handleEdit();
      break;
    case 3: 
      handleMove(true);
      break;
    case 4: 
      handleMove(false);
    }
  }
  
  private void handleMove(boolean moveUp)
  {
    ISelection selection = fReferencesTable.getSelection();
    if (selection != null)
    {
      Object[] array = ((IStructuredSelection)selection).toArray();
      if (moveUp) {
        moveUp(array);
      } else {
        moveDown(array);
      }
    }
  }
  
  private void moveDown(Object[] array)
  {
    for (int i = array.length - 1; i >= 0; i--)
    {
      Object object = array[i];
      if (object != null) {
        if ((object instanceof IDocumentElementNode)) {
          getDSModel().getDSComponent().moveChildNode(
            (IDocumentElementNode)object, 1, true);
        }
      }
    }
  }
  
  private void moveUp(Object[] array)
  {
    for (int i = 0; i < array.length; i++)
    {
      Object object = array[i];
      if (object != null) {
        if ((object instanceof IDocumentElementNode)) {
          getDSModel().getDSComponent().moveChildNode(
            (IDocumentElementNode)object, -1, true);
        }
      }
    }
  }
  
  private void handleEdit()
  {
    ISelection selection = fReferencesTable.getSelection();
    if (selection != null)
    {
      int selectionIndex = fReferencesTable.getTable()
        .getSelectionIndex();
      if (selectionIndex != -1)
      {
        DSEditReferenceDialog dialog = new DSEditReferenceDialog(
          Activator.getActiveWorkbenchShell(), 
          (IDSReference)fReferencesTable
          .getElementAt(selectionIndex), this);
        dialog.create();
        dialog.getShell().setSize(500, 400);
        dialog.open();
      }
    }
  }
  
  private void makeActions()
  {
    fAddAction = new Action(Messages.DSReferenceSection_add)
    {
      public void run()
      {
        DSReferenceSection.this.handleAdd();
      }
    };
    fAddAction.setEnabled(isEditable());
    
    fRemoveAction = new Action(Messages.DSReferenceSection_remove)
    {
      public void run()
      {
        DSReferenceSection.this.handleRemove();
      }
    };
    fRemoveAction.setEnabled(isEditable());
    
    fEditAction = new Action(Messages.DSReferenceSection_edit)
    {
      public void run()
      {
        DSReferenceSection.this.handleEdit();
      }
    };
    fEditAction.setEnabled(isEditable());
  }
  
  private void updateButtons()
  {
    Table table = fReferencesTable.getTable();
    TablePart tablePart = getTablePart();
    tablePart.setButtonEnabled(0, isEditable());
    int length = table.getSelection().length;
    tablePart.setButtonEnabled(1, (isEditable()) && (length > 0));
    tablePart.setButtonEnabled(2, (isEditable()) && (length > 0));
    
    tablePart.setButtonEnabled(3, (isEditable()) && 
      (table.getSelection().length > 0) && (!table.isSelected(0)));
    tablePart.setButtonEnabled(4, (isEditable()) && 
      (table.getSelection().length > 0) && 
      (!table.isSelected(table.getItems().length - 1)));
  }
  
  private void handleRemove()
  {
    IStructuredSelection ssel = (IStructuredSelection)fReferencesTable
      .getSelection();
    if (ssel.size() > 0)
    {
      Iterator iter = ssel.iterator();
      while (iter.hasNext())
      {
        Object object = iter.next();
        if ((object instanceof IDSReference)) {
          getDSModel().getDSComponent().removeReference(
            (IDSReference)object);
        }
      }
    }
  }
  
  private void handleAdd()
  {
    doOpenSelectionDialog(512);
  }
  
  private void doOpenSelectionDialog(int scopeType)
  {
    try
    {
      String filter = "";
      filter = filter.substring(filter.lastIndexOf(".") + 1);
      SelectionDialog dialog = JavaUI.createTypeDialog(
        Activator.getActiveWorkbenchShell(), PlatformUI.getWorkbench()
        .getProgressService(), SearchEngine.createWorkspaceScope(), 
        scopeType, true, filter);
      dialog.setTitle(Messages.DSReferenceDetails_selectType);
      if (dialog.open() == 0)
      {
        Object[] result = dialog.getResult();
        for (int i = 0; i < result.length; i++)
        {
          IType type = (IType)result[i];
          String fullyQualifiedName = type.getFullyQualifiedName('$');
          addReference(fullyQualifiedName);
        }
      }
    }
    catch (CoreException localCoreException) {}
  }
  
  private void addReference(String fullyQualifiedName)
  {
    IDSReference reference = getDSModel().getFactory().createReference();
    
    reference.setReferenceInterface(fullyQualifiedName);
    
    int index = fullyQualifiedName.lastIndexOf(".");
    if (index != -1) {
      fullyQualifiedName = fullyQualifiedName.substring(index + 1);
    }
    reference.setReferenceName(fullyQualifiedName);
    
    getDSModel().getDSComponent().addReference(reference);
  }
  
  public void modelChanged(IModelChangedEvent e)
  {
    if (e.getChangeType() == 99)
    {
      markStale();
    }
    else if (e.getChangeType() == 2)
    {
      Object[] objects = e.getChangedObjects();
      for (int i = 0; i < objects.length; i++)
      {
        Table table = fReferencesTable.getTable();
        if ((objects[i] instanceof IDSReference))
        {
          int index = table.getSelectionIndex();
          fReferencesTable.remove(objects[i]);
          if (canSelect()) {
            table.setSelection(index < table.getItemCount() ? index : 
              table.getItemCount() - 1);
          }
        }
      }
      updateButtons();
      updateTitle();
    }
    else if (e.getChangeType() == 1)
    {
      Object[] objects = e.getChangedObjects();
      if (objects.length > 0)
      {
        fReferencesTable.refresh();
        fReferencesTable.setSelection(new StructuredSelection(
          objects[(objects.length - 1)]));
      }
      updateButtons();
      updateTitle();
    }
    else
    {
      fReferencesTable.refresh();
      updateButtons();
    }
  }
  
  private DSInputContext getDSContext()
  {
    InputContextManager manager = getPage().getPDEEditor()
      .getContextManager();
    return (DSInputContext)manager.findContext("ds-context");
  }
  
  private IDSModel getDSModel()
  {
    DSInputContext context = getDSContext();
    return context == null ? null : (IDSModel)context.getModel();
  }
  
  public boolean doGlobalAction(String actionId)
  {
    if (!isEditable()) {
      return false;
    }
    if (actionId.equals(ActionFactory.DELETE.getId()))
    {
      handleRemove();
      return true;
    }
    return false;
  }
  
  protected void selectionChanged(IStructuredSelection selection)
  {
    getPage().getPDEEditor().setSelection(selection);
    updateButtons();
  }
  
  private void updateTitle()
  {
    int itemCount = fReferencesTable.getTable().getItemCount();
    getSection().setText(
      NLS.bind(Messages.DSReferenceSection_title, new Integer(
      itemCount)));
  }
  
  public void doubleClick(DoubleClickEvent event)
  {
    IDSReference reference = (IDSReference)((IStructuredSelection)fReferencesTable
      .getSelection()).getFirstElement();
    String value = reference.getReferenceInterface();
    IProject project = getProject();
    try
    {
      if ((project != null) && (project.hasNature("org.eclipse.jdt.core.javanature")))
      {
        IJava
1 2 3 4 5 6 7 8

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2017. Infinite Loop Ltd