Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » edit a model in an eclipse view
edit a model in an eclipse view [message #384989] Tue, 11 May 2004 08:21 Go to next message
Eike Stepper is currently offline Eike Stepper
Messages: 5252
Registered: July 2009
Senior Member
i'd like to edit a model in an eclipse view and
started with the "new plug-in project" wizard.

i managed to replace the wizard's sample model
with the emf model from a resource by copying
some code from the emf generated editor to the
wizard generated view.

because of differences between an editor's and a
view's api, i was not able to copy some methods.
when running a run-time workbench, the model
is shown properly, but

1) there is no context menu
2) the command framework does not work,
moving and deleting has no effect
3) the properties view doesn't show anything

i've browsed the web and the newsgroup, but
couldn't find example code. don't you think, it
was nice to have a "generate View Code"
option in the genmodel?

here is my code:

package prototyping.views.views;


import org.eclipse.emf.common.command.BasicCommandStack;
import org.eclipse.emf.common.ui.viewer.IViewerProvider;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain;
import org.eclipse.emf.edit.domain.EditingDomain;
import org.eclipse.emf.edit.domain.IEditingDomainProvider;
import org.eclipse.emf.edit.provider.ComposedAdapterFactory;
import org.eclipse.emf.edit.provider.ReflectiveItemProviderAdapterF actory;
import org.eclipse.emf.edit.provider.resource.ResourceItemProviderA dapterFactory;
import org.eclipse.emf.edit.ui.dnd.EditingDomainViewerDropAdapter;
import org.eclipse.emf.edit.ui.dnd.LocalTransfer;
import org.eclipse.emf.edit.ui.dnd.ViewerDragAdapter;
import org.eclipse.emf.edit.ui.provider.AdapterFactoryContentProvid er;
import org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider ;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IMenuListener;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.action.Separator;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.ISelectionProvider;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerSorter;
import org.eclipse.swt.SWT;
import org.eclipse.swt.dnd.DND;
import org.eclipse.swt.dnd.Transfer;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.ui.part.DrillDownAdapter;
import org.eclipse.ui.part.ViewPart;
import org.eclipse.ui.views.properties.PropertySheetPage;

import prototyping.views.model.library.provider.LibraryItemProvider AdapterFactory;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;


/**
* This sample class demonstrates how to plug-in a new workbench view. The view shows data obtained
* from the model. The sample creates a dummy model on the fly, but a real implementation would
* connect to the model available either in this or another plug-in (e.g. the workspace). The view
* is connected to the model using a content provider.
* <p>
* The view uses a label provider to define how model objects should be presented in the view. Each
* view can present the same model objects using different labels and icons, if needed.
* Alternatively, a single label provider can be shared between views in order to ensure that
* objects of the same type are presented in the same way everywhere.
* <p>
*/

public class ProStepperView extends ViewPart implements IEditingDomainProvider, ISelectionProvider,
IMenuListener, IViewerProvider
{

/**
* The constructor.
*/
public ProStepperView()
{
// Create an adapter factory that yields item providers.
List factories = new ArrayList();
factories.add(new ResourceItemProviderAdapterFactory());
factories.add(new LibraryItemProviderAdapterFactory());
factories.add(new ReflectiveItemProviderAdapterFactory());

adapterFactory = new ComposedAdapterFactory(factories);

// Create the command stack that will notify this editor as commands are executed.
BasicCommandStack commandStack = new BasicCommandStack();

// Create the editing domain with a special command stack.
editingDomain = new AdapterFactoryEditingDomain(adapterFactory, commandStack);
resourceSet = editingDomain.getResourceSet();

URI uri = URI.createPlatformResourceURI("test/My.library");
Resource resource = resourceSet.createResource(uri);

try
{
resource.load(Collections.EMPTY_MAP);
}
catch (IOException ex)
{
ex.printStackTrace();
}
}

/**
* This is a callback that will allow us to create the viewer and initialize it.
*/
public void createPartControl(Composite parent)
{
viewer = new TreeViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
drillDownAdapter = new DrillDownAdapter(viewer);

viewer.setContentProvider(new AdapterFactoryContentProvider(adapterFactory));
viewer.setLabelProvider(new AdapterFactoryLabelProvider(adapterFactory));
viewer.setSorter(new NameSorter());
viewer.setInput(resourceSet);

createContextMenuFor(viewer);
}

/**
* This creates a context menu for the viewer and adds a listener as well registering the menu for extension.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
protected void createContextMenuFor(TreeViewer viewer)
{
MenuManager contextMenu = new MenuManager("#PopUp");
contextMenu.add(new Separator("additions"));
contextMenu.setRemoveAllWhenShown(true);
contextMenu.addMenuListener(this);
Menu menu = contextMenu.createContextMenu(viewer.getControl());
viewer.getControl().setMenu(menu);
getSite().registerContextMenu(contextMenu, viewer);

int dndOperations = DND.DROP_COPY | DND.DROP_MOVE | DND.DROP_LINK;
Transfer[] transfers = new Transfer[] { LocalTransfer.getInstance()};
viewer.addDragSupport(dndOperations, transfers, new ViewerDragAdapter(viewer));
viewer.addDropSupport(dndOperations, transfers, new EditingDomainViewerDropAdapter(
editingDomain, viewer));
}

/**
* Passing the focus request to the viewer's control.
*/
public void setFocus()
{
viewer.getControl().setFocus();
}


class NameSorter extends ViewerSorter
{
}

protected TreeViewer viewer;

protected DrillDownAdapter drillDownAdapter;

protected Action action1;

protected Action action2;

protected Action doubleClickAction;

protected ComposedAdapterFactory adapterFactory;

protected AdapterFactoryEditingDomain editingDomain;

protected ResourceSet resourceSet;

protected PropertySheetPage propertySheetPage;

/**
* This keeps track of the selection of the editor as a whole.
*/
protected ISelection viewerSelection;

/**
* This keeps track of all the {@link org.eclipse.jface.viewers.ISelectionChangedListener}s that
* are listening to this editor.
*/
protected Collection selectionChangedListeners = new ArrayList();

/**
* This returns the editing domain as required by the {@link IEditingDomainProvider}interface.
* This is important for implementing the static methods of {@link AdapterFactoryEditingDomain}
* and for supporting {@link org.eclipse.emf.edit.ui.action.CommandAction}.
*/
public EditingDomain getEditingDomain()
{
return editingDomain;
}

/**
* This implements {@link org.eclipse.jface.viewers.ISelectionProvider}.
*/
public void addSelectionChangedListener(ISelectionChangedListener listener)
{
selectionChangedListeners.add(listener);
}

/**
* This implements {@link org.eclipse.jface.viewers.ISelectionProvider}to return this editor's
* overall selection.
*/
public ISelection getSelection()
{
return viewerSelection;
}

/**
* This implements {@link org.eclipse.jface.viewers.ISelectionProvider}.
*/
public void removeSelectionChangedListener(ISelectionChangedListener listener)
{
selectionChangedListeners.remove(listener);
}

/**
* This implements {@link org.eclipse.jface.viewers.ISelectionProvider}to set this editor's
* overall selection. Calling this result will notify the listeners.
*/
public void setSelection(ISelection selection)
{
viewerSelection = selection;
for (Iterator listeners = selectionChangedListeners.iterator(); listeners.hasNext();)
{
ISelectionChangedListener listener = (ISelectionChangedListener) listeners.next();
listener.selectionChanged(new SelectionChangedEvent(this, selection));
}
//setStatusLineManager(selection);
}

public void menuAboutToShow(IMenuManager manager)
{
// TODO Auto-generated method stub

}

public Viewer getViewer()
{
// TODO Auto-generated method stub
return viewer;
}

}

