use of org.eclipse.ui.IEditorMatchingStrategy in project InformationSystem by ObeoNetwork.
the class BindingTreeEditor method performSaveAs.
/**
* Perform the saveAs action.
*
* @param progressMonitor
* The progress monitor
*/
private void performSaveAs(final IProgressMonitor progressMonitor) {
final Shell shell = getSite().getShell();
final IEditorInput input = getEditorInput();
final SaveAsDialog dialog = new SaveAsDialog(shell);
final IFile original = input instanceof IFileEditorInput ? ((IFileEditorInput) input).getFile() : null;
if (original != null) {
dialog.setOriginalFile(original);
}
dialog.create();
if (dialog.open() == Window.CANCEL) {
if (progressMonitor != null) {
progressMonitor.setCanceled(true);
}
} else {
final IPath filePath = dialog.getResult();
if (filePath == null) {
if (progressMonitor != null) {
progressMonitor.setCanceled(true);
}
return;
}
final IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
final IFile file = workspaceRoot.getFile(filePath);
final IEditorInput newInput = new FileEditorInput(file);
// Check if the editor is already open
final IEditorMatchingStrategy matchingStrategy = getEditorDescriptor().getEditorMatchingStrategy();
final IEditorReference[] editorRefs = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getEditorReferences();
for (int i = 0; i < editorRefs.length; i++) {
if (matchingStrategy.matches(editorRefs[i], newInput)) {
return;
}
}
final boolean success = false;
if (progressMonitor != null) {
progressMonitor.setCanceled(!success);
}
}
}
Aggregations