/** @return the IFile corresponding to the given input, or null if none */ public static IFile getFile(IEditorInput editorInput) { IFile file = null; if (editorInput instanceof IFileEditorInput) { IFileEditorInput fileEditorInput = (IFileEditorInput) editorInput; file = fileEditorInput.getFile(); } else if (editorInput instanceof IPathEditorInput) { IPathEditorInput pathInput = (IPathEditorInput) editorInput; IWorkspaceRoot wsRoot = ResourcesPlugin.getWorkspace().getRoot(); if (wsRoot.getLocation().isPrefixOf(pathInput.getPath())) { file = ResourcesPlugin.getWorkspace().getRoot().getFile(pathInput.getPath()); } else { // Can't get an IFile for an arbitrary file on the file system; return null } } else if (editorInput instanceof IStorageEditorInput) { file = null; // Can't get an IFile for an arbitrary IStorageEditorInput } else if (editorInput instanceof IURIEditorInput) { IURIEditorInput uriEditorInput = (IURIEditorInput) editorInput; IWorkspaceRoot wsRoot = ResourcesPlugin.getWorkspace().getRoot(); URI uri = uriEditorInput.getURI(); String path = uri.getPath(); // Bug 526: uri.getHost() can be null for a local file URL if (uri.getScheme().equals("file") && (uri.getHost() == null || uri.getHost().equals("localhost")) && !path.startsWith(wsRoot.getLocation().toOSString())) { file = wsRoot.getFile(new Path(path)); } } return file; }
@Before public void setUp() throws Exception { IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); FileUtils.mkdir(new File(root.getLocation().toFile(), "Sub"), true); gitDir = new File(new File(root.getLocation().toFile(), "Sub"), Constants.DOT_GIT); repository = FileRepositoryBuilder.create(gitDir); repository.create(); project = root.getProject(TEST_PROJECT); project.create(null); project.open(null); IProjectDescription description = project.getDescription(); description.setLocation(root.getLocation().append(TEST_PROJECT_LOC)); project.move(description, IResource.FORCE, null); project2 = root.getProject(TEST_PROJECT2); project2.create(null); project2.open(null); gitDir2 = new File(project2.getLocation().toFile().getAbsoluteFile(), Constants.DOT_GIT); repository2 = FileRepositoryBuilder.create(gitDir2); repository2.create(); RepositoryMapping mapping = RepositoryMapping.create(project, gitDir); RepositoryMapping mapping2 = RepositoryMapping.create(project2, gitDir2); GitProjectData projectData = new GitProjectData(project); GitProjectData projectData2 = new GitProjectData(project2); projectData.setRepositoryMappings(Collections.singletonList(mapping)); projectData.store(); projectData2.setRepositoryMappings(Collections.singletonList(mapping2)); projectData2.store(); GitProjectData.add(project, projectData); GitProjectData.add(project2, projectData2); RepositoryProvider.map(project, GitProvider.class.getName()); RepositoryProvider.map(project2, GitProvider.class.getName()); JGitTestUtil.write( new File(repository.getWorkTree(), TEST_PROJECT + "/" + TEST_FILE), "Some data"); JGitTestUtil.write(new File(repository2.getWorkTree(), TEST_FILE2), "Some other data"); project.refreshLocal(IResource.DEPTH_INFINITE, null); project2.refreshLocal(IResource.DEPTH_INFINITE, null); git = new Git(repository); git.add().addFilepattern(".").call(); git.commit().setMessage("Initial commit").call(); git = new Git(repository2); git.add().addFilepattern(".").call(); git.commit().setMessage("Initial commit").call(); git.branchRename().setNewName("main").call(); }
public boolean performFinish() { FeatureModel featureModel = new FeatureModel(); featureModel.createDefaultValues(""); Path fullFilePath = new Path(page.fileName.getText()); IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); IPath rootPath = root.getLocation(); if (rootPath.isPrefixOf(fullFilePath)) { // case: is file in workspace int matchingFirstSegments = rootPath.matchingFirstSegments(fullFilePath); IPath localFilePath = fullFilePath.removeFirstSegments(matchingFirstSegments); String[] segments = localFilePath.segments(); localFilePath = new Path(""); for (String segment : segments) { localFilePath = localFilePath.append(segment); } IFile file = root.getFile(localFilePath); featureModel.initFMComposerExtension(file.getProject()); try { new FeatureModelWriterIFileWrapper(new XmlFeatureModelWriter(featureModel)) .writeToFile(file); file.refreshLocal(IResource.DEPTH_INFINITE, null); } catch (CoreException e) { FMUIPlugin.getDefault().logError(e); } open(file); } else { // case: is no file in workspace File file = fullFilePath.toFile(); new XmlFeatureModelWriter(featureModel).writeToFile(file); } return true; }
private void testBasedirRename(int renameRequired) throws IOException, CoreException { IWorkspaceRoot root = workspace.getRoot(); final MavenPlugin plugin = MavenPlugin.getDefault(); String pathname = "projects/MNGECLIPSE-1793_basedirRename/mavenNNNNNNN"; File src = new File(pathname); File dst = new File(root.getLocation().toFile(), src.getName()); copyDir(src, dst); final ArrayList<MavenProjectInfo> projectInfos = new ArrayList<MavenProjectInfo>(); projectInfos.add(new MavenProjectInfo("label", new File(dst, "pom.xml"), null, null)); projectInfos.get(0).setBasedirRename(renameRequired); final ProjectImportConfiguration importConfiguration = new ProjectImportConfiguration(new ResolverConfiguration()); workspace.run( new IWorkspaceRunnable() { public void run(IProgressMonitor monitor) throws CoreException { plugin .getProjectConfigurationManager() .importProjects(projectInfos, importConfiguration, monitor); } }, plugin.getProjectConfigurationManager().getRule(), IWorkspace.AVOID_UPDATE, monitor); }
/** * Test sample project with a virtual folder that points to configure scripts. Tests Bug 434275 - * Autotools configuration in subfolder not found * * @throws Exception */ @Test public void testAutotoolsVirtualFolder() throws Exception { Path p = new Path("zip/project2.zip"); IWorkspaceRoot root = ProjectTools.getWorkspaceRoot(); IPath rootPath = root.getLocation(); IPath configPath = rootPath.append("config"); File configDir = configPath.toFile(); configDir.deleteOnExit(); assertTrue(configDir.mkdir()); ProjectTools.createLinkedFolder( testProject, "src", URIUtil.append(root.getLocationURI(), "config")); ProjectTools.addSourceContainerWithImport(testProject, "src", p); assertTrue(testProject.hasNature(AutotoolsNewProjectNature.AUTOTOOLS_NATURE_ID)); assertTrue(exists("src/ChangeLog")); ProjectTools.setConfigDir(testProject, "src"); ProjectTools.markExecutable(testProject, "src/autogen.sh"); assertFalse(exists("src/configure")); assertFalse(exists("src/Makefile.in")); assertFalse(exists("src/sample/Makefile.in")); assertFalse(exists("src/aclocal.m4")); assertTrue(ProjectTools.build()); assertTrue(exists("src/configure")); assertTrue(exists("src/Makefile.in")); assertTrue(exists("src/sample/Makefile.in")); assertTrue(exists("src/aclocal.m4")); assertTrue(exists("config.status")); assertTrue(exists("Makefile")); String extension = Platform.getOS().equals(Platform.OS_WIN32) ? ".exe" : ""; assertTrue(exists("sample/a.out" + extension)); assertTrue(exists("sample/Makefile")); }
/** 编辑转换配置XML文件 ; */ public void editConfigXml() { ISelection selection = tableViewer.getSelection(); if (!selection.isEmpty() && selection != null && selection instanceof IStructuredSelection) { IStructuredSelection structuredSelection = (IStructuredSelection) selection; @SuppressWarnings("unchecked") Iterator<String[]> iter = structuredSelection.iterator(); String convertXml = iter.next()[1]; AddOrEditXmlConvertConfigDialog dialog = new AddOrEditXmlConvertConfigDialog(getShell(), false); dialog.create(); String convertXmlLoaction = root.getLocation() .append(ADConstants.AD_xmlConverterConfigFolder) .append(convertXml) .toOSString(); if (dialog.setInitEditData(convertXmlLoaction)) { int result = dialog.open(); // 如果点击的是确定按钮,那么更新列表 if (result == IDialogConstants.OK_ID) { String curentConvertXMl = dialog.getCurentConverXML(); refreshTable(); setTableSelection(curentConvertXMl); } } } else { MessageDialog.openInformation( getShell(), Messages.getString("dialogs.XmlConverterConfigurationDialog.msgTitle"), Messages.getString("dialogs.XmlConverterConfigurationDialog.msg2")); } }
boolean exists() { IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); final String projectName = getProjectName(); IPath wsPath = root.getLocation(); IPath localProjectPath = wsPath.append(projectName); IProject project = root.getProject(projectName); return project.exists() || localProjectPath.toFile().exists(); }
/** * Set the folder, in which we will look for files against which to compare other * files-under-test, from its workspace-relative path. CONTRACT: path string is not null or empty. */ public static void setGoldFolder(String workspaceRelativePath) { IWorkspace workspace = ResourcesPlugin.getWorkspace(); IWorkspaceRoot workspaceRoot = workspace.getRoot(); IPath rootPath = workspaceRoot.getLocation(); IPath goldPath = rootPath.append(workspaceRelativePath); IFolder gf = workspaceRoot.getFolder(goldPath); setGoldFolder(gf); }
private String getWorkspaceRelativePath(File folder) { IWorkspace workspace = ResourcesPlugin.getWorkspace(); IWorkspaceRoot root = workspace.getRoot(); IPath rootPath = root.getLocation(); Path path = new Path(folder.getAbsolutePath()); return path.makeRelativeTo(rootPath).toString(); }
public static File getCurrentWorkspace() { IWorkspace workspace = ResourcesPlugin.getWorkspace(); IWorkspaceRoot root = workspace.getRoot(); IPath location = root.getLocation(); location.toFile(); return location.toFile(); }
/** * This method find the absolute path from relative path. * * @param path : relative path * @return absolute path */ public static String convertPath(String path) { String newPath = ""; if (path.startsWith(BASE_PATH)) { IWorkspace workspace = ResourcesPlugin.getWorkspace(); IWorkspaceRoot root = workspace.getRoot(); String rplStr = path.substring(path.indexOf('}') + 4, path.length()); newPath = String.format("%s%s", root.getLocation().toOSString(), rplStr); } else { newPath = path; } return newPath; }
/** * Creates new file from workspace root with empty content. The filename can include relative path * as a part of the name but the the path has to be present on disk. The intention of the method * is to create files which do not belong to any project. * * @param name - filename. * @return full path of the created file. * @throws CoreException... * @throws IOException... */ public static IPath createWorkspaceFile(String name) throws CoreException, IOException { IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); IPath fullPath = workspaceRoot.getLocation().append(name); java.io.File file = new java.io.File(fullPath.toOSString()); if (!file.exists()) { boolean result = file.createNewFile(); Assert.assertTrue(result); } Assert.assertTrue(file.exists()); externalFilesCreated.add(fullPath.toOSString()); workspaceRoot.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor()); return fullPath; }
/** * Creates new folder from workspace root. The folder name can include relative path as a part of * the name. Nonexistent parent directories are being created as per {@link File#mkdirs()}. The * intention of the method is to create folders which do not belong to any project. * * @param name - folder name. * @return absolute location of the folder on the file system. * @throws IOException if something goes wrong. */ public static IPath createWorkspaceFolder(String name) throws CoreException, IOException { IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); IPath fullPath = workspaceRoot.getLocation().append(name); java.io.File folder = new java.io.File(fullPath.toOSString()); if (!folder.exists()) { boolean result = folder.mkdirs(); Assert.assertTrue(result); } Assert.assertTrue(folder.exists()); externalFilesCreated.add(fullPath.toOSString()); workspaceRoot.refreshLocal(IResource.DEPTH_INFINITE, NULL_MONITOR); return fullPath; }
public void testLoadWindowsFile() throws Exception { setUpProject(); WARProductModel model = new WARProductModel(); String separator = File.separator; String fileName = separator + "testWin.warproduct"; ClassLoader classLoader = getClass().getClassLoader(); model.load(classLoader.getResourceAsStream(fileName), false); IWARProduct product = (IWARProduct) model.getProduct(); IPath webXml = product.getWebXml(); IWorkspaceRoot wsRoot = ResourcesPlugin.getWorkspace().getRoot(); IPath absolutWebXmlPath = wsRoot.getLocation().append(webXml); File file = new File(absolutWebXmlPath.toOSString()); assertTrue(file.exists()); }
@Override public void setVisible(boolean visible) { super.setVisible(visible); // We update the image selection here rather than in {@link #createControl} because // that method is called when the wizard is created, and we want to wait until the // user has chosen a project before attempting to look up the right default image to use if (visible) { // Clear out old previews - important if the user goes back to page one, changes // asset type and steps into page 2 - at that point we arrive here and we might // display the old previews for a brief period until the preview delay timer expires. for (Control c : mPreviewArea.getChildren()) { c.dispose(); } mPreviewArea.layout(true); // Update asset type configuration: will show/hide parameter controls depending // on which asset type is chosen CreateAssetSetWizard wizard = (CreateAssetSetWizard) getWizard(); AssetType type = wizard.getAssetType(); assert type != null; configureAssetType(type); // Initial image - use the most recently used image, or the default launcher // icon created in our default projects, if there if (sImagePath == null) { IProject project = wizard.getProject(); if (project != null) { IResource icon = project.findMember("res/drawable-hdpi/icon.png"); // $NON-NLS-1$ if (icon != null) { IWorkspaceRoot workspace = ResourcesPlugin.getWorkspace().getRoot(); IPath workspacePath = workspace.getLocation(); sImagePath = workspacePath.append(icon.getFullPath()).toOSString(); } } } if (sImagePath != null) { mImagePathText.setText(sImagePath); } validatePage(); requestUpdatePreview(true /*quickly*/); if (mTextRadio.getSelection()) { mText.setFocus(); } } }
/** * Creates CDT project in a specific path in workspace adding specified configurations and opens * it. * * @param projectName - project name. * @param pathInWorkspace - path relative to workspace root. * @param configurationIds - array of configuration IDs. * @return - new {@link IProject}. * @throws CoreException - if the project can't be created. * @throws OperationCanceledException... */ public static IProject createCDTProject( String projectName, String pathInWorkspace, String[] configurationIds) throws OperationCanceledException, CoreException { CCorePlugin cdtCorePlugin = CCorePlugin.getDefault(); IWorkspace workspace = ResourcesPlugin.getWorkspace(); IWorkspaceRoot root = workspace.getRoot(); IProject project = root.getProject(projectName); IndexerPreferences.set(project, IndexerPreferences.KEY_INDEXER_ID, IPDOMManager.ID_NO_INDEXER); resourcesCreated.add(project); IProjectDescription prjDescription = workspace.newProjectDescription(projectName); if (pathInWorkspace != null) { IPath absoluteLocation = root.getLocation().append(pathInWorkspace); prjDescription.setLocation(absoluteLocation); } if (configurationIds != null && configurationIds.length > 0) { ICProjectDescriptionManager prjDescManager = cdtCorePlugin.getProjectDescriptionManager(); project.create(NULL_MONITOR); project.open(NULL_MONITOR); ICProjectDescription icPrjDescription = prjDescManager.createProjectDescription(project, false); ICConfigurationDescription baseConfiguration = cdtCorePlugin.getPreferenceConfiguration(TestCfgDataProvider.PROVIDER_ID); for (String cfgId : configurationIds) { icPrjDescription.createConfiguration(cfgId, cfgId + " Name", baseConfiguration); } prjDescManager.setProjectDescription(project, icPrjDescription); } project = cdtCorePlugin.createCDTProject(prjDescription, project, NULL_MONITOR); waitForProjectRefreshToFinish(); Assert.assertNotNull(project); project.open(null); Assert.assertTrue(project.isOpen()); return project; }
@Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); when(workspace.getRepository()).thenReturn(repository); when(workspace.getRoot()).thenReturn(root); when(workspace.getLocation()).thenReturn(location); when(repository.getCollection(anyString())).thenReturn(expectedEntity); when(root.getLocation()).thenReturn(path); when(root.toString()).thenReturn(""); when(path.append(any(IPath.class))).thenReturn(path); when(path.append(anyString())).thenReturn(path); when(location.append(any(IPath.class))).thenReturn(location); when(location.append(anyString())).thenReturn(location); container = new Container(path, workspace); }
/** * Copies the gold folder to the runtime workspace CONTRACT: folder exists in the devspace, * goldFolder has been set In this implementation, the gold folder is copied from * bin/test/GoldFolder */ public static void copyGoldFolder() { /* goldFolder (location where goldfolder should go in runspace) must not be null */ Assert.assertTrue(goldFolder != null); Bundle model2testsBundle = EclipsePlugin.getDefault().getBundle(); /* this is the source for our goldfolder in the devspace that we're copying to the runspace */ URL gfURL = model2testsBundle.getEntry("/"); /* devspace GoldFolder must exist */ // Assert.assertTrue(goldFolder.exists()); // Assert.assertTrue(gf.exists()); IWorkspace workspace = ResourcesPlugin.getWorkspace(); IWorkspaceRoot workspaceRoot = workspace.getRoot(); IPath rootPath = workspaceRoot.getLocation(); try { gfURL = Platform.asLocalURL(gfURL); } catch (IOException e) { e.printStackTrace(); } System.out.println("URL path: " + gfURL.getPath()); System.out.println("URL file: " + gfURL.getFile()); System.out.println("URL ref: " + gfURL.getRef()); File srcDir = new File(gfURL.getPath(), "GoldFolder"); Path p = new Path(gfURL.getPath()); IResource igf = ((Workspace) workspace).newResource(p, IResource.FOLDER); IPath gfpath = goldFolder.getFullPath(); File destDir = new File(gfpath.toOSString()); /* Make sure both of these directories exist */ System.out.println("Source directory exists: " + srcDir.exists()); /* destination directory shouldn't exist because we're going to create it */ // System.out.println ("Dest directory exists: " + destDir.exists()); /* Since assert isn't working for the moment... */ if (!srcDir.exists()) { System.out.println("GoldFolder not found"); Log.log("GoldFolder not found"); Assert.fail("GoldFolder not found"); } // Assert.assertTrue("Source goldfolder does not exist", srcDir.exists()); // Assert.assertTrue("Destination goldfolder does not exist", destDir.exists()); copyFolder(srcDir, destDir); }
@Test public void shouldConfigureSimpleProject() throws JavaModelException, IOException { IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); File workspaceRoot = root.getLocation().toFile(); File projectRoot = new File(workspaceRoot, "myProject"); projectRoot.mkdir(); File sourceFolder = new File(projectRoot, "src"); sourceFolder.mkdir(); File testFolder = new File(projectRoot, "test"); testFolder.mkdir(); File outputFolder = new File(projectRoot, "bin"); outputFolder.mkdir(); IJavaProject project = mock(IJavaProject.class); Properties sonarProperties = new Properties(); when(project.getOption(JavaCore.COMPILER_SOURCE, true)).thenReturn("1.6"); when(project.getOption(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, true)).thenReturn("1.6"); when(project.getPath()).thenReturn(new Path(projectRoot.getAbsolutePath())); IClasspathEntry[] cpes = new IClasspathEntry[] { createCPE(IClasspathEntry.CPE_SOURCE, sourceFolder), createCPE(IClasspathEntry.CPE_SOURCE, testFolder) }; when(project.getResolvedClasspath(true)).thenReturn(cpes); when(project.getOutputLocation()).thenReturn(new Path(outputFolder.getAbsolutePath())); configurator.configureJavaProject(project, sonarProperties); // TODO Find a way to mock a project inside Eclipse // assertTrue(sonarProperties.containsKey("sonar.sources")); // assertThat(sonarProperties.getProperty("sonar.sources"), is(sourceFolder.getPath())); // assertTrue(sonarProperties.containsKey("sonar.tests")); // assertThat(sonarProperties.getProperty("sonar.tests"), is(testFolder.getPath())); // assertTrue(sonarProperties.containsKey("sonar.binaries")); // assertThat(sonarProperties.getProperty("sonar.binaries"), is(outputFolder.getPath())); }
/** * Handles modify event of project name text box. * * @param event */ protected void handleModifyText(ModifyEvent event) { IWorkspace workspace = ResourcesPlugin.getWorkspace(); IWorkspaceRoot root = workspace.getRoot(); final int resourceProj = 4; String projName = ((Text) event.widget).getText(); IStatus projNameStatus = workspace.validateName(projName, resourceProj); IPath projLocation = root.getLocation().append(projName); if (projName.isEmpty()) { setDescription(Messages.wizPageDesc); setPageComplete(false); } else if (!projNameStatus.isOK()) { setErrorMessage(projNameStatus.getMessage()); setPageComplete(false); } else if (root.getProject(projName).exists()) { setErrorMessage(Messages.wizPageErrMsg1); setPageComplete(false); } else if (projLocation.toFile().exists()) { try { String path = projLocation.toFile().getCanonicalPath(); projLocation = new Path(path); } catch (IOException e) { Activator.getDefault().log(Messages.wizPageErrPath, e); setErrorMessage(Messages.wizPageErrPath); setPageComplete(false); } String nameInWorkspace = projLocation.lastSegment(); if (nameInWorkspace.equalsIgnoreCase(projName)) { String msg = String.format(Messages.wizPageNameMustBe, nameInWorkspace); setErrorMessage(msg); setPageComplete(false); } } else { setErrorMessage(null); setDescription(Messages.wizPageDesc); setPageComplete(true); } }
private String formatFileDetail(String changeLogLocation, String editorFileLocation) { // Format Path. Is a full path specified, or just file name? IWorkspaceRoot myWorkspaceRoot = getWorkspaceRoot(); String WorkspaceRoot = myWorkspaceRoot.getLocation().toOSString(); String changeLogLocNoRoot = ""; // $NON-NLS-1$ String editorFileLocNoRoot = ""; // $NON-NLS-1$ if (changeLogLocation.lastIndexOf(WorkspaceRoot) >= 0) { changeLogLocNoRoot = changeLogLocation.substring( changeLogLocation.lastIndexOf(WorkspaceRoot) + WorkspaceRoot.length(), changeLogLocation.length()); } else changeLogLocNoRoot = changeLogLocation; if (editorFileLocation.lastIndexOf(WorkspaceRoot) >= 0) { editorFileLocNoRoot = editorFileLocation.substring( editorFileLocation.lastIndexOf(WorkspaceRoot), editorFileLocation.lastIndexOf(WorkspaceRoot) + WorkspaceRoot.length()); } else editorFileLocNoRoot = editorFileLocation; File changelogLocation = new File(changeLogLocNoRoot); File fileLocation = new File(editorFileLocNoRoot); File reversePath = fileLocation.getParentFile(); String reversePathb = ""; // $NON-NLS-1$ while (reversePath.getParentFile() != null) { if (reversePath.compareTo(changelogLocation.getParentFile()) == 0) break; reversePath = reversePath.getParentFile(); } if (reversePath != null) reversePathb = fileLocation .toString() .substring(reversePath.toString().length() + 1, fileLocation.toString().length()); return reversePathb; }
/** * Import test project into the Eclipse workspace * * @return created projects */ public static IProject importEclipseProject(final String projectdir) throws IOException, CoreException { LOG.info("Importing Eclipse project : " + projectdir); final IWorkspaceRoot root = workspace.getRoot(); final String projectName = projectdir; File dst = new File(root.getLocation().toFile(), projectName); getProject(projectName, dst); final IProject project = workspace.getRoot().getProject(projectName); final List<IProject> addedProjectList = new ArrayList<IProject>(); workspace.run( new IWorkspaceRunnable() { public void run(final IProgressMonitor monitor) throws CoreException { // create project as java project if (!project.exists()) { final IProjectDescription projectDescription = workspace.newProjectDescription(project.getName()); projectDescription.setLocation(null); project.create(projectDescription, monitor); project.open(IResource.NONE, monitor); } else { project.refreshLocal(IResource.DEPTH_INFINITE, monitor); } addedProjectList.add(project); } }, workspace.getRoot(), IWorkspace.AVOID_UPDATE, MONITOR); JobHelpers.waitForJobsToComplete(); LOG.info("Eclipse project imported"); return addedProjectList.get(0); }
public PlwebAddProductWizard( URI domainModelURI, DiagramRoot diagramRoot, TransactionalEditingDomain editingDomain) { assert domainModelURI != null : "Domain model uri must be specified"; // $NON-NLS-1$ assert diagramRoot != null : "Doagram root element must be specified"; // $NON-NLS-1$ assert editingDomain != null : "Editing domain must be specified"; // $NON-NLS-1$ variativitySelectionPage = new VariativitySelectionPage(Messages.AddProduct_VariativityPageName); variativitySelectionPage.setTitle(Messages.AddProduct_VariativityPageName); variativitySelectionPage.setDescription(Messages.AddProduct_VariativityResolveItems); Area area = diagramRoot.getArea(); variativitySelectionPage.setModelElement(area); variativitySelectionPage.setDiagram(diagramRoot); IWorkspace workspace = ResourcesPlugin.getWorkspace(); IWorkspaceRoot root = workspace.getRoot(); IPath location = root.getLocation(); String resourcePath = domainModelURI.toPlatformString(true); filePath = location + (new Path(resourcePath)).toString(); projectName = resourcePath.substring(1, resourcePath.indexOf("/", 1)); myEditingDomain = editingDomain; this.diagramRoot = diagramRoot; }
public static IPath getWorkspaceLocation() { final IWorkspace iWorkspace = ResourcesPlugin.getWorkspace(); final IWorkspaceRoot iWorkspaceRoot = iWorkspace.getRoot(); return iWorkspaceRoot.getLocation(); }
/** * Ask for a file name and save the viewer containing the currently selected GraphicalEditPart to * a image file. */ @Override public void run() { final IEditorInput editorInput = (IEditorInput) getWorkbenchPart().getAdapter(IEditorInput.class); final SaveAsDialog dialog = new SaveAsDialog(new Shell(Display.getDefault())); dialog.setBlockOnOpen(true); if (editorInput == null) { dialog.setOriginalName("viewerImage" + counter + ".png"); } else { final String fileName = editorInput.getName(); final int extensionPos = fileName.lastIndexOf("."); dialog.setOriginalName(fileName.substring(0, extensionPos) + ".png"); } dialog.create(); dialog.setMessage( "If you don't choose an extension png will be used a default. " + "\n" + "Export is limited to file size of 15MByte -> you may use file ..(read more) " + "\n" + "type svg for very large graphs." + "\n" + "After export the workspace needs a manual refresh to show new image file."); dialog.setTitle("Specify file to export viewer image (png, jpeg, bmp, svg)"); dialog.open(); if (Window.CANCEL == dialog.getReturnCode()) { return; } final IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); final IPath path = root.getLocation().append(dialog.getResult()); int format; final String ext = path.getFileExtension(); if (ext.equals("png")) { format = SWT.IMAGE_PNG; // GIFs work only with 8Bit and not with 32 Bits color depth // } else if (ext.equals("gif")) { // format = SWT.IMAGE_GIF; } else if (ext.equals("jpeg")) { format = SWT.IMAGE_JPEG; } else if (ext.equals("bmp")) { format = SWT.IMAGE_BMP; // } else if (ext.equals("ico")) { // format = SWT.IMAGE_ICO; } else if (ext.equalsIgnoreCase("svg")) { format = SWT.IMAGE_UNDEFINED; // TODO: find a more appropriate constant for representing SVGs } else { MessageDialog.openError( null, "Invalid file extension!", "The specified extension (" + ext + ") is not a valid image format extension.\nPlease use png, jpeg, bmp or svg!"); return; } IFigure figure = ((SimpleRootEditPart) viewer.getRootEditPart()).getFigure(); if (figure instanceof Viewport) { // This seems to trim the figure to the smallest rectangle containing all child figures ((Viewport) figure).setSize(1, 1); ((Viewport) figure).validate(); figure = ((Viewport) figure).getContents(); } if (format == SWT.IMAGE_UNDEFINED) { try { final File file = path.toFile(); this.exportToSVG(file, figure); } catch (final IOException e) { e.printStackTrace(); } } else { final byte[] imageCode = createImage(figure, format); try { final File file = path.toFile(); final FileOutputStream fos = new FileOutputStream(file); fos.write(imageCode); fos.flush(); fos.close(); counter++; } catch (final IOException e) { e.printStackTrace(); } } }
public static String getWorkspaceProjectPath(String projectName) { IWorkspace workspace = ResourcesPlugin.getWorkspace(); IWorkspaceRoot root = workspace.getRoot(); IPath location = root.getLocation(); return location + "/" + projectName; }
private static String getDefaultWorkingDir() { final IWorkspaceRoot wroot = ResourcesPlugin.getWorkspace().getRoot(); return wroot.getLocation().toPortableString(); }
/** * Creates composite for project location. * * @param container */ private void createProjLocComposite(Composite container) { final IWorkspace workspace = ResourcesPlugin.getWorkspace(); IWorkspaceRoot root = workspace.getRoot(); Composite containerDefLoc = new Composite(container, SWT.NONE); GridLayout gridLayout = new GridLayout(); gridLayout.numColumns = 3; GridData gridData = new GridData(); gridData.horizontalAlignment = SWT.FILL; gridData.grabExcessHorizontalSpace = true; containerDefLoc.setLayout(gridLayout); containerDefLoc.setLayoutData(gridData); lblLocation = new Label(containerDefLoc, SWT.LEFT); lblLocation.setText(Messages.wizPageLocation); lblLocation.setEnabled(false); textLocation = new Text(containerDefLoc, SWT.SINGLE | SWT.BORDER); textLocation.setText(root.getLocation().toPortableString()); textLocation.setEnabled(false); gridData = new GridData(); gridData.widthHint = 270; gridData.horizontalAlignment = SWT.FILL; gridData.grabExcessHorizontalSpace = true; textLocation.setLayoutData(gridData); textLocation.addModifyListener( new ModifyListener() { @Override public void modifyText(ModifyEvent event) { String projLocation = ((Text) event.widget).getText(); Path path = new Path(projLocation); IStatus status = workspace.validateProjectLocation(null, path); if (projLocation.length() == 0) { setDescription(Messages.wizPageEnterLoc); setPageComplete(false); } else if (status.isOK()) { setErrorMessage(null); setPageComplete(true); } else { setErrorMessage(status.getMessage()); setPageComplete(false); } } }); buttonBrowse = new Button(containerDefLoc, SWT.PUSH); buttonBrowse.setText(Messages.wizPageBrowse); buttonBrowse.setEnabled(false); buttonBrowse.addSelectionListener( new SelectionListener() { @Override public void widgetSelected(SelectionEvent arg0) { browseBtnListener(); } @Override public void widgetDefaultSelected(SelectionEvent arg0) {} }); gridData = new GridData(); gridData.widthHint = 80; buttonBrowse.setLayoutData(gridData); }