Révision 3711

TXM/trunk/bundles/org.txm.rcp/src/main/java/org/txm/rcp/editors/SWTResourceManager.java (revision 3711)
434 434
		Integer key = Integer.valueOf(id);
435 435
		Cursor cursor = m_idToCursorMap.get(key);
436 436
		if (cursor == null) {
437
			cursor = new Cursor(Display.getDefault(), id);
437
			cursor = Display.getDefault().getSystemCursor(SWT.CURSOR_SIZENS);
438 438
			m_idToCursorMap.put(key, cursor);
439 439
		}
440 440
		return cursor;
TXM/trunk/bundles/org.txm.rcp/src/main/java/org/txm/rcp/commands/CleanPerspective.java (revision 3711)
2 2

  
3 3
import org.eclipse.core.commands.AbstractHandler;
4 4
import org.eclipse.core.commands.ExecutionEvent;
5
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
6
import org.eclipse.e4.ui.workbench.modeling.EModelService;
7
import org.eclipse.jface.dialogs.MessageDialog;
5 8
import org.eclipse.ui.IEditorReference;
6
import org.eclipse.ui.IViewReference;
9
import org.eclipse.ui.IPerspectiveDescriptor;
7 10
import org.eclipse.ui.IWorkbenchPage;
8 11
import org.eclipse.ui.IWorkbenchPart;
12
import org.eclipse.ui.IWorkbenchWindow;
9 13
import org.eclipse.ui.PlatformUI;
10 14
import org.eclipse.ui.handlers.HandlerUtil;
11
import org.eclipse.ui.handlers.IHandlerService;
12
import org.txm.core.messages.TXMCoreMessages;
13
import org.txm.rcp.messages.TXMUIMessages;
14
import org.txm.utils.logger.Log;
15
import org.eclipse.ui.internal.Workbench;
16
import org.eclipse.ui.internal.registry.PerspectiveDescriptor;
17
import org.eclipse.ui.internal.registry.PerspectiveRegistry;
15 18

  
16 19
public class CleanPerspective extends AbstractHandler {
20

  
17 21
	/* (non-Javadoc)
18 22
	 * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
19 23
	 */
20 24
	@Override
21 25
	public Object execute(ExecutionEvent event) {
26
		if (MessageDialog.openConfirm(HandlerUtil.getActiveShell(event), "Reset perspective", "This will will restore the views and close the additional views of the current perspective. Continue?" )) {
27
			reset(event, true, false);
28
		}
29
		return null;
30
	}
31

  
32
	public static void reset(ExecutionEvent event, boolean perspective, boolean parts) {
22 33
		//System.out.println("clean perspective");
23
		IWorkbenchPart part = HandlerUtil.getActivePart(event);
24
		//System.out.println("part: "+part.getTitle());
25
		IWorkbenchPage page = part.getSite().getPage();
26
		//System.out.println("page: "+page.getLabel());
27
		if (page.isEditorAreaVisible()) {
28
			//System.out.println(" page is visible");
34

  
35
		IWorkbenchPage page;
36
		if (event == null) {
37
			IWorkbenchPart part = HandlerUtil.getActivePart(event);
38
			page = part.getSite().getPage();
39
		} else {
40
			page = Workbench.getInstance().getActiveWorkbenchWindow().getActivePage();
41
		}
42

  
43
		if (page == null) return;
44

  
45
		if (parts) {
29 46
			IEditorReference[] editors = page.getEditorReferences();
30
			IViewReference[] views = page.getViewReferences();
31
			if (editors.length == 0 && views.length == 0) {
32
				//System.out.println("  no editor");
33
				page.setEditorAreaVisible(false);
34
			} else {
35
				//System.out.println("  editors: "+editors.length);
47
			for (IEditorReference er : editors) {
48
				page.closeEditor(er.getEditor(false), false);
36 49
			}
37
		} else {
38
			//System.out.println(" page is not visible");
39 50
		}
40 51
		
41
		IHandlerService handlerService = (IHandlerService) PlatformUI.getWorkbench().getService(IHandlerService.class);
42
		if (handlerService != null) {
43
			try {
44
				handlerService.executeCommand("org.eclipse.ui.window.resetPerspective", null); //$NON-NLS-1$
45
			} catch (Exception e) {
46
				System.out.println(TXMCoreMessages.bind(TXMUIMessages.errorWhileCallingOrgeclipseuiwindowresetPerspectiveColon, e));
47
				Log.printStackTrace(e);
52
		if (perspective) {
53
			IPerspectiveDescriptor descriptor = page.getPerspective();
54
			if (descriptor != null) {
55
				boolean offerRevertToBase = false;
56
				if (descriptor instanceof PerspectiveDescriptor) {
57
					PerspectiveDescriptor desc = (PerspectiveDescriptor) descriptor;
58
					offerRevertToBase = desc.isPredefined() && desc.hasCustomDefinition();
59
				}
60

  
61
				if (offerRevertToBase) {
62

  
63
					PerspectiveRegistry reg = (PerspectiveRegistry) PlatformUI.getWorkbench().getPerspectiveRegistry();
64
					reg.revertPerspective(descriptor);
65
				}
66
				page.resetPerspective();
48 67
			}
49
		} else {
50
			System.out.println(TXMUIMessages.errorWhileCleaningPerspectiveColonNoHandlerServiceFound);
51 68
		}
52
		
53
		return null;
69
		return;
54 70
	}
55 71
}
TXM/trunk/bundles/org.txm.rcp/src/main/java/org/txm/rcp/commands/CleanEditors.java (revision 3711)
1
package org.txm.rcp.commands;
2

  
3
import org.eclipse.core.commands.AbstractHandler;
4
import org.eclipse.core.commands.ExecutionEvent;
5
import org.eclipse.jface.dialogs.MessageDialog;
6
import org.eclipse.ui.handlers.HandlerUtil;
7

  
8
public class CleanEditors extends AbstractHandler {
9

  
10
	/* (non-Javadoc)
11
	 * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
12
	 */
13
	@Override
14
	public Object execute(ExecutionEvent event) {
15
		if (MessageDialog.openConfirm(HandlerUtil.getActiveShell(event), "Reset the window", "This will will close all editors all non saved changes will be lost. Continue?" )) {
16
			CleanPerspective.reset(event, false, true);
17
		}
18
		return null;
19
	}
20
}
0 21

  
TXM/trunk/bundles/org.txm.rcp/plugin.xml (revision 3711)
1292 1292
                  style="push">
1293 1293
            </command>
1294 1294
            <command
1295
                  commandId="org.txm.rcp.commands.CleanEditors"
1296
                  style="push">
1297
            </command>
1298
            <command
1295 1299
                  commandId="org.eclipse.ui.window.newWindow"
1296 1300
                  label="%command.label.157">
1297 1301
            </command>
......
2818 2822
            id="org.txm.rcp.commands.RecoverCorporaFromInstalls"
2819 2823
            name="Recover corpora">
2820 2824
      </command>
2825
      <command
2826
            defaultHandler="org.txm.rcp.commands.CleanEditors"
2827
            id="org.txm.rcp.commands.CleanEditors"
2828
            name="Close all editors">
2829
      </command>
2821 2830
   </extension>
2822 2831
   <extension
2823 2832
         id="commands"

Formats disponibles : Unified diff