org.eclipse.emf.edit.ui_2.7.0.v20120130-0943

g.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.TreeItem;

public class AdapterFactoryTreeEditor
  extends ExtendedTreeEditor
{
  protected AdapterFactory adapterFactory;
  protected TreeItem currentTreeItem;
  
  public AdapterFactoryTreeEditor(Tree tree, AdapterFactory adapterFactory)
  {
    super(tree);
    this.adapterFactory = adapterFactory;
  }
  
  public AdapterFactory getAdapterFactory()
  {
    return adapterFactory;
  }
  
  public void setAdapterFactory(AdapterFactory adapterFactory)
  {
    this.adapterFactory = adapterFactory;
  }
  
  protected void editItem(TreeItem treeItem)
  {
    final Object object = treeItem.getData();
    final IUpdateableItemText updateableItemText = (IUpdateableItemText)adapterFactory.adapt(object, IUpdateableItemText.class);
    if (updateableItemText != null)
    {
      String string = updateableItemText.getUpdateableText(object);
      if (string != null)
      {
        horizontalAlignment = 16384;
        
        minimumWidth = Math.max(50, getBoundswidth);
        if (System.getProperty("EMF_COMBO_TEST") == null)
        {
          final Text text = new Text(tree, 2048);
          setEditor(text, treeItem);
          text.setFocus();
          text.setText(string);
          text.setSelection(0, string.length());
          
          text.addFocusListener(
            new FocusAdapter()
            {
              public void focusLost(FocusEvent event)
              {
                updateableItemText.setText(object, text.getText());
                text.setVisible(false);
              }
            });
          text.addKeyListener(
            new KeyAdapter()
            {
              public void keyPressed(KeyEvent event)
              {
                if ((character == '\r') || (character == '\n'))
                {
                  updateableItemText.setText(object, text.getText());
                  setEditor(null);
                  text.dispose();
                }
                else if (character == '\033')
                {
                  setEditor(null);
                  text.dispose();
                }
              }
            });
        }
        else
        {
          final Combo combo = new Combo(tree, 2048);
          setEditor(combo, treeItem);
          combo.setFocus();
          combo.setText(string);
          combo.setSelection(new Point(0, string.length()));
          combo.add("Item 1");
          combo.add("Item 2");
          combo.add("Item 3");
          combo.add("Item 4");
          
          combo.addFocusListener(
            new FocusAdapter()
            {
              public void focusLost(FocusEvent event)
              {
                System.out.println("Combo lost focus");
                updateableItemText.setText(object, combo.getText());
                combo.setVisible(false);
              }
            });
          combo.addKeyListener(
            new KeyAdapter()
            {
              public void keyPressed(KeyEvent event)
              {
                System.out.println("Combo key event");
                if ((character == '\r') || (character == '\n'))
                {
                  updateableItemText.setText(object, combo.getText());
                  setEditor(null);
                  combo.dispose();
                }
                else if (character == '\033')
                {
                  setEditor(null);
                  combo.dispose();
                }
              }
            });
          combo.addModifyListener(
            new ModifyListener()
            {
              public void modifyText(ModifyEvent event)
              {
                System.out.println("Combo modified");
              }
            });
        }
      }
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.emf.edit.ui.celleditor.AdapterFactoryTreeEditor
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.emf.edit.ui.celleditor;

import org.eclipse.jface.viewers.AbstractTreeViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.ui.dialogs.PatternFilter;

class FeatureEditorDialog$1
  extends PatternFilter
{
  FeatureEditorDialog$1(FeatureEditorDialog paramFeatureEditorDialog) {}
  
  protected boolean isParentMatch(Viewer viewer, Object element)
  {
    return ((viewer instanceof AbstractTreeViewer)) && (super.isParentMatch(viewer, element));
  }
}

/* Location:
 * Qualified Name:     org.eclipse.emf.edit.ui.celleditor.FeatureEditorDialog.1
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.emf.edit.ui.celleditor;

import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.dialogs.PatternFilter;

class FeatureEditorDialog$2
  implements ModifyListener
{
  FeatureEditorDialog$2(FeatureEditorDialog paramFeatureEditorDialog, PatternFilter paramPatternFilter, TableViewer paramTableViewer) {}
  
  public void modifyText(ModifyEvent e)
  {
    val$filter.setPattern(((Text)widget).getText());
    val$choiceTableViewer.refresh();
  }
}

/* Location:
 * Qualified Name:     org.eclipse.emf.edit.ui.celleditor.FeatureEditorDialog.2
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.emf.edit.ui.celleditor;

import org.eclipse.jface.viewers.DoubleClickEvent;
import org.eclipse.jface.viewers.IDoubleClickListener;
import org.eclipse.swt.widgets.Button;

class FeatureEditorDialog$3
  implements IDoubleClickListener
{
  FeatureEditorDialog$3(FeatureEditorDialog paramFeatureEditorDialog, Button paramButton) {}
  
  public void doubleClick(DoubleClickEvent event)
  {
    if (val$addButton.isEnabled()) {
      val$addButton.notifyListeners(13, null);
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.emf.edit.ui.celleditor.FeatureEditorDialog.3
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.emf.edit.ui.celleditor;

import org.eclipse.jface.viewers.DoubleClickEvent;
import org.eclipse.jface.viewers.IDoubleClickListener;
import org.eclipse.swt.widgets.Button;

class FeatureEditorDialog$4
  implements IDoubleClickListener
{
  FeatureEditorDialog$4(FeatureEditorDialog paramFeatureEditorDialog, Button paramButton) {}
  
  public void doubleClick(DoubleClickEvent event)
  {
    if (val$removeButton.isEnabled()) {
      val$removeButton.notifyListeners(13, null);
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.emf.edit.ui.celleditor.FeatureEditorDialog.4
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.emf.edit.ui.celleditor;

import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EDataType;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.edit.provider.ItemProvider;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.swt.events.KeyAdapter;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.widgets.Text;

class FeatureEditorDialog$5
  extends KeyAdapter
{
  FeatureEditorDialog$5(FeatureEditorDialog paramFeatureEditorDialog, Text paramText, TableViewer paramTableViewer) {}
  
  public void keyPressed(KeyEvent event)
  {
    if ((!this$0.multiLine) && ((character == '\r') || (character == '\n')))
    {
      try
      {
        Object value = EcoreUtil.createFromString((EDataType)this$0.eClassifier, val$choiceText.getText());
        this$0.values.getChildren().add(value);
        val$choiceText.setText("");
        val$featureTableViewer.setSelection(new StructuredSelection(value));
        doit = false;
      }
      catch (RuntimeException localRuntimeException) {}
    }
    else if (character == '\033')
    {
      val$choiceText.setText("");
      doit = false;
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.emf.edit.ui.celleditor.FeatureEditorDialog.5
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.emf.edit.ui.celleditor;

import java.util.Iterator;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.edit.provider.ItemProvider;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;

class FeatureEditorDialog$6
  extends SelectionAdapter
{
  FeatureEditorDialog$6(FeatureEditorDialog paramFeatureEditorDialog, TableViewer paramTableViewer) {}
  
  public void widgetSelected(SelectionEvent event)
  {
    IStructuredSelection selection = (IStructuredSelection)val$featureTableViewer.getSelection();
    int minIndex = 0;
    for (Iterator<?> i = selection.iterator(); i.hasNext();)
    {
      Object value = i.next();
      int index = this$0.values.getChildren().indexOf(value);
      this$0.values.getChildren().move(Math.max(index - 1, minIndex++), value);
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.emf.edit.ui.celleditor.FeatureEditorDialog.6
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.emf.edit.ui.celleditor;

import java.util.Iterator;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.edit.provider.ItemProvider;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;

class FeatureEditorDialog$7
  extends SelectionAdapter
{
  FeatureEditorDialog$7(FeatureEditorDialog paramFeatureEditorDialog, TableViewer paramTableViewer) {}
  
  public void widgetSelected(SelectionEvent event)
  {
    IStructuredSelection selection = (IStructuredSelection)val$featureTableViewer.getSelection();
    int maxIndex = this$0.values.getChildren().size() - selection.size();
    for (Iterator<?> i = selection.iterator(); i.hasNext();)
    {
      Object value = i.next();
      int index = this$0.values.getChildren().indexOf(value);
      this$0.values.getChildren().move(Math.min(index + 1, maxIndex++), value);
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.emf.edit.ui.celleditor.FeatureEditorDialog.7
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.emf.edit.ui.celleditor;

import java.util.Iterator;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EDataType;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.edit.provider.ItemProvider;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Text;

class FeatureEditorDialog$8
  extends SelectionAdapter
{
  FeatureEditorDialog$8(FeatureEditorDialog paramFeatureEditorDialog, TableViewer paramTableViewer1, TableViewer paramTableViewer2, Text paramText) {}
  
  public void widgetSelected(SelectionEvent event)
  {
    if (val$choiceTableViewer != null)
    {
      IStructuredSelection selection = (IStructuredSelection)val$choiceTableViewer.getSelection();
      for (Iterator<?> i = selection.iterator(); i.hasNext();)
      {
        Object value = i.next();
        if ((!this$0.unique) || (!this$0.values.getChildren().contains(value))) {
          this$0.values.getChildren().add(value);
        }
      }
      val$featureTableViewer.setSelection(selection);
    }
    else if (val$choiceText != null)
    {
      try
      {
        Object value = EcoreUtil.createFromString((EDataType)this$0.eClassifier, val$choiceText.getText());
        if ((!this$0.unique) || (!this$0.values.getChildren().contains(value)))
        {
          this$0.values.getChildren().add(value);
          val$choiceText.setText("");
        }
        val$featureTableViewer.setSelection(new StructuredSelection(value));
      }
      catch (RuntimeException localRuntimeException) {}
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.emf.edit.ui.celleditor.FeatureEditorDialog.8
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.emf.edit.ui.celleditor;

import java.util.Iterator;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EDataType;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.edit.provider.ItemProvider;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Text;

class FeatureEditorDialog$9
  extends SelectionAdapter
{
  FeatureEditorDialog$9(FeatureEditorDialog paramFeatureEditorDialog, TableViewer paramTableViewer1, TableViewer paramTableViewer2, Text paramText) {}
  
  public void widgetSelected(SelectionEvent event)
  {
    IStructuredSelection selection = (IStructuredSelection)val$featureTableViewer.getSelection();
    Object firstValue = null;
    for (Iterator<?> i = selection.iterator(); i.hasNext();)
    {
      Object value = i.next();
      if (firstValue == null) {
        firstValue = value;
      }
      this$0.values.getChildren().remove(value);
    }
    if (!this$0.values.getChildren().isEmpty()) {
      val$featureTableViewer.setSelection(new StructuredSelection(this$0.values.getChildren().get(0)));
    }
    if (val$choiceTableViewer != null) {
      val$choiceTableViewer.setSelection(selection);
    } else if (val$choiceText != null) {
      if (firstValue != null)
      {
        String value = EcoreUtil.convertToString((EDataType)this$0.eClassifier, firstValue);
        val$choiceText.setText(value);
      }
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.emf.edit.ui.celleditor.FeatureEditorDialog.9
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.emf.edit.ui.celleditor;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import org.eclipse.emf.common.notify.AdapterFactory;
import org.eclipse.emf.common.notify.impl.AdapterFactoryImpl;
import org.eclipse.emf.common.ui.celleditor.ExtendedComboBoxCellEditor;
import org.eclipse.emf.common.util.BasicEList;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EClassifier;
import org.eclipse.emf.ecore.EDataType;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.edit.provider.ComposedAdapterFactory;
import org.eclipse.emf.edit.provider.ItemProvider;
import org.eclipse.emf.edit.ui.EMFEditUIPlugin;
import org.eclipse.emf.edit.ui.provider.AdapterFactoryContentProvider;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.viewers.AbstractTreeViewer;
import org.eclipse.jface.viewers.DoubleClickEvent;
import org.eclipse.jface.viewers.IContentProvider;
import org.eclipse.jface.viewers.IDoubleClickListener;
import org.eclipse.jface.viewers.ILabelProvider;
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.swt.events.KeyAdapter;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.dialogs.PatternFilter;

public class FeatureEditorDialog
  extends Dialog
{
  protected ILabelProvider labelProvider;
  protected IContentProvider contentProvider;
  protected Object object;
  protected EClassifier eClassifier;
  protected String displayName;
  protected ItemProvider values;
  protected List<?> choiceOfValues;
  protected EList<?> result;
  protected boolean multiLine;
  protected boolean unique;
  
  public FeatureEditorDialog(Shell parent, ILabelProvider labelProvider, Object object, EClassifier eClassifier, List<?> currentValues, String displayName, List<?> choiceOfValues, boolean multiLine, boolean sortChoices, boolean unique)
  {
    super(parent);
    setShellStyle(getShellStyle() | 0x10 | 0x400);
    this.labelProvider = labelProvider;
    this.object = object;
    this.eClassifier = eClassifier;
    this.displayName = displayName;
    this.choiceOfValues = choiceOfValues;
    this.multiLine = multiLine;
    this.unique = unique;
    
    AdapterFactory adapterFactory = new ComposedAdapterFactory(Collections.emptyList());
    values = new ItemProvider(adapterFactory, currentValues);
    contentProvider = new AdapterFactoryContentProvider(adapterFactory);
    if ((sortChoices) && (choiceOfValues != null))
    {
      this.choiceOfValues = new ArrayList(choiceOfValues);
      ExtendedComboBoxCellEditor.createItems(this.choiceOfValues, labelProvider, true);
    }
  }
  
  @Deprecated
  public FeatureEditorDialog(Shell parent, ILabelProvider labelProvider, Object object, EClassifier eClassifier, List<?> currentValues, String displayName, List<?> choiceOfValues, boolean multiLine, boolean sortChoices)
  {
    this(parent, labelProvider, object, eClassifier, currentValues, displayName, choiceOfValues, multiLine, sortChoices, choiceOfValues != null);
  }
  
  @Deprecated
  public FeatureEditorDialog(Shell parent, ILabelProvider labelProvider, Object object, EClassifier eClassifier, List<?> currentValues, String displayName, List<?> choiceOfValues)
  {
    this(parent, labelProvider, object, eClassifier, currentValues, displayName, choiceOfValues, false, false, choiceOfValues != null);
  }
  
  public FeatureEditorDialog(Shell parent, ILabelProvider labelProvider, EObject eObject, EStructuralFeature eStructuralFeature, String displayName, List<?> choiceOfValues)
  {
    this(parent, labelProvider, eObject, eStructuralFeature.getEType(), (List)eObject.eGet(eStructuralFeature), displayName, choiceOfValues, false, false, eStructuralFeature.isUnique());
  }
  
  protected void configureShell(Shell shell)
  {
    super.configureShell(shell);
    shell.setText(
      EMFEditUIPlugin.INSTANCE.getString(
      "_UI_FeatureEditorDialog_title", new Object[] { displayName, labelProvider.getText(object) }));
    shell.setImage(labelProvider.getImage(object));
  }
  
  protected Control createDialogArea(Composite parent)
  {
    Composite contents = (Composite)super.createDialogArea(parent);
    
    GridLayout contentsGridLayout = (GridLayout)contents.getLayout();
    numColumns = 3;
    
    GridData contentsGridData = (GridData)contents.getLayoutData();
    horizontalAlignment = 4;
    verticalAlignment = 4;
    
    Text patternText = null;
    if (choiceOfValues != null)
    {
      Group filterGroupComposite = new Group(contents, 0);
      filterGroupComposite.setText(EMFEditUIPlugin.INSTANCE.getString("_UI_Choices_pattern_group"));
      filterGroupComposite.setLayout(new GridLayout(2, false));
      filterGroupComposite.setLayoutData(new GridData(4, -1, true, false, 3, 1));
      
      Label label = new Label(filterGroupComposite, 0);
      label.setText(EMFEditUIPlugin.INSTANCE.getString("_UI_Choices_pattern_label"));
      
      patternText = new Text(filterGroupComposite, 2048);
      patternText.setLayoutData(new GridData(768));
    }
    Composite choiceComposite = new Composite(contents, 0);
    
    GridData data = new GridData(4, 4, true, true);
    horizontalAlignment = 16777224;
    choiceComposite.setLayoutData(data);
    
    GridLayout layout = new GridLayout();
    horizontalAlignment = 4;
    marginHeight = 0;
    marginWidth = 0;
    numColumns = 1;
    choiceComposite.setLayout(layout);
    
    Label choiceLabel = new Label(choiceComposite, 0);
    choiceLabel.setText(
      choiceOfValues == null ? 
      EMFEditUIPlugin.INSTANCE.getString("_UI_Value_label") : 
      EMFEditUIPlugin.INSTANCE.getString("_UI_Choices_label"));
    GridData choiceLabelGridData = new GridData();
    verticalAlignment = 4;
    horizontalAlignment = 4;
    choiceLabel.setLayoutData(choiceLabelGridData);
    
    Table choiceTable = choiceOfValues == null ? null : new Table(choiceComposite, 2050);
    if (choiceTable != null)
    {
      GridData choiceTableGridData = new GridData();
      widthHint = (getCurrentgetBoundswidth / 5);
      heightHint = (getCurrentgetBoundsheight / 3);
      verticalAlignment = 4;
      horizontalAlignment = 4;
      grabExcessHorizontalSpace = true;
      grabExcessVerticalSpace = true;
      choiceTable.setLayoutData(choiceTableGridData);
    }
    final TableViewer choiceTableViewer = choiceOfValues == null ? null : new TableViewer(choiceTable);
    if (choiceTableViewer != null)
    {
      choiceTableViewer.setContentProvider(new AdapterFactoryContentProvider(new AdapterFactoryImpl()));
      choiceTableViewer.setLabelProvider(labelProvider);
      final PatternFilter filter = 
        new PatternFilter()
        {
          protected boolean isParentMatch(Viewer viewer, Object element)
          {
            return ((viewer instanceof AbstractTreeViewer)) && (super.isParentMatch(viewer, element));
          }
        };
        choiceTableViewer.addFilter(filter);
        assert (patternText != null);
        patternText.addModifyListener(
          new ModifyListener()
          {
            public void modifyText(ModifyEvent e)
            {
              filter.setPattern(((Text)widget).getText());
              choiceTableViewer.refresh();
            }
          });
        choiceTableViewer.setInput(new ItemProvider(choiceOfValues));
      }
      int style = multiLine ? 
        2818 : 
        2050;
      final Text choiceText = choiceOfValues == null ? new Text(choiceComposite, style) : null;
      if (choiceText != null)
      {
        GridData choiceTextGridData = new GridData();
        widthHint = (getCurrentgetBoundswidth / 5);
        verticalAlignment = 1;
        horizontalAlignment = 4;
        grabExcessHorizontalSpace = true;
        if (multiLine)
        {
          verticalAlignment = 4;
          grabExcessVerticalSpace = true;
        }
        choiceText.setLayoutData(choiceTextGridData);
      }
      Composite controlButtons = new Composite(contents, 0);
      GridData controlButtonsGridData = new GridData();
      verticalAlignment = 4;
      horizontalAlignment = 4;
      controlButtons.setLayoutData(controlButtonsGridData);
      
      GridLayout controlsButtonGridLayout = new GridLayout();
      controlButtons.setLayout(controlsButtonGridLayout);
      
      new Label(controlButtons, 0);
      
      final Button addButton = new Button(controlButtons, 8);
      addButton.setText(EMFEditUIPlugin.INSTANCE.getString("_UI_Add_label"));
      GridData addButtonGridData = new GridData();
      verticalAlignment = 4;
      horizontalAlignment = 4;
      addButton.setLayoutData(addButtonGridData);
      
      final Button removeButton = new Button(controlButtons, 8);
      removeButton.setText(EMFEditUIPlugin.INSTANCE.getString("_UI_Remove_label"));
      GridData removeButtonGridData = new GridData();
      verticalAlignment = 4;
      horizontalAlignment = 4;
      removeButton.setLayoutData(removeButtonGridData);
      
      Label spaceLabel = new Label(controlButtons, 0);
      GridData spaceLabelGridData = new GridData();
      verticalSpan = 2;
      spaceLabel.setLayoutData(spaceLabelGridData);
      
      Button upButton = new Button(controlButtons, 8);
      upButton.setText(EMFEditUIPlugin.INSTANCE.getString("_UI_Up_label"));
      GridData upButtonGridData = new GridData();
      verticalAlignment = 4;
      horizontalAlignment = 4;
      upButton.setLayoutData(upButtonGridData);
      
      Button downButton = new Button(controlButtons, 8);
      downButton.setText(EMFEditUIPlugin.INSTANCE.getString("_UI_Down_label"));
      GridData downButtonGridData = new GridData();
      verticalAlignment = 4;
      horizontalAlignment = 4;
      downButton.setLayoutData(downButtonGridData);
      
      Composite featureComposite = new Composite(contents, 0);
      
      GridData data = new GridData(4, 4, true, true);
      horizontalAlignment = 16777224;
      featureComposite.setLayoutData(data);
      
      GridLayout layout = new GridLayout();
      horizontalAlignment = 4;
      marginHeight = 0;
      marginWidth = 0;
      numColumns = 1;
      featureComposite.setLayout(layout);
      
      Label featureLabel = new Label(featureComposite, 0);
      featureLabel.setText(EMFEditUIPlugin.INSTANCE.getString("_UI_Feature_label"));
      GridData featureLabelGridData = new GridData();
      horizontalSpan = 2;
      horizontalAlignment = 4;
      verticalAlignment = 4;
      featureLabel.setLayoutData(featureLabelGridData);
      
      Table featureTable = new Table(featureComposite, 2050);
      GridData featureTableGridData = new GridData();
      widthHint = (getCurrentgetBoundswidth / 5);
      heightHint = (getCurrentgetBoundsheight / 3);
      verticalAlignment = 4;
      horizontalAlignment = 4;
      grabExcessHorizontalSpace = true;
      grabExcessVerticalSpace = true;
      featureTable.setLayoutData(featureTableGridData);
      
      final TableViewer featureTableViewer = new TableViewer(featureTable);
      featureTableViewer.setContentProvider(contentProvider);
      featureTableViewer.setLabelProvider(labelProvider);
      featureTableViewer.setInput(values);
      if (!values.getChildren().isEmpty()) {
        featureTableViewer.setSelection(new StructuredSelection(values.getChildren().get(0)));
      }
      if (choiceTableViewer != null)
      {
        choiceTableViewer.addDoubleClickListener(new IDoubleClickListener()
        {
          public void doubleClick(DoubleClickEvent event)
          {
            if (addButton.isEnabled()) {
              addButton.notifyListeners(13, null);
            }
          }
        });
        featureTableViewer.addDoubleClickListener(new IDoubleClickListener()
        {
          public void doubleClick(DoubleClickEvent event)
          {
            if (removeButton.isEnabled()) {
              removeButton.notifyListeners(13, null);
            }
          }
        });
      }
      if (choiceText != null) {
        choiceText.addKeyListener(
          new KeyAdapter()
          {
            public void keyPressed(KeyEvent event)
            {
              if ((!multiLine) && ((character == '\r') || (character == '\n')))
              {
                try
                {
                  Object value = EcoreUtil.createFromString((EDataType)eClassifier, choiceText.getText());
                  values.getChildren().add(value);
                  choiceText.setText("");
                  featureTableViewer.setSelection(new StructuredSelection(value));
                  doit = false;
                }
                catch (RuntimeException localRuntimeException) {}
              }
              else if (character == '\033')
              {
                choiceText.setText("");
                doit = false;
              }
            }
          });
      }
      upButton.addSelectionListener(
        new SelectionAdapter()
        {
          public void widgetSelected(SelectionEvent event)
          {
            IStructuredSelection selection = (IStructuredSelection)featureTableViewer.getSelection();
            int minIndex = 0;
            for (Iterator<?> i = selection.iterator(); i.hasNext();)
            {
              Object value = i.next();
              int index = values.getChildren().indexOf(value);
              values.getChildren().move(Math.max(index - 1, minIndex++), value);
            }
          }
        });
      downButton.addSelectionListener(
        new SelectionAdapter()
        {
          public void widgetSelected(SelectionEvent event)
          {
            IStructuredSelection selection = (IStructuredSelection)featureTableViewer.getSelection();
            int maxIndex = values.getChildren().size() - selection.size();
            for (Iterator<?> i = selection.iterator(); i.hasNext();)
            {
              Object value = i.next();
              int index = values.getChildren().indexOf(value);
              values.getChildren().move(Math.min(index + 1, maxIndex++), value);
            }
          }
        });
      addButton.addSelectionListener(
        new SelectionAdapter()
        {
          public void widgetSelected(SelectionEvent event)
          {
            if (choiceTableViewer != null)
            {
              IStructuredSelection selection = (IStructuredSelection)choiceTableViewer.getSelection();
              for (Iterator<?> i = selection.iterator(); i.hasNext();)
              {
                Object value = i.next();
                if ((!unique) || (!values.getChildren().contains(value))) {
                  values.getChildren().add(value);
                }
              }
              featureTableViewer.setSelection(selection);
            }
            else if (choiceText != null)
            {
              try
              {
                Object value = EcoreUtil.createFromString((EDataType)eClassifier, choiceText.getText());
                if ((!unique) || (!values.getChildren().contains(value)))
                {
                  values.getChildren().add(value);
                  choiceText.setText("");
                }
                featureTableViewer.setSelection(new StructuredSelection(value));
              }
              catch (RuntimeException localRuntimeException) {}
            }
          }
        });
      removeButton.addSelectionListener(
        new SelectionAdapter()
        {
          public void widgetSelected(SelectionEvent event)
          {
            IStructuredSelection selection = (IStructuredSelection)featureTableViewer.getSelection();
            Object firstValue = null;
            for (Iterator<?> i = selection.iterator(); i.hasNext();)
            {
              Object value = i.next();
              if (firstValue == null) {
                firstValue = value;
              }
              values.getChildren().remove(value);
            }
            if (!values.getChildren().isEmpty()) {
              featureTableViewer.setSelection(new StructuredSelection(values.getChildren().get(0)));
            }
            if (choiceTableViewer != null) {
              choiceTableViewer.setSelection(selection);
            } else if (choiceText != null) {
              if (firstValue != null)
              {
                String value = EcoreUtil.convertToString((EDataType)eClassifier, firstValue);
                choiceText.setText(value);
              }
            }
          }
        });
      return contents;
    }
    
    protected void okPressed()
    {
      result = new BasicEList(values.getChildren());
      super.okPressed();
    }
    
    public boolean close()
    {
      contentProvider.dispose();
      return super.close();
    }
    
    public EList<?> getResult()
    {
      return result;
    }
  }

/* Location:
 * Qualified Name:     org.eclipse.emf.edit.ui.celleditor.FeatureEditorDialog
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.emf.edit.ui.dnd;

import java.util.ArrayList;
import java.util.Collection;
import org.eclipse.emf.common.command.Command;
import org.eclipse.emf.edit.command.DragAndDropCommand;
import org.eclipse.emf.edit.domain.EditingDomain;

public class EditingDomainViewerDropAdapter$DragAndDropCommandInformation
{
  protected EditingDomain domain;
  protected Object target;
  protected float location;
  protected int operations;
  protected int operation;
  protected Collection<?> source;
  
  public EditingDomainViewerDropAdapter$DragAndDropCommandInformation(EditingDomain domain, Object target, float location, int operations, int operation, Collection<?> source)
  {
    this.domain = domain;
    this.target = target;
    this.location = location;
    this.operations = operations;
    this.operation = operation;
    this.source = new ArrayList(source);
  }
  
  public Command createCommand()
  {
    return DragAndDropCommand.create(domain, target, location, operations, operation, source);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.emf.edit.ui.dnd.EditingDomainViewerDropAdapter.DragAndDropCommandInformation
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.emf.edit.ui.dnd;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import org.eclipse.emf.common.command.Command;
import org.eclipse.emf.common.command.CommandStack;
import org.eclipse.emf.edit.command.DragAndDropCommand;
import org.eclipse.emf.edit.command.DragAndDropFeedback;
import org.eclipse.emf.edit.domain.EditingDomain;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.dnd.DropTargetAdapter;
import org.eclipse.swt.dnd.DropTargetEvent;
import org.eclipse.swt.dnd.TransferData;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Item;
import org.eclipse.swt.widgets.TableItem;
import org.eclipse.swt.widgets.TreeItem;
import org.eclipse.swt.widgets.Widget;

public class EditingDomainViewerDropAdapter
  extends DropTargetAdapter
{
  protected static final boolean IS_MOTIF = "motif".equals(SWT.getPlatform());
  protected Viewer viewer;
  protected EditingDomain domain;
  protected Collection<?> source;
  protected Command command;
  protected Object commandTarget;
  protected int originalOperation;
  protected DragAndDropCommandInformation dragAndDropCommandInformation;
  
  public EditingDomainViewerDropAdapter(EditingDomain domain, Viewer viewer)
  {
    this.viewer = viewer;
    this.domain = domain;
  }
  
  public void dragEnter(DropTargetEvent event)
  {
    originalOperation = detail;
    
    helper(event);
  }
  
  public void dragLeave(DropTargetEvent event)
  {
    if (command != null)
    {
      command.dispose();
      command = null;
      commandTarget = null;
    }
    source = null;
  }
  
  public void dragOperationChanged(DropTargetEvent event)
  {
    originalOperation = detail;
    
    helper(event);
  }
  
  public void dragOver(DropTargetEvent event)
  {
    helper(event);
  }
  
  public void dropAccept(DropTargetEvent event)
  {
    helper(event);
  }
  
  public void drop(DropTargetEvent event)
  {
    if (dragAndDropCommandInformation != null)
    {
      command = dragAndDropCommandInformation.createCommand();
    }
    else
    {
      source = extractDragSource(data);
      Object target = extractDropTarget(item);
      command = DragAndDropCommand.create(domain, target, getLocation(event), operations, originalOperation, source);
    }
    if (command.canExecute())
    {
      domain.getCommandStack().execute(command);
    }
    else
    {
      detail = 0;
      command.dispose();
    }
    command = null;
    commandTarget = null;
    source = null;
    dragAndDropCommandInformation = null;
  }
  
  protected void helper(DropTargetEvent event)
  {
    feedback = (0x1 | getAutoFeedback());
    if (source == null)
    {
      source = getDragSource(event);
      if (source == null)
      {
        dragAndDropCommandInformation = null;
        return;
      }
    }
    Object target = extractDropTarget(item);
    float location = getLocation(event);
    
    boolean valid = false;
    if (command == null)
    {
      dragAndDropCommandInformation = new DragAndDropCommandInformation(domain, target, location, operations, originalOperation, source);
      
      commandTarget = target;
      command = dragAndDropCommandInformation.createCommand();
      valid = command.canExecute();
    }
    else if ((target == commandTarget) && ((command instanceof DragAndDropFeedback)))
    {
      valid = ((DragAndDropFeedback)command).validate(target, location, operations, originalOperation, source);
      
      dragAndDropCommandInformation = new DragAndDropCommandInformation(domain, target, location, operations, originalOperation, source);
    }
    else
    {
      dragAndDropCommandInformation = new DragAndDropCommandInformation(domain, target, location, operations, originalOperation, source);
      commandTarget = target;
      command.dispose();
      command = dragAndDropCommandInformation.createCommand();
      valid = command.canExecute();
    }
    if ((command instanceof DragAndDropFeedback))
    {
      DragAndDropFeedback dragAndDropFeedback = (DragAndDropFeedback)command;
      detail = dragAndDropFeedback.getOperation();
      feedback = (dragAndDropFeedback.getFeedback() | getAutoFeedback());
    }
    else if (!valid)
    {
      detail = 0;
    }
  }
  
  protected int getAutoFeedback()
  {
    return 24;
  }
  
  protected Collection<?> getDragSource(DropTargetEvent event)
  {
    LocalTransfer localTransfer = LocalTransfer.getInstance();
    if (!localTransfer.isSupportedType(currentDataType))
    {
      TransferData[] dataTypes = dataTypes;
      for (int i = 0; i < dataTypes.length; i++)
      {
        TransferData transferData = dataTypes[i];
        if (localTransfer.isSupportedType(transferData)) {
          currentDataType = transferData;
        }
      }
      return null;
    }
    if (IS_MOTIF) {
      return null;
    }
    Object object = localTransfer.nativeToJava(currentDataType);
    return object == null ? null : extractDragSource(object);
  }
  
  protected Collection<?> extractDragSource(Object object)
  {
    if ((object instanceof IStructuredSelection))
    {
      List<?> list = ((IStructuredSelection)object).toList();
      return list;
    }
    return Collections.EMPTY_LIST;
  }
  
  protected Object extractDropTarget(Widget item)
  {
    if (item == null) {
      return null;
    }
    return (item.getData("TableTreeItemID") instanceof Item) ? 
      ((Item)item.getData("TableTreeItemID")).getData() : 
      item.getData();
  }
  
  protected float getLocation(DropTargetEvent event)
  {
    if ((item instanceof TreeItem))
    {
      TreeItem treeItem = (TreeItem)item;
      Control control = treeItem.getParent();
      Point point = control.toControl(new Point(x, y));
      Rectangle bounds = treeItem.getBounds();
      return (y - y) / height;
    }
    if ((item instanceof TableItem))
    {
      TableItem tableItem = (TableItem)item;
      Control control = tableItem.getParent();
      Point point = control.toControl(new Point(x, y));
      Rectangle bounds = tableItem.getBounds(0);
      return (y - y) / height;
    }
    return 0.0F;
  }
  
  protected static class DragAndDropCommandInformation
  {
    protected EditingDomain domain;
    protected Object target;
    protected float location;
    protected int operations;
    protected int operation;
    protected Collection<?> source;
    
    pub
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-2019. Infinite Loop Ltd