本文整理汇总了Java中org.eclipse.core.resources.IWorkspaceRoot.exists方法的典型用法代码示例。如果您正苦于以下问题:Java IWorkspaceRoot.exists方法的具体用法?Java IWorkspaceRoot.exists怎么用?Java IWorkspaceRoot.exists使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.core.resources.IWorkspaceRoot
的用法示例。
在下文中一共展示了IWorkspaceRoot.exists方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: openEditorForFileExtension
import org.eclipse.core.resources.IWorkspaceRoot; //导入方法依赖的package包/类
/**
* Opens the default editor for the given file extension side by side with the currently
* active editor
* @param File extension
*/
public void openEditorForFileExtension(String fileExtension){
IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
IPath path = getPathToEditorRelatedFileWithFileExtension(fileExtension);
// only open editor if a file exist with the same name as the feature model in same directory
if(workspaceRoot.exists(path)){
IFile constraintFile = workspaceRoot.getFile(path);
IEditorDescriptor desc = PlatformUI.getWorkbench().
getEditorRegistry().getDefaultEditor(constraintFile.getName());
if(desc == null){
System.err.println("No editor for file extension "+fileExtension+" exist");
return;
}
try {
IWorkbenchPage workbenchPage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
IEditorPart editor = workbenchPage.openEditor(new FileEditorInput(constraintFile), desc.getId());
MPart constraintEditorPart = editor.getSite().getService(MPart.class);
MPart editorPart = this.getSite().getService(MPart.class);
if (editorPart == null) {
return;
}
insertEditor(0.3f, EModelService.RIGHT_OF, editorPart, constraintEditorPart);
} catch (PartInitException e) {
e.printStackTrace();
}
}
}
示例2: setInput
import org.eclipse.core.resources.IWorkspaceRoot; //导入方法依赖的package包/类
@Override
protected void setInput(IEditorInput input) {
if (input instanceof DiagramEditorInput) {
final DiagramEditorInput diagramEditorInput = (DiagramEditorInput) input;
// The input is an architecture file resource
if (TurnusExtensions.ARCHITECTURE.equals(diagramEditorInput.getUri().fileExtension())) {
final IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
final URI xafUri = diagramEditorInput.getUri();
final URI diagramUri = getDiagramUri(xafUri);
final IPath diagramPath = new Path(diagramUri.toPlatformString(true));
// The diagram associated with the Xdf doesn't exists
if (!workspaceRoot.exists(diagramPath)) {
try {
// Create it (empty). Its content will be updated in
// UpdateDiagramFeature
EclipseUtils.createDiagramResource(TurnusUiConstants.ARCHITECTURE_DIAGRAM_TYPE, diagramUri);
} catch (IOException e) {
Logger.error("Unable to create a diagram resource from the architecture file.");
}
}
diagramEditorInput.updateUri(diagramUri);
super.setInput(diagramEditorInput);
return;
}
}
super.setInput(input);
}
示例3: update
import org.eclipse.core.resources.IWorkspaceRoot; //导入方法依赖的package包/类
@Override
public boolean update(IUpdateContext context) {
if (!(context.getPictogramElement() instanceof Diagram)) {
Logger.warning("UpdateDiagramFeature has been used with a non Diagram parameter: %s",
context.getPictogramElement().getClass().toString());
return false;
}
final EditingDomain editingDomain = getDiagramBehavior().getEditingDomain();
final ResourceSet resourceSet = editingDomain.getResourceSet();
final IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
final Diagram diagram = (Diagram) context.getPictogramElement();
final Object linkedBo = getBusinessObjectForPictogramElement(diagram);
final URI diagramUri = diagram.eResource().getURI();
final URI archUri = diagramUri.trimFileExtension().appendFileExtension(TurnusExtensions.ARCHITECTURE);
final Architecture architecture;
if (linkedBo == null || !(linkedBo instanceof Architecture)) {
if (root.exists(new Path(archUri.toPlatformString(true)))) {
architecture = (Architecture) resourceSet.getResource(archUri, true).getContents().get(0);
link(diagram, architecture);
} else {
MessageDialog.openWarning(EclipseUtils.getDefaultShell(), "Warning",
"This diagram has no architecture attached. It should not be used.");
return false;
}
} else {
architecture = (Architecture) linkedBo;
final Resource linkedRes = architecture.eResource();
if (linkedRes == null || !linkedRes.getURI().equals(archUri)) {
// Particular case. The existing network is not contained in a
// resource, or its resource has a wrong URI. It can happen if
// the diagram has been moved or duplicated without the
// corresponding xaf. The Move/Rename participant should take
// care of that.
final Resource res = editingDomain.createResource(archUri.toString());
res.getContents().add(EcoreUtil.copy(architecture));
hasDoneChanges = true;
}
}
// Check network validity / initialize diagram.
if (diagram.getChildren().size() == 0 && architecture.getProcessingUnits().size() > 0) {
// Diagram is new / empty. We check network validity
final List<String> updatedNetworkWarnings = new ArrayList<String>();
// hasDoneChanges |= fixNetwork(network, updatedNetworkWarnings);
// Initialize the new diagram
hasDoneChanges |= initializeDiagramFromNetwork(architecture, diagram);
// Display a synthesis message to user, to tell him what have been
// automatically modified in the diagram/network he just opened
if (updatedNetworkWarnings.size() > 0) {
final StringBuilder message = new StringBuilder(
"The architecture diagram has been automatically updated:");
message.append('\n');
for (final String msg : updatedNetworkWarnings) {
message.append(msg).append('\n');
}
MessageDialog.openInformation(EclipseUtils.getDefaultShell(), "Architecture diagram update",
message.toString());
}
} else {
checkDiagramValidity(getDiagram());
}
updateVersion(diagram);
return hasDoneChanges;
}
示例4: toIResource
import org.eclipse.core.resources.IWorkspaceRoot; //导入方法依赖的package包/类
/**
* Returns the equivalent {@linkplain org.eclipse.core.resources.IResource
* Eclipse IResource} for an {@linkplain org.eclipse.emf.common.util.URI Ecore
* URI}, if available.
*
* <p>
* {@code uri} can be represented as IResource if {@code uri} is an
* {@linkplain URI#isPlatformResource() platform resource} (i.e. {@code uri}
* starts with {@code platform:/resource/}). Otherwise, this method returns
* {@code null}.
* </p>
*
* <p>
* This method ignores any {@linkplain URI#fragment() fragment} or
* {@linkplain URI#query() query} of {@code uri}.
* </p>
*
* <p>
* If the resulting IResource exists, this method returns the existing kind of
* IResource ({@linkplain org.eclipse.core.resources.IWorkspaceRoot
* IWorkspaceRoot}, {@linkplain org.eclipse.core.resources.IProject IProject},
* {@linkplain org.eclipse.core.resources.IFolder IFolder}, or
* {@linkplain org.eclipse.core.resources.IFile IFile}).
* </p>
*
* <p>
* If the resulting IResource does not exist, this method returns an IFile
* pointing to the place equivalent to {@code uri}.
* </p>
*
* <p>
* This method handles excess slashes (behind the platform resource identifiers)
* gracefully (i.e. ignores the slashes).<br/>
* Example: An URI of
* {@code platform:/resource/////MyProject///folder///deep/myFile.ext//} leads
* to an IFile for path {@code /MyProject/folder/deep/myFile.ext}.
* </p>
*
* <p>
* <b>Note:</b> This method treats {@code uri} as case-sensitive (on <i>all</i>
* platforms, including Windows). Therefore, if the workspace contained a file
* at {@code /MyProject/myFolder/myFile.ext} and we passed the URI
* {@code platform:/resource/MyProject/myFolder/mYfILE.ext} to this method, the
* result is an IFile for path {@code /MyProject/myFolder/mYfILE.ext}.
* {@link IResource#exists() result.exists()} will return {@code false}.
* </p>
*
* @param uri
* The Ecore URI to return as Eclipse IResource.
* @return {@code uri} as Eclipse IResource, if available; {@code null}
* otherwise.
*
* @throws IllegalArgumentException
* If {@code uri} is seriously ill-formatted.
*
* @since 0.1
*/
public static @Nullable IResource toIResource(final @NonNull URI uri) {
if (uri.isPlatformResource()) {
String platformString = uri.toPlatformString(true);
IPath path = Path.fromOSString(platformString);
IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
if (workspaceRoot.exists(path)) {
return workspaceRoot.findMember(path);
} else {
return workspaceRoot.getFile(path);
}
}
return null;
}
示例5: resourcePathExists
import org.eclipse.core.resources.IWorkspaceRoot; //导入方法依赖的package包/类
/**
* Return whether the path corresponds to an existing resource
*
* @param path
* @return
*/
public static boolean resourcePathExists(String path) {
IWorkspaceRoot root = ResourceManager.getWorkspaceRoot();
IPath p = new Path(path);
return root.exists(p);
}