/eike
Re: edit a model in an eclipse view [message #384990 is a reply to message #384989] Tue, 11 May 2004 08:36 Go to previous messageGo to next message
Ed Merks is currently offline Ed Merks
Messages: 25227
Registered: July 2009
Senior Member
Eike,

The list of nice to haves is endless. Generating a view that supports editing opens up a whole set of issues that
we can't address anytime soon.


Eike Stepper wrote:

> i'd like to edit a model in an eclipse view and
> started with the "new plug-in project" wizard.
>
> i managed to replace the wizard's sample model
> with the emf model from a resource by copying
> some code from the emf generated editor to the
> wizard generated view.
>
> because of differences between an editor's and a
> view's api, i was not able to copy some methods.
> when running a run-time workbench, the model
> is shown properly, but
>
> 1) there is no context menu
> 2) the command framework does not work,
> moving and deleting has no effect
> 3) the properties view doesn't show anything
>
> i've browsed the web and the newsgroup, but
> couldn't find example code. don't you think, it
> was nice to have a "generate View Code"
> option in the genmodel?
>
> here is my code:
>
> package prototyping.views.views;
>
> import org.eclipse.emf.common.command.BasicCommandStack;
> import org.eclipse.emf.common.ui.viewer.IViewerProvider;
> import org.eclipse.emf.common.util.URI;
> import org.eclipse.emf.ecore.resource.Resource;
> import org.eclipse.emf.ecore.resource.ResourceSet;
> import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain;
> import org.eclipse.emf.edit.domain.EditingDomain;
> import org.eclipse.emf.edit.domain.IEditingDomainProvider;
> import org.eclipse.emf.edit.provider.ComposedAdapterFactory;
> import org.eclipse.emf.edit.provider.ReflectiveItemProviderAdapterF actory;
> import org.eclipse.emf.edit.provider.resource.ResourceItemProviderA dapterFactory;
> import org.eclipse.emf.edit.ui.dnd.EditingDomainViewerDropAdapter;
> import org.eclipse.emf.edit.ui.dnd.LocalTransfer;
> import org.eclipse.emf.edit.ui.dnd.ViewerDragAdapter;
> import org.eclipse.emf.edit.ui.provider.AdapterFactoryContentProvid er;
> import org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider ;
> import org.eclipse.jface.action.Action;
> import org.eclipse.jface.action.IMenuListener;
> import org.eclipse.jface.action.IMenuManager;
> import org.eclipse.jface.action.MenuManager;
> import org.eclipse.jface.action.Separator;
> import org.eclipse.jface.viewers.ISelection;
> import org.eclipse.jface.viewers.ISelectionChangedListener;
> import org.eclipse.jface.viewers.ISelectionProvider;
> import org.eclipse.jface.viewers.SelectionChangedEvent;
> import org.eclipse.jface.viewers.TreeViewer;
> import org.eclipse.jface.viewers.Viewer;
> import org.eclipse.jface.viewers.ViewerSorter;
> import org.eclipse.swt.SWT;
> import org.eclipse.swt.dnd.DND;
> import org.eclipse.swt.dnd.Transfer;
> import org.eclipse.swt.widgets.Composite;
> import org.eclipse.swt.widgets.Menu;
> import org.eclipse.ui.part.DrillDownAdapter;
> import org.eclipse.ui.part.ViewPart;
> import org.eclipse.ui.views.properties.PropertySheetPage;
>
> import prototyping.views.model.library.provider.LibraryItemProvider AdapterFactory;
>
> import java.io.IOException;
> import java.util.ArrayList;
> import java.util.Collection;
> import java.util.Collections;
> import java.util.Iterator;
> import java.util.List;
>
> /**
> * This sample class demonstrates how to plug-in a new workbench view. The view shows data obtained
> * from the model. The sample creates a dummy model on the fly, but a real implementation would
> * connect to the model available either in this or another plug-in (e.g. the workspace). The view
> * is connected to the model using a content provider.
> * <p>
> * The view uses a label provider to define how model objects should be presented in the view. Each
> * view can present the same model objects using different labels and icons, if needed.
> * Alternatively, a single label provider can be shared between views in order to ensure that
> * objects of the same type are presented in the same way everywhere.
> * <p>
> */
>
> public class ProStepperView extends ViewPart implements IEditingDomainProvider, ISelectionProvider,
> IMenuListener, IViewerProvider
> {
>
> /**
> * The constructor.
> */
> public ProStepperView()
> {
> // Create an adapter factory that yields item providers.
> List factories = new ArrayList();
> factories.add(new ResourceItemProviderAdapterFactory());
> factories.add(new LibraryItemProviderAdapterFactory());
> factories.add(new ReflectiveItemProviderAdapterFactory());
>
> adapterFactory = new ComposedAdapterFactory(factories);
>
> // Create the command stack that will notify this editor as commands are executed.
> BasicCommandStack commandStack = new BasicCommandStack();
>
> // Create the editing domain with a special command stack.
> editingDomain = new AdapterFactoryEditingDomain(adapterFactory, commandStack);
> resourceSet = editingDomain.getResourceSet();
>
> URI uri = URI.createPlatformResourceURI("test/My.library");
> Resource resource = resourceSet.createResource(uri);
>
> try
> {
> resource.load(Collections.EMPTY_MAP);
> }
> catch (IOException ex)
> {
> ex.printStackTrace();
> }
> }
>
> /**
> * This is a callback that will allow us to create the viewer and initialize it.
> */
> public void createPartControl(Composite parent)
> {
> viewer = new TreeViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
> drillDownAdapter = new DrillDownAdapter(viewer);
>
> viewer.setContentProvider(new AdapterFactoryContentProvider(adapterFactory));
> viewer.setLabelProvider(new AdapterFactoryLabelProvider(adapterFactory));
> viewer.setSorter(new NameSorter());
> viewer.setInput(resourceSet);
>
> createContextMenuFor(viewer);
> }
>
> /**
> * This creates a context menu for the viewer and adds a listener as well registering the menu for extension.
> * <!-- begin-user-doc -->
> * <!-- end-user-doc -->
> * @generated
> */
> protected void createContextMenuFor(TreeViewer viewer)
> {
> MenuManager contextMenu = new MenuManager("#PopUp");
> contextMenu.add(new Separator("additions"));
> contextMenu.setRemoveAllWhenShown(true);
> contextMenu.addMenuListener(this);
> Menu menu = contextMenu.createContextMenu(viewer.getControl());
> viewer.getControl().setMenu(menu);
> getSite().registerContextMenu(contextMenu, viewer);
>
> int dndOperations = DND.DROP_COPY | DND.DROP_MOVE | DND.DROP_LINK;
> Transfer[] transfers = new Transfer[] { LocalTransfer.getInstance()};
> viewer.addDragSupport(dndOperations, transfers, new ViewerDragAdapter(viewer));
> viewer.addDropSupport(dndOperations, transfers, new EditingDomainViewerDropAdapter(
> editingDomain, viewer));
> }
>
> /**
> * Passing the focus request to the viewer's control.
> */
> public void setFocus()
> {
> viewer.getControl().setFocus();
> }
>
> class NameSorter extends ViewerSorter
> {
> }
>
> protected TreeViewer viewer;
>
> protected DrillDownAdapter drillDownAdapter;
>
> protected Action action1;
>
> protected Action action2;
>
> protected Action doubleClickAction;
>
> protected ComposedAdapterFactory adapterFactory;
>
> protected AdapterFactoryEditingDomain editingDomain;
>
> protected ResourceSet resourceSet;
>
> protected PropertySheetPage propertySheetPage;
>
> /**
> * This keeps track of the selection of the editor as a whole.
> */
> protected ISelection viewerSelection;
>
> /**
> * This keeps track of all the {@link org.eclipse.jface.viewers.ISelectionChangedListener}s that
> * are listening to this editor.
> */
> protected Collection selectionChangedListeners = new ArrayList();
>
> /**
> * This returns the editing domain as required by the {@link IEditingDomainProvider}interface.
> * This is important for implementing the static methods of {@link AdapterFactoryEditingDomain}
> * and for supporting {@link org.eclipse.emf.edit.ui.action.CommandAction}.
> */
> public EditingDomain getEditingDomain()
> {
> return editingDomain;
> }
>
> /**
> * This implements {@link org.eclipse.jface.viewers.ISelectionProvider}.
> */
> public void addSelectionChangedListener(ISelectionChangedListener listener)
> {
> selectionChangedListeners.add(listener);
> }
>
> /**
> * This implements {@link org.eclipse.jface.viewers.ISelectionProvider}to return this editor's
> * overall selection.
> */
> public ISelection getSelection()
> {
> return viewerSelection;
> }
>
> /**
> * This implements {@link org.eclipse.jface.viewers.ISelectionProvider}.
> */
> public void removeSelectionChangedListener(ISelectionChangedListener listener)
> {
> selectionChangedListeners.remove(listener);
> }
>
> /**
> * This implements {@link org.eclipse.jface.viewers.ISelectionProvider}to set this editor's
> * overall selection. Calling this result will notify the listeners.
> */
> public void setSelection(ISelection selection)
> {
> viewerSelection = selection;
> for (Iterator listeners = selectionChangedListeners.iterator(); listeners.hasNext();)
> {
> ISelectionChangedListener listener = (ISelectionChangedListener) listeners.next();
> listener.selectionChanged(new SelectionChangedEvent(this, selection));
> }
> //setStatusLineManager(selection);
> }
>
> public void menuAboutToShow(IMenuManager manager)
> {
> // TODO Auto-generated method stub
>
> }
>
> public Viewer getViewer()
> {
> // TODO Auto-generated method stub
> return viewer;
> }
>
> }
>
> /eike
Re: edit a model in an eclipse view [message #384994 is a reply to message #384989] Tue, 11 May 2004 13:57 Go to previous messageGo to next message
John Howard is currently offline John Howard
Messages: 83
Registered: July 2009
Member
I had to do this for a project I was working on and although fiddly I
don't remember it being that difficult. I basically took the generated
Editor and generated ActionBarContributor and modified these to get the
view working. e.g. the Editor code extends ViewPart instead of
MultiPageEditorPart. I think in the end it took a couple of days to
sort out the issues. The main problem with editing the model in this
way is tracking changes and making sure everything is saved. Eclipse
handles all this for editors, but not for views.

John.

Eike Stepper wrote:

> i'd like to edit a model in an eclipse view and
> started with the "new plug-in project" wizard.
>
> i managed to replace the wizard's sample model
> with the emf model from a resource by copying
> some code from the emf generated editor to the
> wizard generated view.
>
> because of differences between an editor's and a
> view's api, i was not able to copy some methods.
> when running a run-time workbench, the model
> is shown properly, but
>
> 1) there is no context menu
> 2) the command framework does not work,
> moving and deleting has no effect
> 3) the properties view doesn't show anything
>
> i've browsed the web and the newsgroup, but
> couldn't find example code. don't you think, it
> was nice to have a "generate View Code"
> option in the genmodel?
>
> here is my code:
>
> package prototyping.views.views;
>
>
> import org.eclipse.emf.common.command.BasicCommandStack;
> import org.eclipse.emf.common.ui.viewer.IViewerProvider;
> import org.eclipse.emf.common.util.URI;
> import org.eclipse.emf.ecore.resource.Resource;
> import org.eclipse.emf.ecore.resource.ResourceSet;
> import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain;
> import org.eclipse.emf.edit.domain.EditingDomain;
> import org.eclipse.emf.edit.domain.IEditingDomainProvider;
> import org.eclipse.emf.edit.provider.ComposedAdapterFactory;
> import org.eclipse.emf.edit.provider.ReflectiveItemProviderAdapterF actory;
> import org.eclipse.emf.edit.provider.resource.ResourceItemProviderA dapterFactory;
> import org.eclipse.emf.edit.ui.dnd.EditingDomainViewerDropAdapter;
> import org.eclipse.emf.edit.ui.dnd.LocalTransfer;
> import org.eclipse.emf.edit.ui.dnd.ViewerDragAdapter;
> import org.eclipse.emf.edit.ui.provider.AdapterFactoryContentProvid er;
> import org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider ;
> import org.eclipse.jface.action.Action;
> import org.eclipse.jface.action.IMenuListener;
> import org.eclipse.jface.action.IMenuManager;
> import org.eclipse.jface.action.MenuManager;
> import org.eclipse.jface.action.Separator;
> import org.eclipse.jface.viewers.ISelection;
> import org.eclipse.jface.viewers.ISelectionChangedListener;
> import org.eclipse.jface.viewers.ISelectionProvider;
> import org.eclipse.jface.viewers.SelectionChangedEvent;
> import org.eclipse.jface.viewers.TreeViewer;
> import org.eclipse.jface.viewers.Viewer;
> import org.eclipse.jface.viewers.ViewerSorter;
> import org.eclipse.swt.SWT;
> import org.eclipse.swt.dnd.DND;
> import org.eclipse.swt.dnd.Transfer;
> import org.eclipse.swt.widgets.Composite;
> import org.eclipse.swt.widgets.Menu;
> import org.eclipse.ui.part.DrillDownAdapter;
> import org.eclipse.ui.part.ViewPart;
> import org.eclipse.ui.views.properties.PropertySheetPage;
>
> import prototyping.views.model.library.provider.LibraryItemProvider AdapterFactory;
>
> import java.io.IOException;
> import java.util.ArrayList;
> import java.util.Collection;
> import java.util.Collections;
> import java.util.Iterator;
> import java.util.List;
>
>
> /**
> * This sample class demonstrates how to plug-in a new workbench view. The view shows data obtained
> * from the model. The sample creates a dummy model on the fly, but a real implementation would
> * connect to the model available either in this or another plug-in (e.g. the workspace). The view
> * is connected to the model using a content provider.
> * <p>
> * The view uses a label provider to define how model objects should be presented in the view. Each
> * view can present the same model objects using different labels and icons, if needed.
> * Alternatively, a single label provider can be shared between views in order to ensure that
> * objects of the same type are presented in the same way everywhere.
> * <p>
> */
>
> public class ProStepperView extends ViewPart implements IEditingDomainProvider, ISelectionProvider,
> IMenuListener, IViewerProvider
> {
>
> /**
> * The constructor.
> */
> public ProStepperView()
> {
> // Create an adapter factory that yields item providers.
> List factories = new ArrayList();
> factories.add(new ResourceItemProviderAdapterFactory());
> factories.add(new LibraryItemProviderAdapterFactory());
> factories.add(new ReflectiveItemProviderAdapterFactory());
>
> adapterFactory = new ComposedAdapterFactory(factories);
>
> // Create the command stack that will notify this editor as commands are executed.
> BasicCommandStack commandStack = new BasicCommandStack();
>
> // Create the editing domain with a special command stack.
> editingDomain = new AdapterFactoryEditingDomain(adapterFactory, commandStack);
> resourceSet = editingDomain.getResourceSet();
>
> URI uri = URI.createPlatformResourceURI("test/My.library");
> Resource resource = resourceSet.createResource(uri);
>
> try
> {
> resource.load(Collections.EMPTY_MAP);
> }
> catch (IOException ex)
> {
> ex.printStackTrace();
> }
> }
>
> /**
> * This is a callback that will allow us to create the viewer and initialize it.
> */
> public void createPartControl(Composite parent)
> {
> viewer = new TreeViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
> drillDownAdapter = new DrillDownAdapter(viewer);
>
> viewer.setContentProvider(new AdapterFactoryContentProvider(adapterFactory));
> viewer.setLabelProvider(new AdapterFactoryLabelProvider(adapterFactory));
> viewer.setSorter(new NameSorter());
> viewer.setInput(resourceSet);
>
> createContextMenuFor(viewer);
> }
>
> /**
> * This creates a context menu for the viewer and adds a listener as well registering the menu for extension.
> * <!-- begin-user-doc -->
> * <!-- end-user-doc -->
> * @generated
> */
> protected void createContextMenuFor(TreeViewer viewer)
> {
> MenuManager contextMenu = new MenuManager("#PopUp");
> contextMenu.add(new Separator("additions"));
> contextMenu.setRemoveAllWhenShown(true);
> contextMenu.addMenuListener(this);
> Menu menu = contextMenu.createContextMenu(viewer.getControl());
> viewer.getControl().setMenu(menu);
> getSite().registerContextMenu(contextMenu, viewer);
>
> int dndOperations = DND.DROP_COPY | DND.DROP_MOVE | DND.DROP_LINK;
> Transfer[] transfers = new Transfer[] { LocalTransfer.getInstance()};
> viewer.addDragSupport(dndOperations, transfers, new ViewerDragAdapter(viewer));
> viewer.addDropSupport(dndOperations, transfers, new EditingDomainViewerDropAdapter(
> editingDomain, viewer));
> }
>
> /**
> * Passing the focus request to the viewer's control.
> */
> public void setFocus()
> {
> viewer.getControl().setFocus();
> }
>
>
> class NameSorter extends ViewerSorter
> {
> }
>
> protected TreeViewer viewer;
>
> protected DrillDownAdapter drillDownAdapter;
>
> protected Action action1;
>
> protected Action action2;
>
> protected Action doubleClickAction;
>
> protected ComposedAdapterFactory adapterFactory;
>
> protected AdapterFactoryEditingDomain editingDomain;
>
> protected ResourceSet resourceSet;
>
> protected PropertySheetPage propertySheetPage;
>
> /**
> * This keeps track of the selection of the editor as a whole.
> */
> protected ISelection viewerSelection;
>
> /**
> * This keeps track of all the {@link org.eclipse.jface.viewers.ISelectionChangedListener}s that
> * are listening to this editor.
> */
> protected Collection selectionChangedListeners = new ArrayList();
>
> /**
> * This returns the editing domain as required by the {@link IEditingDomainProvider}interface.
> * This is important for implementing the static methods of {@link AdapterFactoryEditingDomain}
> * and for supporting {@link org.eclipse.emf.edit.ui.action.CommandAction}.
> */
> public EditingDomain getEditingDomain()
> {
> return editingDomain;
> }
>
> /**
> * This implements {@link org.eclipse.jface.viewers.ISelectionProvider}.
> */
> public void addSelectionChangedListener(ISelectionChangedListener listener)
> {
> selectionChangedListeners.add(listener);
> }
>
> /**
> * This implements {@link org.eclipse.jface.viewers.ISelectionProvider}to return this editor's
> * overall selection.
> */
> public ISelection getSelection()
> {
> return viewerSelection;
> }
>
> /**
> * This implements {@link org.eclipse.jface.viewers.ISelectionProvider}.
> */
> public void removeSelectionChangedListener(ISelectionChangedListener listener)
> {
> selectionChangedListeners.remove(listener);
> }
>
> /**
> * This implements {@link org.eclipse.jface.viewers.ISelectionProvider}to set this editor's
> * overall selection. Calling this result will notify the listeners.
> */
> public void setSelection(ISelection selection)
> {
> viewerSelection = selection;
> for (Iterator listeners = selectionChangedListeners.iterator(); listeners.hasNext();)
> {
> ISelectionChangedListener listener = (ISelectionChangedListener) listeners.next();
> listener.selectionChanged(new SelectionChangedEvent(this, selection));
> }
> //setStatusLineManager(selection);
> }
>
> public void menuAboutToShow(IMenuManager manager)
> {
> // TODO Auto-generated method stub
>
> }
>
> public Viewer getViewer()
> {
> // TODO Auto-generated method stub
> return viewer;
> }
>
> }
>
> /eike
>
>
Re: edit a model in an eclipse view [message #385006 is a reply to message #384994] Wed, 12 May 2004 04:34 Go to previous messageGo to next message
Eike Stepper is currently offline Eike Stepper
Messages: 5252
Registered: July 2009
Senior Member
john,

thanks for these more encouraging words ;-))

