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);
}
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);
}
}
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();
}
}
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);
}
}
}
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();
}
}
Aggregations