Search in sources :

Example 1 with SaveablesList

use of org.eclipse.ui.internal.SaveablesList in project eclipse.platform.ui by eclipse-platform.

the class PropertySheet method createPartControl.

/**
 * The <code>PropertySheet</code> implementation of this
 * <code>IWorkbenchPart</code> method creates a <code>PageBook</code> control
 * with its default page showing.
 */
@Override
public void createPartControl(Composite parent) {
    super.createPartControl(parent);
    pinPropertySheetAction.addPropertyChangeListener(event -> {
        if (IAction.CHECKED.equals(event.getProperty())) {
            updateContentDescription();
            if (!isPinned()) {
                selectionChanged(currentPart, currentSelection);
            }
        }
    });
    IMenuManager menuManager = getViewSite().getActionBars().getMenuManager();
    menuManager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
    menuManager.add(pinPropertySheetAction);
    IToolBarManager toolBarManager = getViewSite().getActionBars().getToolBarManager();
    menuManager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
    toolBarManager.add(pinPropertySheetAction);
    ISaveablesLifecycleListener saveables = getSite().getService(ISaveablesLifecycleListener.class);
    if (saveables instanceof SaveablesList) {
        ((SaveablesList) saveables).addModelLifecycleListener(saveablesTracker);
    }
    getSite().getPage().getWorkbenchWindow().getWorkbench().getHelpSystem().setHelp(getPageBook(), IPropertiesHelpContextIds.PROPERTY_SHEET_VIEW);
}
Also used : IToolBarManager(org.eclipse.jface.action.IToolBarManager) SaveablesList(org.eclipse.ui.internal.SaveablesList) IMenuManager(org.eclipse.jface.action.IMenuManager) ISaveablesLifecycleListener(org.eclipse.ui.ISaveablesLifecycleListener) Separator(org.eclipse.jface.action.Separator)

Example 2 with SaveablesList

use of org.eclipse.ui.internal.SaveablesList in project eclipse.platform.ui by eclipse-platform.

the class SaveablesListTest method testPreclosePartsWithSaveOptions_DiscardAll.

@Test
public void testPreclosePartsWithSaveOptions_DiscardAll() throws Throwable {
    int total = 5;
    final IFile[] files = new IFile[total];
    IEditorPart[] editors = new IEditorPart[total];
    CallHistory[] callTraces = new CallHistory[total];
    MockEditorPart[] mocks = new MockEditorPart[total];
    List<IWorkbenchPart> parts = new ArrayList<>();
    proj = FileUtil.createProject("testOpenEditor");
    for (int i = 0; i < total; i++) {
        files[i] = FileUtil.createFile(i + ".mock2", proj);
    }
    SaveablesList saveablesList = (SaveablesList) PlatformUI.getWorkbench().getService(ISaveablesLifecycleListener.class);
    for (int i = 0; i < total; i++) {
        editors[i] = IDE.openEditor(page, files[i]);
        mocks[i] = (MockEditorPart) editors[i];
        mocks[i].setDirty(true);
        callTraces[i] = mocks[i].getCallHistory();
        parts.add(editors[i]);
    }
    Map<IWorkbenchPart, List<Saveable>> saveableMap = saveablesList.getSaveables(parts);
    Map<Saveable, Save> map = new LinkedHashMap<>();
    for (IWorkbenchPart part : parts) {
        List<Saveable> saveables = saveableMap.get(part);
        if (saveables != null) {
            for (Saveable saveable : saveables) {
                map.put(saveable, Save.NO);
            }
        }
    }
    assertEquals((saveablesList.preCloseParts(parts, false, true, fWin, map) != null), true);
    for (int i = 0; i < total; i++) {
        assertEquals(callTraces[i].contains("isDirty"), true);
        assertEquals(callTraces[i].contains("doSave"), false);
    }
}
Also used : Saveable(org.eclipse.ui.Saveable) IFile(org.eclipse.core.resources.IFile) ArrayList(java.util.ArrayList) IEditorPart(org.eclipse.ui.IEditorPart) ISaveablesLifecycleListener(org.eclipse.ui.ISaveablesLifecycleListener) LinkedHashMap(java.util.LinkedHashMap) CallHistory(org.eclipse.ui.tests.harness.util.CallHistory) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) SaveablesList(org.eclipse.ui.internal.SaveablesList) ArrayList(java.util.ArrayList) List(java.util.List) SaveablesList(org.eclipse.ui.internal.SaveablesList) Save(org.eclipse.e4.ui.workbench.modeling.ISaveHandler.Save) Test(org.junit.Test)

