类org.eclipse.ui.IEditorMatchingStrategy源码实例Demo

下面列出了怎么用org.eclipse.ui.IEditorMatchingStrategy的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: scava   文件: CrossflowDiagramEditor.java
/**
* @generated
*/
protected void performSaveAs(IProgressMonitor progressMonitor) {
	Shell shell = getSite().getShell();
	IEditorInput input = getEditorInput();
	SaveAsDialog dialog = new SaveAsDialog(shell);
	IFile original = input instanceof IFileEditorInput ? ((IFileEditorInput) input).getFile() : null;
	if (original != null) {
		dialog.setOriginalFile(original);
	}
	dialog.create();
	IDocumentProvider provider = getDocumentProvider();
	if (provider == null) {
		// editor has been programmatically closed while the dialog was open
		return;
	}
	if (provider.isDeleted(input) && original != null) {
		String message = NLS.bind(Messages.CrossflowDiagramEditor_SavingDeletedFile, original.getName());
		dialog.setErrorMessage(null);
		dialog.setMessage(message, IMessageProvider.WARNING);
	}
	if (dialog.open() == Window.CANCEL) {
		if (progressMonitor != null) {
			progressMonitor.setCanceled(true);
		}
		return;
	}
	IPath filePath = dialog.getResult();
	if (filePath == null) {
		if (progressMonitor != null) {
			progressMonitor.setCanceled(true);
		}
		return;
	}
	IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
	IFile file = workspaceRoot.getFile(filePath);
	final IEditorInput newInput = new FileEditorInput(file);
	// Check if the editor is already open
	IEditorMatchingStrategy matchingStrategy = getEditorDescriptor().getEditorMatchingStrategy();
	IEditorReference[] editorRefs = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
			.getEditorReferences();
	for (int i = 0; i < editorRefs.length; i++) {
		if (matchingStrategy.matches(editorRefs[i], newInput)) {
			MessageDialog.openWarning(shell, Messages.CrossflowDiagramEditor_SaveAsErrorTitle,
					Messages.CrossflowDiagramEditor_SaveAsErrorMessage);
			return;
		}
	}
	boolean success = false;
	try {
		provider.aboutToChange(newInput);
		getDocumentProvider(newInput).saveDocument(progressMonitor, newInput,
				getDocumentProvider().getDocument(getEditorInput()), true);
		success = true;
	} catch (CoreException x) {
		IStatus status = x.getStatus();
		if (status == null || status.getSeverity() != IStatus.CANCEL) {
			ErrorDialog.openError(shell, Messages.CrossflowDiagramEditor_SaveErrorTitle,
					Messages.CrossflowDiagramEditor_SaveErrorMessage, x.getStatus());
		}
	} finally {
		provider.changed(newInput);
		if (success) {
			setInput(newInput);
		}
	}
	if (progressMonitor != null) {
		progressMonitor.setCanceled(!success);
	}
}
 
源代码2 项目: bonita-studio   文件: ProcessDiagramEditor.java
/**
* @generated
*/
protected void performSaveAs(IProgressMonitor progressMonitor) {
	Shell shell = getSite().getShell();
	IEditorInput input = getEditorInput();
	SaveAsDialog dialog = new SaveAsDialog(shell);
	IFile original = input instanceof IFileEditorInput ? ((IFileEditorInput) input).getFile() : null;
	if (original != null) {
		dialog.setOriginalFile(original);
	}
	dialog.create();
	IDocumentProvider provider = getDocumentProvider();
	if (provider == null) {
		// editor has been programmatically closed while the dialog was open
		return;
	}
	if (provider.isDeleted(input) && original != null) {
		String message = NLS.bind(Messages.ProcessDiagramEditor_SavingDeletedFile, original.getName());
		dialog.setErrorMessage(null);
		dialog.setMessage(message, IMessageProvider.WARNING);
	}
	if (dialog.open() == Window.CANCEL) {
		if (progressMonitor != null) {
			progressMonitor.setCanceled(true);
		}
		return;
	}
	IPath filePath = dialog.getResult();
	if (filePath == null) {
		if (progressMonitor != null) {
			progressMonitor.setCanceled(true);
		}
		return;
	}
	IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
	IFile file = workspaceRoot.getFile(filePath);
	final IEditorInput newInput = new FileEditorInput(file);
	// Check if the editor is already open
	IEditorMatchingStrategy matchingStrategy = getEditorDescriptor().getEditorMatchingStrategy();
	IEditorReference[] editorRefs = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
			.getEditorReferences();
	for (int i = 0; i < editorRefs.length; i++) {
		if (matchingStrategy.matches(editorRefs[i], newInput)) {
			MessageDialog.openWarning(shell, Messages.ProcessDiagramEditor_SaveAsErrorTitle,
					Messages.ProcessDiagramEditor_SaveAsErrorMessage);
			return;
		}
	}
	boolean success = false;
	try {
		provider.aboutToChange(newInput);
		getDocumentProvider(newInput).saveDocument(progressMonitor, newInput,
				getDocumentProvider().getDocument(getEditorInput()), true);
		success = true;
	} catch (CoreException x) {
		IStatus status = x.getStatus();
		if (status == null || status.getSeverity() != IStatus.CANCEL) {
			ErrorDialog.openError(shell, Messages.ProcessDiagramEditor_SaveErrorTitle,
					Messages.ProcessDiagramEditor_SaveErrorMessage, x.getStatus());
		}
	} finally {
		provider.changed(newInput);
		if (success) {
			setInput(newInput);
		}
	}
	if (progressMonitor != null) {
		progressMonitor.setCanceled(!success);
	}
}
 
 类所在包
 类方法
 同包方法