Skip to content
This repository has been archived by the owner on Jan 20, 2024. It is now read-only.

Commit

Permalink
- Undo (Working, but text is not updated, would need to find the menu
Browse files Browse the repository at this point in the history
entries to do so). 
- Select All
  • Loading branch information
Christophe Bouhier committed Apr 12, 2013
1 parent 7400a4a commit b57b36f
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 26 deletions.
3 changes: 2 additions & 1 deletion bundles/org.eclipse.e4mf.edit.ui/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ Require-Bundle: javax.inject;bundle-version="1.0.0",
org.eclipse.e4.core.di;bundle-version="1.3.0",
org.eclipse.e4.ui.services;bundle-version="1.0.0",
org.eclipse.e4.core.contexts;bundle-version="1.3.0",
org.eclipse.e4.tools.properties;bundle-version="1.0.0"
org.eclipse.e4.tools.properties;bundle-version="1.0.0",
org.eclipse.e4.core.commands;bundle-version="0.10.1"
Eclipse-LazyStart: true
Bundle-ActivationPolicy: lazy
Service-Component: OSGI-INF/editingdomaincontribution.xml,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
package org.eclipse.e4mf.edit.ui.e4.action;

import java.util.ArrayList;
import java.util.List;

import javax.inject.Named;

import org.eclipse.e4.core.di.annotations.Execute;
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
import org.eclipse.e4.ui.services.IServiceConstants;
import org.eclipse.e4mf.common.ui.viewer.IViewerProvider;
import org.eclipse.emf.common.notify.Notifier;
import org.eclipse.emf.common.util.TreeIterator;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.viewers.Viewer;

@SuppressWarnings("restriction")
Expand All @@ -25,24 +18,10 @@ public void execute(@Named(IServiceConstants.ACTIVE_PART) MPart part ) {
// The contribution object is our editor.
if(part.getObject() != null && part.getObject() instanceof IViewerProvider){
Viewer v = ((IViewerProvider) part.getObject()).getViewer();

Object input = v.getInput();


List<Object> toSelect = new ArrayList<Object>();

// Flatten the input to set the selection.
if(input instanceof ResourceSet){
TreeIterator<Notifier> allContents = ((ResourceSet) input).getAllContents();
while( allContents.hasNext() ){
Notifier next = allContents.next();
toSelect.add(next);
}
if(v instanceof TreeViewer){
((TreeViewer) v).getTree().selectAll();
// v.setSelection(v.getSelection(), true);
}
IStructuredSelection all = new StructuredSelection(toSelect);
v.setSelection(all, true);
}

}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,69 @@
package org.eclipse.e4mf.edit.ui.e4.action;

import javax.inject.Inject;

import org.eclipse.e4.core.commands.ECommandService;
import org.eclipse.e4.core.di.annotations.CanExecute;
import org.eclipse.e4.core.di.annotations.Execute;
import org.eclipse.e4.core.di.annotations.Optional;
import org.eclipse.e4mf.edit.ui.EMFEditUIPlugin;
import org.eclipse.emf.common.command.Command;
import org.eclipse.emf.edit.domain.EditingDomain;

@SuppressWarnings("restriction")
public class UndoHandler {

private static final String UNDO_COMMAND_ID = "org.eclipse.ui.edit.undo";

@Inject
@Optional
protected EditingDomain domain;

@Inject
@Optional
private ECommandService commandService;

@CanExecute
public boolean canExecute() {

// org.eclipse.core.commands.Command command = commandService
// .getCommand(UNDO_COMMAND_ID);

boolean result = domain.getCommandStack().canUndo();

String newText = null;
String newDescription = null;

Command undoCommand = domain.getCommandStack().getUndoCommand();
if (undoCommand != null && undoCommand.getLabel() != null) {
newText = EMFEditUIPlugin.INSTANCE.getString("_UI_Undo_menu_item",
new Object[] { undoCommand.getLabel() });
// setText();
} else {
newText = EMFEditUIPlugin.INSTANCE.getString("_UI_Undo_menu_item",
new Object[] { "" });
// setText();
}

if (undoCommand != null && undoCommand.getDescription() != null) {
newDescription = EMFEditUIPlugin.INSTANCE.getString(
"_UI_Undo_menu_item_description",
new Object[] { undoCommand.getDescription() });
// setDescription();
} else {
newDescription = EMFEditUIPlugin.INSTANCE
.getString("_UI_Undo_menu_item_simple_description");
// setDescription();
}

System.out.println("Undo Handler: debug: " + newText + newDescription);

return result;
}

@Execute
public void execute() {
domain.getCommandStack().undo();
}

}
1 change: 1 addition & 0 deletions bundles/org.eclipse.e4mf.edit.ui/xmi/fragment.e4xmi
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,6 @@
<elements xsi:type="commands:Handler" xmi:id="_zkTmkKFKEeKWZrq3lrURUg" elementId="org.eclipse.e4mf.edit.ui.handler.cut" contributionURI="bundleclass://org.eclipse.e4mf.edit.ui/org.eclipse.e4mf.edit.ui.e4.action.CutHandler" command="_jQsFcKBKEeK9y_k9g5Mqqg"/>
<elements xsi:type="commands:Handler" xmi:id="_EPqB0KN1EeKnq8UUfCP01A" elementId="org.eclipse.e4mf.edit.ui.handler.delete" contributionURI="bundleclass://org.eclipse.e4mf.edit.ui/org.eclipse.e4mf.edit.ui.e4.action.DeleteHandler" command="_kEh9MKBKEeK9y_k9g5Mqqg"/>
<elements xsi:type="commands:Handler" xmi:id="_yWYO8KN7EeKnq8UUfCP01A" elementId="org.eclipse.e4mf.edit.ui.handler.0" contributionURI="bundleclass://org.eclipse.e4mf.edit.ui/org.eclipse.e4mf.edit.ui.e4.action.SelectAllHandler" command="_kSvYUKBKEeK9y_k9g5Mqqg"/>
<elements xsi:type="commands:Handler" xmi:id="__1jTYKOHEeKvgomZMld7dQ" elementId="org.eclipse.e4mf.edit.ui.handler.undo" contributionURI="bundleclass://org.eclipse.e4mf.edit.ui/org.eclipse.e4mf.edit.ui.e4.action.UndoHandler" command="_h1FDEKBKEeK9y_k9g5Mqqg"/>
</fragments>
</fragment:ModelFragments>

0 comments on commit b57b36f

Please sign in to comment.