Example 3 with SaveablesList

use of org.eclipse.ui.internal.SaveablesList in project eclipse.platform.ui by eclipse-platform.

the class SaveablesListTest method testPreclosePartsWithSaveOptions_SaveAll.

@Test
public void testPreclosePartsWithSaveOptions_SaveAll() throws Throwable {
    int total = 5;
    final IFile[] files = new IFile[total];
    IEditorPart[] editors = new IEditorPart[total];
    CallHistory[] callTraces = new CallHistory[total];
    MockEditorPart[] mocks = new MockEditorPart[total];
    List<IWorkbenchPart> parts = new ArrayList<>();
    proj = FileUtil.createProject("testOpenEditor");
    for (int i = 0; i < total; i++) {
        files[i] = FileUtil.createFile(i + ".mock2", proj);
    }
    SaveablesList saveablesList = (SaveablesList) PlatformUI.getWorkbench().getService(ISaveablesLifecycleListener.class);
    for (int i = 0; i < total; i++) {
        editors[i] = IDE.openEditor(page, files[i]);
        mocks[i] = (MockEditorPart) editors[i];
        mocks[i].setDirty(true);
        callTraces[i] = mocks[i].getCallHistory();
        parts.add(editors[i]);
    }
    Map<IWorkbenchPart, List<Saveable>> saveableMap = saveablesList.getSaveables(parts);
    Map<Saveable, Save> map = new LinkedHashMap<>();
    for (IWorkbenchPart part : parts) {
        List<Saveable> saveables = saveableMap.get(part);
        if (saveables != null) {
            for (Saveable saveable : saveables) {
                map.put(saveable, Save.YES);
            }
        }
    }
    assertEquals((saveablesList.preCloseParts(parts, false, true, fWin, map) != null), true);
    for (int i = 0; i < total; i++) {
        assertEquals(callTraces[i].contains("isDirty"), true);
        assertEquals(callTraces[i].contains("doSave"), true);
        callTraces[i].clear();
    }
}
Also used : Saveable(org.eclipse.ui.Saveable) IFile(org.eclipse.core.resources.IFile) ArrayList(java.util.ArrayList) IEditorPart(org.eclipse.ui.IEditorPart) ISaveablesLifecycleListener(org.eclipse.ui.ISaveablesLifecycleListener) LinkedHashMap(java.util.LinkedHashMap) CallHistory(org.eclipse.ui.tests.harness.util.CallHistory) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) SaveablesList(org.eclipse.ui.internal.SaveablesList) ArrayList(java.util.ArrayList) List(java.util.List) SaveablesList(org.eclipse.ui.internal.SaveablesList) Save(org.eclipse.e4.ui.workbench.modeling.ISaveHandler.Save) Test(org.junit.Test)

Example 4 with SaveablesList

use of org.eclipse.ui.internal.SaveablesList in project eclipse.platform.ui by eclipse-platform.

the class SaveablesListTest method testPreclosePartsWithSaveOptions_SaveFew.

