|
Lines 14-37
Link Here
|
| 14 |
import java.lang.reflect.InvocationTargetException; |
14 |
import java.lang.reflect.InvocationTargetException; |
| 15 |
import java.util.Vector; |
15 |
import java.util.Vector; |
| 16 |
|
16 |
|
| 17 |
import org.eclipse.core.resources.IFile; |
|
|
| 18 |
import org.eclipse.core.resources.IProject; |
| 19 |
import org.eclipse.core.resources.IResource; |
| 20 |
import org.eclipse.core.resources.IResourceChangeEvent; |
| 21 |
import org.eclipse.core.resources.IResourceChangeListener; |
| 22 |
import org.eclipse.core.resources.IResourceDelta; |
| 23 |
import org.eclipse.core.runtime.CoreException; |
| 24 |
import org.eclipse.core.runtime.IPath; |
| 25 |
import org.eclipse.core.runtime.IProgressMonitor; |
| 26 |
import org.eclipse.core.runtime.IStatus; |
| 27 |
import org.eclipse.core.runtime.Status; |
| 28 |
import org.eclipse.jface.action.IMenuManager; |
| 29 |
import org.eclipse.jface.dialogs.ErrorDialog; |
| 30 |
import org.eclipse.jface.dialogs.MessageDialog; |
| 31 |
import org.eclipse.jface.dialogs.ProgressMonitorDialog; |
| 32 |
import org.eclipse.jface.resource.ImageDescriptor; |
| 33 |
import org.eclipse.jface.resource.JFaceColors; |
| 34 |
import org.eclipse.jface.window.Window; |
| 35 |
import org.eclipse.swt.SWT; |
17 |
import org.eclipse.swt.SWT; |
| 36 |
import org.eclipse.swt.SWTException; |
18 |
import org.eclipse.swt.SWTException; |
| 37 |
import org.eclipse.swt.custom.BusyIndicator; |
19 |
import org.eclipse.swt.custom.BusyIndicator; |
|
Lines 46-54
Link Here
|
| 46 |
import org.eclipse.swt.widgets.Menu; |
28 |
import org.eclipse.swt.widgets.Menu; |
| 47 |
import org.eclipse.swt.widgets.MenuItem; |
29 |
import org.eclipse.swt.widgets.MenuItem; |
| 48 |
import org.eclipse.swt.widgets.Shell; |
30 |
import org.eclipse.swt.widgets.Shell; |
|
|
31 |
|
| 32 |
import org.eclipse.core.runtime.CoreException; |
| 33 |
import org.eclipse.core.runtime.IPath; |
| 34 |
import org.eclipse.core.runtime.IProgressMonitor; |
| 35 |
import org.eclipse.core.runtime.IStatus; |
| 36 |
import org.eclipse.core.runtime.Status; |
| 37 |
|
| 38 |
import org.eclipse.core.resources.IFile; |
| 39 |
import org.eclipse.core.resources.IProject; |
| 40 |
import org.eclipse.core.resources.IResource; |
| 41 |
import org.eclipse.core.resources.IResourceChangeEvent; |
| 42 |
import org.eclipse.core.resources.IResourceChangeListener; |
| 43 |
import org.eclipse.core.resources.IResourceDelta; |
| 44 |
import org.eclipse.core.resources.ResourcesPlugin; |
| 45 |
|
| 46 |
import org.eclipse.jface.action.IMenuManager; |
| 47 |
import org.eclipse.jface.dialogs.ErrorDialog; |
| 48 |
import org.eclipse.jface.dialogs.MessageDialog; |
| 49 |
import org.eclipse.jface.dialogs.ProgressMonitorDialog; |
| 50 |
import org.eclipse.jface.resource.ImageDescriptor; |
| 51 |
import org.eclipse.jface.resource.JFaceColors; |
| 52 |
import org.eclipse.jface.window.Window; |
| 53 |
|
| 49 |
import org.eclipse.ui.IEditorInput; |
54 |
import org.eclipse.ui.IEditorInput; |
| 50 |
import org.eclipse.ui.IEditorSite; |
55 |
import org.eclipse.ui.IEditorSite; |
|
|
56 |
import org.eclipse.ui.IFileEditorInput; |
| 51 |
import org.eclipse.ui.IPartListener; |
57 |
import org.eclipse.ui.IPartListener; |
|
|
58 |
import org.eclipse.ui.IPathEditorInput; |
| 52 |
import org.eclipse.ui.IWorkbench; |
59 |
import org.eclipse.ui.IWorkbench; |
| 53 |
import org.eclipse.ui.IWorkbenchActionConstants; |
60 |
import org.eclipse.ui.IWorkbenchActionConstants; |
| 54 |
import org.eclipse.ui.IWorkbenchPart; |
61 |
import org.eclipse.ui.IWorkbenchPart; |
|
Lines 68-74
Link Here
|
| 68 |
|
75 |
|
| 69 |
/** |
76 |
/** |
| 70 |
* The resource listener updates the receiver when |
77 |
* The resource listener updates the receiver when |
| 71 |
* a change has occured. |
78 |
* a change has occurred. |
| 72 |
*/ |
79 |
*/ |
| 73 |
private IResourceChangeListener resourceListener = new IResourceChangeListener() { |
80 |
private IResourceChangeListener resourceListener = new IResourceChangeListener() { |
| 74 |
|
81 |
|
|
Lines 220-237
Link Here
|
| 220 |
|
227 |
|
| 221 |
initializeWorkbenchMenus(); |
228 |
initializeWorkbenchMenus(); |
| 222 |
|
229 |
|
| 223 |
// Set the input file. |
|
|
| 224 |
IFile file = ResourceUtil.getFile(getEditorInput()); |
| 225 |
if (file != null) { |
| 226 |
setResource(file); |
| 227 |
resource.getWorkspace().addResourceChangeListener(resourceListener); |
| 228 |
} |
| 229 |
|
| 230 |
createClientSite(); |
230 |
createClientSite(); |
| 231 |
} |
231 |
} |
| 232 |
|
232 |
|
| 233 |
/** |
233 |
/** |
| 234 |
* Create the client site for the reciever |
234 |
* Create the client site for the receiver |
| 235 |
*/ |
235 |
*/ |
| 236 |
|
236 |
|
| 237 |
private void createClientSite() { |
237 |
private void createClientSite() { |
|
Lines 257-263
Link Here
|
| 257 |
|
257 |
|
| 258 |
private void deactivateClient(IWorkbenchPart part) { |
258 |
private void deactivateClient(IWorkbenchPart part) { |
| 259 |
//Check the client active flag. Set it to false when we have deactivated |
259 |
//Check the client active flag. Set it to false when we have deactivated |
| 260 |
//to prevent multiple deactivations. |
260 |
//to prevent multiple de-activations. |
| 261 |
if (part == this && clientActive) { |
261 |
if (part == this && clientActive) { |
| 262 |
if (clientSite != null) |
262 |
if (clientSite != null) |
| 263 |
clientSite.deactivateInPlaceClient(); |
263 |
clientSite.deactivateInPlaceClient(); |
|
Lines 282-290
Link Here
|
| 282 |
* @see IWorkbenchPart#dispose |
282 |
* @see IWorkbenchPart#dispose |
| 283 |
*/ |
283 |
*/ |
| 284 |
public void dispose() { |
284 |
public void dispose() { |
| 285 |
if (resource != null) |
285 |
if (resource != null) { |
| 286 |
resource.getWorkspace().removeResourceChangeListener( |
286 |
ResourcesPlugin.getWorkspace().removeResourceChangeListener( |
| 287 |
resourceListener); |
287 |
resourceListener); |
|
|
288 |
resource = null; |
| 289 |
} |
| 288 |
|
290 |
|
| 289 |
//can dispose the title image because it was created in init |
291 |
//can dispose the title image because it was created in init |
| 290 |
if (oleTitleImage != null) { |
292 |
if (oleTitleImage != null) { |
|
Lines 433-458
Link Here
|
| 433 |
*/ |
435 |
*/ |
| 434 |
public void init(IEditorSite site, IEditorInput input) |
436 |
public void init(IEditorSite site, IEditorInput input) |
| 435 |
throws PartInitException { |
437 |
throws PartInitException { |
| 436 |
// Check input. |
438 |
|
| 437 |
IFile file = ResourceUtil.getFile(input); |
439 |
validatePathEditorInput(input); |
| 438 |
if (file == null) |
|
|
| 439 |
throw new PartInitException(OleMessages.format( |
| 440 |
"OleEditor.invalidInput", new Object[] { input })); //$NON-NLS-1$ |
| 441 |
|
| 442 |
//Cannot create this with a file and no physical location |
| 443 |
if (file.getLocation() == null |
| 444 |
|| !(new File(file.getLocation().toOSString()).exists())) |
| 445 |
throw new PartInitException( |
| 446 |
OleMessages |
| 447 |
.format( |
| 448 |
"OleEditor.noFileInput", new Object[] { file.getLocation() })); //$NON-NLS-1$ |
| 449 |
|
440 |
|
| 450 |
// Save input. |
441 |
// Save input. |
| 451 |
setSite(site); |
442 |
setSite(site); |
| 452 |
setInput(input); |
443 |
setInputWithNotify(input); |
| 453 |
|
444 |
|
| 454 |
// Update titles. |
445 |
// Update titles. |
| 455 |
setTitle(input.getName()); |
446 |
setPartName(input.getName()); |
| 456 |
setTitleToolTip(input.getToolTipText()); |
447 |
setTitleToolTip(input.getToolTipText()); |
| 457 |
ImageDescriptor desc = input.getImageDescriptor(); |
448 |
ImageDescriptor desc = input.getImageDescriptor(); |
| 458 |
if (desc != null) { |
449 |
if (desc != null) { |
|
Lines 464-470
Link Here
|
| 464 |
site.getPage().addPartListener(partListener); |
455 |
site.getPage().addPartListener(partListener); |
| 465 |
|
456 |
|
| 466 |
} |
457 |
} |
|
|
458 |
|
| 459 |
/** |
| 460 |
* Validates the given input |
| 461 |
* |
| 462 |
* @param input the editor input to validate |
| 463 |
* @throws PartInitException if the editor input is not OK |
| 464 |
*/ |
| 465 |
private boolean validatePathEditorInput(IEditorInput input) throws PartInitException { |
| 466 |
// Check input type. |
| 467 |
if (!(input instanceof IPathEditorInput)) |
| 468 |
throw new PartInitException(OleMessages.format( |
| 469 |
"OleEditor.invalidInput", new Object[] { input })); //$NON-NLS-1$ |
| 470 |
|
| 471 |
IPath path= ((IPathEditorInput)input).getPath(); |
| 467 |
|
472 |
|
|
|
473 |
//Cannot create this with a file and no physical location |
| 474 |
if (path == null |
| 475 |
|| !(new File(path.toOSString()).exists())) |
| 476 |
throw new PartInitException( |
| 477 |
OleMessages |
| 478 |
.format( |
| 479 |
"OleEditor.noFileInput", new Object[] { path.toOSString() })); //$NON-NLS-1$ |
| 480 |
return true; |
| 481 |
} |
| 482 |
|
| 468 |
/** |
483 |
/** |
| 469 |
* Initialize the workbench menus for proper merging |
484 |
* Initialize the workbench menus for proper merging |
| 470 |
*/ |
485 |
*/ |
|
Lines 472-478
Link Here
|
| 472 |
//If there was an OLE Error or nothing has been created yet |
487 |
//If there was an OLE Error or nothing has been created yet |
| 473 |
if (clientFrame == null || clientFrame.isDisposed()) |
488 |
if (clientFrame == null || clientFrame.isDisposed()) |
| 474 |
return; |
489 |
return; |
| 475 |
// Get the browser menubar. If one does not exist then |
490 |
// Get the browser menu bar. If one does not exist then |
| 476 |
// create it. |
491 |
// create it. |
| 477 |
Shell shell = clientFrame.getShell(); |
492 |
Shell shell = clientFrame.getShell(); |
| 478 |
Menu menuBar = shell.getMenuBar(); |
493 |
Menu menuBar = shell.getMenuBar(); |
|
Lines 636-648
Link Here
|
| 636 |
} |
651 |
} |
| 637 |
} |
652 |
} |
| 638 |
|
653 |
|
| 639 |
/** |
654 |
/* (non-Javadoc) |
| 640 |
* Set the file resource that this object is displaying |
655 |
* @see org.eclipse.ui.part.EditorPart#setInputWithNotify(org.eclipse.ui.IEditorInput) |
| 641 |
* @param file |
|
|
| 642 |
*/ |
656 |
*/ |
| 643 |
protected void setResource(IFile file) { |
657 |
protected void setInputWithNotify(IEditorInput input) { |
| 644 |
resource = file; |
658 |
if (input instanceof IPathEditorInput) |
| 645 |
source = new File(file.getLocation().toOSString()); |
659 |
source = new File(((IPathEditorInput)input).getPath().toOSString()); |
|
|
660 |
|
| 661 |
if (input instanceof IFileEditorInput) { |
| 662 |
if (resource == null) |
| 663 |
ResourcesPlugin.getWorkspace().addResourceChangeListener(resourceListener); |
| 664 |
resource = ((IFileEditorInput)input).getFile(); |
| 665 |
} else if (resource != null) { |
| 666 |
ResourcesPlugin.getWorkspace().removeResourceChangeListener(resourceListener); |
| 667 |
resource = null; |
| 668 |
} |
| 669 |
|
| 670 |
super.setInputWithNotify(input); |
| 646 |
} |
671 |
} |
| 647 |
|
672 |
|
| 648 |
/** |
673 |
/** |
|
Lines 665-674
Link Here
|
| 665 |
private void sourceChanged(IFile newFile) { |
690 |
private void sourceChanged(IFile newFile) { |
| 666 |
|
691 |
|
| 667 |
FileEditorInput newInput = new FileEditorInput(newFile); |
692 |
FileEditorInput newInput = new FileEditorInput(newFile); |
| 668 |
setInput(newInput); |
693 |
setInputWithNotify(newInput); |
| 669 |
setResource(newFile); |
|
|
| 670 |
sourceChanged = true; |
694 |
sourceChanged = true; |
| 671 |
setTitle(newInput.getName()); |
695 |
setPartName(newInput.getName()); |
| 672 |
|
696 |
|
| 673 |
} |
697 |
} |
| 674 |
|
698 |
|