|
Added
Link Here
|
| 1 |
/******************************************************************************* |
| 2 |
* Copyright (c) 2000, 2006 IBM Corporation and others. |
| 3 |
* All rights reserved. This program and the accompanying materials |
| 4 |
* are made available under the terms of the Eclipse Public License v1.0 |
| 5 |
* which accompanies this distribution, and is available at |
| 6 |
* http://www.eclipse.org/legal/epl-v10.html |
| 7 |
* |
| 8 |
* Contributors: |
| 9 |
* IBM Corporation - initial API and implementation |
| 10 |
*******************************************************************************/ |
| 11 |
package org.eclipse.ui.tests.api; |
| 12 |
|
| 13 |
import org.eclipse.core.runtime.IProgressMonitor; |
| 14 |
import org.eclipse.swt.SWT; |
| 15 |
import org.eclipse.swt.events.SelectionAdapter; |
| 16 |
import org.eclipse.swt.events.SelectionEvent; |
| 17 |
import org.eclipse.swt.widgets.Button; |
| 18 |
import org.eclipse.swt.widgets.Composite; |
| 19 |
import org.eclipse.ui.IActionBars; |
| 20 |
import org.eclipse.ui.IEditorInput; |
| 21 |
import org.eclipse.ui.IEditorPart; |
| 22 |
import org.eclipse.ui.IEditorPersistable; |
| 23 |
import org.eclipse.ui.IEditorSite; |
| 24 |
import org.eclipse.ui.IMemento; |
| 25 |
import org.eclipse.ui.PartInitException; |
| 26 |
|
| 27 |
public class MockEditorWithState extends MockWorkbenchPart implements |
| 28 |
IEditorPart, IEditorPersistable { |
| 29 |
|
| 30 |
public static final String ID = "org.eclipse.ui.tests.api.MockEditorStatePart"; |
| 31 |
|
| 32 |
public static final String NAME = "Mock Editor State 1"; |
| 33 |
|
| 34 |
private IEditorInput input; |
| 35 |
|
| 36 |
private boolean dirty = false; |
| 37 |
|
| 38 |
private boolean saveNeeded = true; |
| 39 |
|
| 40 |
private boolean saveAsAllowed = false; |
| 41 |
|
| 42 |
public MockEditorWithState() { |
| 43 |
super(); |
| 44 |
} |
| 45 |
|
| 46 |
public void createPartControl(Composite parent) { |
| 47 |
super.createPartControl(parent); |
| 48 |
|
| 49 |
final Button dirtyToggle = new Button(parent, SWT.CHECK); |
| 50 |
dirtyToggle.setText("Dirty"); |
| 51 |
dirtyToggle.addSelectionListener(new SelectionAdapter() { |
| 52 |
public void widgetSelected(SelectionEvent e) { |
| 53 |
setDirty(dirtyToggle.getSelection()); |
| 54 |
} |
| 55 |
}); |
| 56 |
dirtyToggle.setSelection(isDirty()); |
| 57 |
|
| 58 |
final Button saveNeededToggle = new Button(parent, SWT.CHECK); |
| 59 |
saveNeededToggle.setText("Save on close"); |
| 60 |
saveNeededToggle.addSelectionListener(new SelectionAdapter() { |
| 61 |
public void widgetSelected(SelectionEvent e) { |
| 62 |
setSaveNeeded(saveNeededToggle.getSelection()); |
| 63 |
} |
| 64 |
}); |
| 65 |
saveNeededToggle.setSelection(saveNeeded); |
| 66 |
|
| 67 |
final Button saveAsToggle = new Button(parent, SWT.CHECK); |
| 68 |
saveAsToggle.setText("Save as allowed"); |
| 69 |
saveAsToggle.addSelectionListener(new SelectionAdapter() { |
| 70 |
public void widgetSelected(SelectionEvent e) { |
| 71 |
setSaveAsAllowed(saveAsToggle.getSelection()); |
| 72 |
} |
| 73 |
}); |
| 74 |
saveAsToggle.setSelection(saveAsAllowed); |
| 75 |
} |
| 76 |
|
| 77 |
/** |
| 78 |
* @see IEditorPart#doSave(IProgressMonitor) |
| 79 |
*/ |
| 80 |
public void doSave(IProgressMonitor monitor) { |
| 81 |
setDirty(false); |
| 82 |
callTrace.add("doSave"); |
| 83 |
} |
| 84 |
|
| 85 |
/** |
| 86 |
* @see IEditorPart#doSaveAs() |
| 87 |
*/ |
| 88 |
public void doSaveAs() { |
| 89 |
} |
| 90 |
|
| 91 |
/** |
| 92 |
* @see IEditorPart#getEditorInput() |
| 93 |
*/ |
| 94 |
public IEditorInput getEditorInput() { |
| 95 |
return input; |
| 96 |
} |
| 97 |
|
| 98 |
/** |
| 99 |
* @see IEditorPart#getEditorSite() |
| 100 |
*/ |
| 101 |
public IEditorSite getEditorSite() { |
| 102 |
return (IEditorSite) getSite(); |
| 103 |
} |
| 104 |
|
| 105 |
/** |
| 106 |
* @see IEditorPart#init(IEditorSite, IEditorInput) |
| 107 |
*/ |
| 108 |
public void init(IEditorSite site, IEditorInput input) |
| 109 |
throws PartInitException { |
| 110 |
this.input = input; |
| 111 |
setSite(site); |
| 112 |
callTrace.add("init"); |
| 113 |
setSiteInitialized(); |
| 114 |
} |
| 115 |
|
| 116 |
/** |
| 117 |
* @see IEditorPart#isDirty() |
| 118 |
*/ |
| 119 |
public boolean isDirty() { |
| 120 |
callTrace.add("isDirty"); |
| 121 |
return dirty; |
| 122 |
} |
| 123 |
|
| 124 |
public void setDirty(boolean value) { |
| 125 |
dirty = value; |
| 126 |
firePropertyChange(PROP_DIRTY); |
| 127 |
} |
| 128 |
|
| 129 |
/** |
| 130 |
* @see IEditorPart#isSaveAsAllowed() |
| 131 |
*/ |
| 132 |
public boolean isSaveAsAllowed() { |
| 133 |
callTrace.add("isSaveAsAllowed"); |
| 134 |
return saveAsAllowed; |
| 135 |
} |
| 136 |
|
| 137 |
/** |
| 138 |
* @see IEditorPart#isSaveOnCloseNeeded() |
| 139 |
*/ |
| 140 |
public boolean isSaveOnCloseNeeded() { |
| 141 |
callTrace.add("isSaveOnCloseNeeded"); |
| 142 |
return saveNeeded; |
| 143 |
} |
| 144 |
|
| 145 |
public void setSaveAsAllowed(boolean isSaveAsAllowed) { |
| 146 |
this.saveAsAllowed = isSaveAsAllowed; |
| 147 |
} |
| 148 |
|
| 149 |
public void setSaveNeeded(boolean value) { |
| 150 |
saveNeeded = value; |
| 151 |
} |
| 152 |
|
| 153 |
/* |
| 154 |
* (non-Javadoc) |
| 155 |
* |
| 156 |
* @see org.eclipse.ui.tests.api.MockWorkbenchPart#getActionBars() |
| 157 |
*/ |
| 158 |
protected IActionBars getActionBars() { |
| 159 |
return getEditorSite().getActionBars(); |
| 160 |
} |
| 161 |
|
| 162 |
/* |
| 163 |
* (non-Javadoc) |
| 164 |
* |
| 165 |
* @see org.eclipse.ui.IEditorPersistable#restoreState(org.eclipse.ui.IMemento) |
| 166 |
*/ |
| 167 |
public void restoreState(IMemento memento) { |
| 168 |
callTrace.add("restoreState"); |
| 169 |
} |
| 170 |
|
| 171 |
/* |
| 172 |
* (non-Javadoc) |
| 173 |
* |
| 174 |
* @see org.eclipse.ui.IPersistable#saveState(org.eclipse.ui.IMemento) |
| 175 |
*/ |
| 176 |
public void saveState(IMemento memento) { |
| 177 |
callTrace.add("saveState"); |
| 178 |
} |
| 179 |
} |