@Test
public void testPreclosePartsWithSaveOptions_SaveFew() throws Throwable {
    int total = 5;
    final IFile[] files = new IFile[total];
    IEditorPart[] editors = new IEditorPart[total];
    CallHistory[] callTraces = new CallHistory[total];
    MockEditorPart[] mocks = new MockEditorPart[total];
    List<IWorkbenchPart> parts = new ArrayList<>();
    proj = FileUtil.createProject("testOpenEditor");
    for (int i = 0; i < total; i++) {
        files[i] = FileUtil.createFile(i + ".mock2", proj);
    }
    SaveablesList saveablesList = (SaveablesList) PlatformUI.getWorkbench().getService(ISaveablesLifecycleListener.class);
    for (int i = 0; i < total; i++) {
        editors[i] = IDE.openEditor(page, files[i]);
        mocks[i] = (MockEditorPart) editors[i];
        if (i % 2 == 0) {
            mocks[i].setDirty(true);
        }
        callTraces[i] = mocks[i].getCallHistory();
        parts.add(editors[i]);
    }
    Map<IWorkbenchPart, List<Saveable>> saveableMap = saveablesList.getSaveables(parts);
    Map<Saveable, Save> map = new LinkedHashMap<>();
    int j = 0;
    for (IWorkbenchPart part : parts) {
        List<Saveable> saveables = saveableMap.get(part);
        if (saveables != null) {
            for (Saveable saveable : saveables) {
                if (j % 2 == 0) {
                    map.put(saveable, Save.YES);
                } else {
                    map.put(saveable, Save.NO);
                }
            }
        }
        j++;
    }
    assertEquals((saveablesList.preCloseParts(parts, false, true, fWin, map) != null), true);
    for (int i = 0; i < total; i++) {
        if (i % 2 == 0) {
            assertEquals(callTraces[i].contains("isDirty"), true);
            assertEquals(callTraces[i].contains("doSave"), true);
        } else {
            assertEquals(callTraces[i].contains("isDirty"), true);
            assertEquals(callTraces[i].contains("doSave"), false);
        }
    }
}
Also used : Saveable(org.eclipse.ui.Saveable) IFile(org.eclipse.core.resources.IFile) ArrayList(java.util.ArrayList) IEditorPart(org.eclipse.ui.IEditorPart) ISaveablesLifecycleListener(org.eclipse.ui.ISaveablesLifecycleListener) LinkedHashMap(java.util.LinkedHashMap) CallHistory(org.eclipse.ui.tests.harness.util.CallHistory) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) SaveablesList(org.eclipse.ui.internal.SaveablesList) ArrayList(java.util.ArrayList) List(java.util.List) SaveablesList(org.eclipse.ui.internal.SaveablesList) Save(org.eclipse.e4.ui.workbench.modeling.ISaveHandler.Save) Test(org.junit.Test)

Example 5 with SaveablesList

use of org.eclipse.ui.internal.SaveablesList in project eclipse.platform.ui by eclipse-platform.

the class WorkbenchEditorsDialog method closeItems.

/**
 * Closes the specified editors
 */
private void closeItems(TableItem[] items) {
    if (items.length == 0) {
        return;
    }
    // collect all instantiated editors that have been selected
    List<IWorkbenchPart> selectedEditors = new ArrayList<>();
    for (TableItem item : items) {
        Adapter e = (Adapter) item.getData();
        if (e.editorRef != null) {
            IWorkbenchPart part = e.editorRef.getPart(false);
            if (part != null) {
                selectedEditors.add(part);
            }
        }
    }
    SaveablesList saveablesList = (SaveablesList) window.getService(ISaveablesLifecycleListener.class);
    // prompt for save
    if (saveablesList.preCloseParts(selectedEditors, true, this, window) != null) {
        // close all editors
        for (TableItem item : items) {
            Adapter e = (Adapter) item.getData();
            e.close();
        }
        // update the list
        updateItems();
    }
}
Also used : IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) TableItem(org.eclipse.swt.widgets.TableItem) ArrayList(java.util.ArrayList) SaveablesList(org.eclipse.ui.internal.SaveablesList) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) SelectionListener.widgetSelectedAdapter(org.eclipse.swt.events.SelectionListener.widgetSelectedAdapter) ISaveablesLifecycleListener(org.eclipse.ui.ISaveablesLifecycleListener)

Aggregations

SaveablesList (org.eclipse.ui.internal.SaveablesList)9 ISaveablesLifecycleListener (org.eclipse.ui.ISaveablesLifecycleListener)8 Saveable (org.eclipse.ui.Saveable)5 ArrayList (java.util.ArrayList)4 IWorkbenchPart (org.eclipse.ui.IWorkbenchPart)4 LinkedHashMap (java.util.LinkedHashMap)3 List (java.util.List)3 IFile (org.eclipse.core.resources.IFile)3 Save (org.eclipse.e4.ui.workbench.modeling.ISaveHandler.Save)3 IEditorPart (org.eclipse.ui.IEditorPart)3 CallHistory (org.eclipse.ui.tests.harness.util.CallHistory)3 Test (org.junit.Test)3 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)2 EPartService (org.eclipse.e4.ui.workbench.modeling.EPartService)1 Action (org.eclipse.jface.action.Action)1 IMenuManager (org.eclipse.jface.action.IMenuManager)1 IToolBarManager (org.eclipse.jface.action.IToolBarManager)1 Separator (org.eclipse.jface.action.Separator)1 TableViewer (org.eclipse.jface.viewers.TableViewer)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1