would you mind sharing your viewpart-code?
if i could spare the time of re-inventing the wheel,
i'd rather try to make some jet templates out of it
(and share it with the group of course).

/eike

"John Howard" <john.howard9@btinternet.com> schrieb im Newsbeitrag news:c7r3ov$7l2$1@eclipse.org...
> I had to do this for a project I was working on and although fiddly I
> don't remember it being that difficult. I basically took the generated
> Editor and generated ActionBarContributor and modified these to get the
> view working. e.g. the Editor code extends ViewPart instead of
> MultiPageEditorPart. I think in the end it took a couple of days to
> sort out the issues. The main problem with editing the model in this
> way is tracking changes and making sure everything is saved. Eclipse
> handles all this for editors, but not for views.
>
> John.
>
> Eike Stepper wrote:
>
> > i'd like to edit a model in an eclipse view and
> > started with the "new plug-in project" wizard.
> >
> > i managed to replace the wizard's sample model
> > with the emf model from a resource by copying
> > some code from the emf generated editor to the
> > wizard generated view.
> >
> > because of differences between an editor's and a
> > view's api, i was not able to copy some methods.
> > when running a run-time workbench, the model
> > is shown properly, but
> >
> > 1) there is no context menu
> > 2) the command framework does not work,
> > moving and deleting has no effect
> > 3) the properties view doesn't show anything
> >
> > i've browsed the web and the newsgroup, but
> > couldn't find example code. don't you think, it
> > was nice to have a "generate View Code"
> > option in the genmodel?
> >
> > here is my code:
> >
> > package prototyping.views.views;
> >
> >
> > import org.eclipse.emf.common.command.BasicCommandStack;
> > import org.eclipse.emf.common.ui.viewer.IViewerProvider;
> > import org.eclipse.emf.common.util.URI;
> > import org.eclipse.emf.ecore.resource.Resource;
> > import org.eclipse.emf.ecore.resource.ResourceSet;
> > import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain;
> > import org.eclipse.emf.edit.domain.EditingDomain;
> > import org.eclipse.emf.edit.domain.IEditingDomainProvider;
> > import org.eclipse.emf.edit.provider.ComposedAdapterFactory;
> > import org.eclipse.emf.edit.provider.ReflectiveItemProviderAdapterF actory;
> > import org.eclipse.emf.edit.provider.resource.ResourceItemProviderA dapterFactory;
> > import org.eclipse.emf.edit.ui.dnd.EditingDomainViewerDropAdapter;
> > import org.eclipse.emf.edit.ui.dnd.LocalTransfer;
> > import org.eclipse.emf.edit.ui.dnd.ViewerDragAdapter;
> > import org.eclipse.emf.edit.ui.provider.AdapterFactoryContentProvid er;
> > import org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider ;
> > import org.eclipse.jface.action.Action;
> > import org.eclipse.jface.action.IMenuListener;
> > import org.eclipse.jface.action.IMenuManager;
> > import org.eclipse.jface.action.MenuManager;
> > import org.eclipse.jface.action.Separator;
> > import org.eclipse.jface.viewers.ISelection;
> > import org.eclipse.jface.viewers.ISelectionChangedListener;
> > import org.eclipse.jface.viewers.ISelectionProvider;
> > import org.eclipse.jface.viewers.SelectionChangedEvent;
> > import org.eclipse.jface.viewers.TreeViewer;
> > import org.eclipse.jface.viewers.Viewer;
> > import org.eclipse.jface.viewers.ViewerSorter;
> > import org.eclipse.swt.SWT;
> > import org.eclipse.swt.dnd.DND;
> > import org.eclipse.swt.dnd.Transfer;
> > import org.eclipse.swt.widgets.Composite;
> > import org.eclipse.swt.widgets.Menu;
> > import org.eclipse.ui.part.DrillDownAdapter;
> > import org.eclipse.ui.part.ViewPart;
> > import org.eclipse.ui.views.properties.PropertySheetPage;
> >
> > import prototyping.views.model.library.provider.LibraryItemProvider AdapterFactory;
> >
> > import java.io.IOException;
> > import java.util.ArrayList;
> > import java.util.Collection;
> > import java.util.Collections;
> > import java.util.Iterator;
> > import java.util.List;
> >
> >
> > /**
> > * This sample class demonstrates how to plug-in a new workbench view. The view shows data obtained
> > * from the model. The sample creates a dummy model on the fly, but a real implementation would
> > * connect to the model available either in this or another plug-in (e.g. the workspace). The view
> > * is connected to the model using a content provider.
> > * <p>
> > * The view uses a label provider to define how model objects should be presented in the view. Each
> > * view can present the same model objects using different labels and icons, if needed.
> > * Alternatively, a single label provider can be shared between views in order to ensure that
> > * objects of the same type are presented in the same way everywhere.
> > * <p>
> > */
> >
> > public class ProStepperView extends ViewPart implements IEditingDomainProvider, ISelectionProvider,
> > IMenuListener, IViewerProvider
> > {
> >
> > /**
> > * The constructor.
> > */
> > public ProStepperView()
> > {
> > // Create an adapter factory that yields item providers.
> > List factories = new ArrayList();
> > factories.add(new ResourceItemProviderAdapterFactory());
> > factories.add(new LibraryItemProviderAdapterFactory());
> > factories.add(new ReflectiveItemProviderAdapterFactory());
> >
> > adapterFactory = new ComposedAdapterFactory(factories);
> >
> > // Create the command stack that will notify this editor as commands are executed.
> > BasicCommandStack commandStack = new BasicCommandStack();
> >
> > // Create the editing domain with a special command stack.
> > editingDomain = new AdapterFactoryEditingDomain(adapterFactory, commandStack);
> > resourceSet = editingDomain.getResourceSet();
> >
> > URI uri = URI.createPlatformResourceURI("test/My.library");
> > Resource resource = resourceSet.createResource(uri);
> >
> > try
> > {
> > resource.load(Collections.EMPTY_MAP);
> > }
> > catch (IOException ex)
> > {
> > ex.printStackTrace();
> > }
> > }
> >
> > /**
> > * This is a callback that will allow us to create the viewer and initialize it.
> > */
> > public void createPartControl(Composite parent)
> > {
> > viewer = new TreeViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
> > drillDownAdapter = new DrillDownAdapter(viewer);
> >
> > viewer.setContentProvider(new AdapterFactoryContentProvider(adapterFactory));
> > viewer.setLabelProvider(new AdapterFactoryLabelProvider(adapterFactory));
> > viewer.setSorter(new NameSorter());
> > viewer.setInput(resourceSet);
> >
> > createContextMenuFor(viewer);
> > }
> >
> > /**
> > * This creates a context menu for the viewer and adds a listener as well registering the menu for extension.
> > * <!-- begin-user-doc -->
> > * <!-- end-user-doc -->
> > * @generated
> > */
> > protected void createContextMenuFor(TreeViewer viewer)
> > {
> > MenuManager contextMenu = new MenuManager("#PopUp");
> > contextMenu.add(new Separator("additions"));
> > contextMenu.setRemoveAllWhenShown(true);
> > contextMenu.addMenuListener(this);
> > Menu menu = contextMenu.createContextMenu(viewer.getControl());
> > viewer.getControl().setMenu(menu);
> > getSite().registerContextMenu(contextMenu, viewer);
> >
> > int dndOperations = DND.DROP_COPY | DND.DROP_MOVE | DND.DROP_LINK;
> > Transfer[] transfers = new Transfer[] { LocalTransfer.getInstance()};
> > viewer.addDragSupport(dndOperations, transfers, new ViewerDragAdapter(viewer));
> > viewer.addDropSupport(dndOperations, transfers, new EditingDomainViewerDropAdapter(
> > editingDomain, viewer));
> > }
> >
> > /**
> > * Passing the focus request to the viewer's control.
> > */
> > public void setFocus()
> > {
> > viewer.getControl().setFocus();
> > }
> >
> >
> > class NameSorter extends ViewerSorter
> > {
> > }
> >
> > protected TreeViewer viewer;
> >
> > protected DrillDownAdapter drillDownAdapter;
> >
> > protected Action action1;
> >
> > protected Action action2;
> >
> > protected Action doubleClickAction;
> >
> > protected ComposedAdapterFactory adapterFactory;
> >
> > protected AdapterFactoryEditingDomain editingDomain;
> >
> > protected ResourceSet resourceSet;
> >
> > protected PropertySheetPage propertySheetPage;
> >
> > /**
> > * This keeps track of the selection of the editor as a whole.
> > */
> > protected ISelection viewerSelection;
> >
> > /**
> > * This keeps track of all the {@link org.eclipse.jface.viewers.ISelectionChangedListener}s that
> > * are listening to this editor.
> > */
> > protected Collection selectionChangedListeners = new ArrayList();
> >
> > /**
> > * This returns the editing domain as required by the {@link IEditingDomainProvider}interface.
> > * This is important for implementing the static methods of {@link AdapterFactoryEditingDomain}
> > * and for supporting {@link org.eclipse.emf.edit.ui.action.CommandAction}.
> > */
> > public EditingDomain getEditingDomain()
> > {
> > return editingDomain;
> > }
> >
> > /**
> > * This implements {@link org.eclipse.jface.viewers.ISelectionProvider}.
> > */
> > public void addSelectionChangedListener(ISelectionChangedListener listener)
> > {
> > selectionChangedListeners.add(listener);
> > }
> >
> > /**
> > * This implements {@link org.eclipse.jface.viewers.ISelectionProvider}to return this editor's
> > * overall selection.
> > */
> > public ISelection getSelection()
> > {
> > return viewerSelection;
> > }
> >
> > /**
> > * This implements {@link org.eclipse.jface.viewers.ISelectionProvider}.
> > */
> > public void removeSelectionChangedListener(ISelectionChangedListener listener)
> > {
> > selectionChangedListeners.remove(listener);
> > }
> >
> > /**
> > * This implements {@link org.eclipse.jface.viewers.ISelectionProvider}to set this editor's
> > * overall selection. Calling this result will notify the listeners.
> > */
> > public void setSelection(ISelection selection)
> > {
> > viewerSelection = selection;
> > for (Iterator listeners = selectionChangedListeners.iterator(); listeners.hasNext();)
> > {
> > ISelectionChangedListener listener = (ISelectionChangedListener) listeners.next();
> > listener.selectionChanged(new SelectionChangedEvent(this, selection));
> > }
> > //setStatusLineManager(selection);
> > }
> >
> > public void menuAboutToShow(IMenuManager manager)
> > {
> > // TODO Auto-generated method stub
> >
> > }
> >
> > public Viewer getViewer()
> > {
> > // TODO Auto-generated method stub
> > return viewer;
> > }
> >
> > }
> >
> > /eike
> >
> >
Re: edit a model in an eclipse view [message #385022 is a reply to message #384990] Thu, 13 May 2004 11:13 Go to previous messageGo to next message
Eike Stepper is currently offline Eike Stepper
Messages: 5252
Registered: July 2009
Senior Member
ed,

with some help from john i managed to set up a
full functional view. unfortunately i had to modify
some classes in org.eclipse.emf.edit.ui.action to
also support IViewPart in addition to IEditorPart.

i have simply changed IEditorPart into IWorkbenchPart.
do you think, these changes could be merged into the
emf distribution?

/eike


"Ed Merks" <merks@ca.ibm.com> schrieb im Newsbeitrag news:40A0C8B8.4BDD79F3@ca.ibm.com...
> Eike,
>
> The list of nice to haves is endless. Generating a view that supports editing opens up a whole set of issues that
> we can't address anytime soon.
Re: edit a model in an eclipse view [message #385023 is a reply to message #385022] Thu, 13 May 2004 11:17 Go to previous messageGo to next message
Ed Merks is currently offline Ed Merks
Messages: 25227
Registered: July 2009
Senior Member
--------------A1EF079FCDB56FC456615AB4
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Eike,

There are quite a few uses of that:

action/CommandAction.java
action/CopyAction.java
action/CreateChildAction.java
action/CreateSiblingAction.java
action/CutAction.java
action/DelegatingCommandAction.java
action/DeleteAction.java
action/EditingDomainActionBarContributor.java
action/LoadResourceAction.java
action/PasteAction.java
action/RedoAction.java
action/StaticSelectionCommandAction.java
action/UndoAction.java
action/ValidateAction.java

Did you have to change them all?


Eike Stepper wrote:

> ed,
>
> with some help from john i managed to set up a
> full functional view. unfortunately i had to modify
> some classes in org.eclipse.emf.edit.ui.action to
> also support IViewPart in addition to IEditorPart.
>
> i have simply changed IEditorPart into IWorkbenchPart.
> do you think, these changes could be merged into the
> emf distribution?
>
> /eike
>
> "Ed Merks" <merks@ca.ibm.com> schrieb im Newsbeitrag news:40A0C8B8.4BDD79F3@ca.ibm.com...
> > Eike,
> >
> > The list of nice to haves is endless. Generating a view that supports editing opens up a whole set of issues that
> > we can't address anytime soon.

--------------A1EF079FCDB56FC456615AB4
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit

<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
Eike,
<p>There are quite a few uses of that:
<blockquote>action/CommandAction.java
<br>action/CopyAction.java
<br>action/CreateChildAction.java
<br>action/CreateSiblingAction.java
<br>action/CutAction.java
<br>action/DelegatingCommandAction.java
<br>action/DeleteAction.java
<br>action/EditingDomainActionBarContributor.java
<br>action/LoadResourceAction.java
<br>action/PasteAction.java
<br>action/RedoAction.java
<br>action/StaticSelectionCommandAction.java
<br>action/UndoAction.java
<br>action/ValidateAction.java</blockquote>
Did you have to change them all?
<br>&nbsp;
<p>Eike Stepper wrote:
<blockquote TYPE=CITE>ed,
<p>with some help from john i managed to set up a
<br>full functional view. unfortunately i had to modify
<br>some classes in org.eclipse.emf.edit.ui.action to
<br>also support IViewPart in addition to IEditorPart.
<p>i have simply changed IEditorPart into IWorkbenchPart.
<br>do you think, these changes could be merged into the
<br>emf distribution?
<p>/eike
<p>"Ed Merks" &lt;merks@ca.ibm.com> schrieb im Newsbeitrag <a href="news:40A0C8B8.4BDD79F3@ca.ibm.com">news:40A0C8B8.4BDD79F3@ca.ibm.com</a>...
<br>> Eike,
<br>>
<br>> The list of nice to haves is endless. Generating a view that supports
editing opens up a whole set of issues that
<br>> we can't address anytime soon.</blockquote>
</html>

--------------A1EF079FCDB56FC456615AB4--
Re: edit a model in an eclipse view [message #385024 is a reply to message #385023] Thu, 13 May 2004 11:26 Go to previous messageGo to next message
Eike Stepper is currently offline Eike Stepper
Messages: 5252
Registered: July 2009
Senior Member
ed,

no, until now i have only changed CreateChildAction,
CreateSiblingAction and StaticSelectionCommandAction,
but the view is quite new and might use more actions in
the future. is it a question of effort or does it have negative
side effects?

the EditingDomainActionBarContributor will not be touched,
since it is editor-specific. (btw: can you imagine, why a view
has no ActionBarContributor? is the multiple-instances-per-view
feature too new?)

/eike


"Ed Merks" <merks@ca.ibm.com> schrieb im Newsbeitrag news:40A39198.73A42F88@ca.ibm.com...
Eike,
There are quite a few uses of that:
action/CommandAction.java
action/CopyAction.java
action/CreateChildAction.java
action/CreateSiblingAction.java
action/CutAction.java
action/DelegatingCommandAction.java
action/DeleteAction.java
action/EditingDomainActionBarContributor.java
action/LoadResourceAction.java
action/PasteAction.java
action/RedoAction.java
action/StaticSelectionCommandAction.java
action/UndoAction.java
action/ValidateAction.java
Did you have to change them all?
Re: edit a model in an eclipse view [message #385025 is a reply to message #385024] Thu, 13 May 2004 11:45 Go to previous messageGo to next message
Ed Merks is currently offline Ed Merks
Messages: 25227
Registered: July 2009
Senior Member
Eike,

Yes, I'm concerned about making breaking changes. It seems to me that all the actions would
potentially be desired in the view. Can you provide a simple example view part and show what
you changed in the framework to make it work? Then I'll give it some more thought. It does
sound useful, but I don't really understand how editing in views without an editor all hangs
together, e.g., how do you do a save?


Eike Stepper wrote:

> ed,
>
> no, until now i have only changed CreateChildAction,
> CreateSiblingAction and StaticSelectionCommandAction,
> but the view is quite new and might use more actions in
> the future. is it a question of effort or does it have negative
> side effects?
>
> the EditingDomainActionBarContributor will not be touched,
> since it is editor-specific. (btw: can you imagine, why a view
> has no ActionBarContributor? is the multiple-instances-per-view
> feature too new?)
>
> /eike
>
> "Ed Merks" <merks@ca.ibm.com> schrieb im Newsbeitrag news:40A39198.73A42F88@ca.ibm.com...
> Eike,
> There are quite a few uses of that:
> action/CommandAction.java
> action/CopyAction.java
> action/CreateChildAction.java
> action/CreateSiblingAction.java
> action/CutAction.java
> action/DelegatingCommandAction.java
> action/DeleteAction.java
> action/EditingDomainActionBarContributor.java
> action/LoadResourceAction.java
> action/PasteAction.java
> action/RedoAction.java
> action/StaticSelectionCommandAction.java
> action/UndoAction.java
> action/ValidateAction.java
> Did you have to change them all?
Re: edit a model in an eclipse view [message #385026 is a reply to message #385025] Thu, 13 May 2004 12:11 Go to previous message
Eike Stepper is currently offline Eike Stepper
Messages: 5252
Registered: July 2009
Senior Member
ed,

i've attached three files. there's a ViewActionBarContributor that
would have to go into org.eclipse.emf.edit.ui.actions, too (for me).
it is extended by a special contributor (much like the EditingDomainActionBarContributor).

i have the feeling that these contributors simply came from
migrating the generated editor to a view, but now with multiple
instances of a view it seems a good idea anyway.

i'm quite new to the eclipse ui api, so if anyone would review
the viewpart and the contributor classes, i could try to make
jet templates out of them.

i will have to give saving more thoughts. for my application
i plan to present a save question to the user each time she/he
changes the selection. additionally the property sheet will have
a save button and dialogs will save on ok. but i find it interesting
to think about more general flows and how to implement them
(this way i could improve my understnding of the eclipse api).

/eike


"Ed Merks" <merks@ca.ibm.com> schrieb im Newsbeitrag news:40A39808.C252EBE1@ca.ibm.com...
> Eike,
>
> Yes, I'm concerned about making breaking changes. It seems to me that all the actions would
> potentially be desired in the view. Can you provide a simple example view part and show what
> you changed in the framework to make it work? Then I'll give it some more thought. It does
> sound useful, but I don't really understand how editing in views without an editor all hangs
> together, e.g., how do you do a save?




Previous Topic:EMF framework and generated plugins
Next Topic:Thoughts on JET
Goto Forum:
  


Current Time: Tue Oct 08 08:05:55 EDT 2013

Powered by FUDForum. Page generated in 0.02423 seconds