use of org.eclipse.core.filesystem.IFileStore in project linuxtools by eclipse.
the class ImageBuildPage method createControl.
@Override
public void createControl(Composite parent) {
final Composite container = new Composite(parent, SWT.NULL);
FormLayout layout = new FormLayout();
layout.marginHeight = 5;
layout.marginWidth = 5;
container.setLayout(layout);
Label label = new Label(container, SWT.NULL);
Label nameLabel = new Label(container, SWT.NULL);
nameLabel.setText(WizardMessages.getString(NAME_LABEL));
nameText = new Text(container, SWT.BORDER | SWT.SINGLE);
nameText.addModifyListener(Listener);
nameText.setToolTipText(WizardMessages.getString(NAME_TOOLTIP));
Label dirLabel = new Label(container, SWT.NULL);
dirLabel.setText(WizardMessages.getString(DIRECTORY_LABEL));
directoryText = new Text(container, SWT.BORDER | SWT.SINGLE);
directoryText.addModifyListener(Listener);
directoryText.setToolTipText(WizardMessages.getString(DIRECTORY_TOOLTIP));
Button browse = new Button(container, SWT.NULL);
browse.setText(WizardMessages.getString(BROWSE_LABEL));
browse.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> {
DirectoryDialog d = new DirectoryDialog(container.getShell());
String k = d.open();
if (k != null)
directoryText.setText(k);
}));
editButton = new Button(container, SWT.NULL);
editButton.setText(WizardMessages.getString(EDIT_LABEL));
editButton.setEnabled(false);
editButton.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> {
String dir = directoryText.getText();
IFileStore fileStore = EFS.getLocalFileSystem().getStore(// $NON-NLS-1$
new Path(dir).append("Dockerfile"));
// $NON-NLS-1$
java.nio.file.Path filePath = Paths.get(dir, "Dockerfile");
if (!Files.exists(filePath)) {
try {
Files.createFile(filePath);
} catch (IOException e1) {
// File won't exist, and directory should be
// writable
}
}
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
try {
IEditorPart dockerFileEditor = IDE.openEditorOnFileStore(page, fileStore);
IWorkbenchPartSite site = page.getActivePart().getSite();
EModelService s = site.getService(EModelService.class);
MPartSashContainerElement p = site.getService(MPart.class);
s.detach(p, 100, 100, 500, 375);
dockerFileEditor.getEditorSite().getShell().setText(WizardMessages.getString(// $NON-NLS-1$
"ImageBuild.editor.name"));
editors.add(dockerFileEditor);
} catch (PartInitException e1) {
Activator.log(e1);
}
validate();
}));
Point p1 = label.computeSize(SWT.DEFAULT, SWT.DEFAULT);
Point p2 = directoryText.computeSize(SWT.DEFAULT, SWT.DEFAULT);
Point p3 = browse.computeSize(SWT.DEFAULT, SWT.DEFAULT);
int centering = (p2.y - p1.y + 1) / 2;
int centering2 = (p3.y - p2.y + 1) / 2;
FormData f = new FormData();
f.top = new FormAttachment(0);
label.setLayoutData(f);
f = new FormData();
f.top = new FormAttachment(label, 11 + centering + centering2);
f.left = new FormAttachment(0, 0);
nameLabel.setLayoutData(f);
f = new FormData();
f.top = new FormAttachment(label, 11 + centering2);
f.left = new FormAttachment(nameLabel, 5);
f.right = new FormAttachment(browse, -10);
nameText.setLayoutData(f);
f = new FormData();
f.top = new FormAttachment(nameLabel, 11 + centering + centering2);
f.left = new FormAttachment(0, 0);
dirLabel.setLayoutData(f);
f = new FormData();
f.top = new FormAttachment(nameLabel, 11);
f.right = new FormAttachment(100);
editButton.setLayoutData(f);
f = new FormData();
f.top = new FormAttachment(nameLabel, 11);
f.right = new FormAttachment(editButton, -10);
browse.setLayoutData(f);
f = new FormData();
f.top = new FormAttachment(nameLabel, 11 + centering2);
f.left = new FormAttachment(nameLabel, 5);
f.right = new FormAttachment(browse, -10);
directoryText.setLayoutData(f);
if (lastDirectoryPath != null) {
directoryText.setText(lastDirectoryPath);
}
setControl(container);
setPageComplete(false);
}
use of org.eclipse.core.filesystem.IFileStore in project linuxtools by eclipse.
the class JavaDocToc method getTopics.
@Override
public ITopic[] getTopics() {
try {
// Finds the path to the javadoc directory from the preference
// store, and gets all children directories.
ArrayList<ITopic> topics = new ArrayList<>();
IPreferenceStore ps = JavaDocPlugin.getDefault().getPreferenceStore();
IPath javadocLocation = new Path(ps.getString(PreferenceConstants.JAVADOCS_DIRECTORY));
IFileSystem fs = EFS.getLocalFileSystem();
IFileStore htmlDir = fs.getStore(javadocLocation);
IFileStore[] files = htmlDir.childStores(EFS.NONE, null);
Arrays.sort(files, new Comparator<IFileStore>() {
@Override
public int compare(IFileStore arg0, IFileStore arg1) {
return (arg0.getName().compareToIgnoreCase(arg1.getName()));
}
});
// directory and generates topics for them.
for (IFileStore file : files) {
String name = file.fetchInfo().getName();
if (fs.getStore(// $NON-NLS-1$
javadocLocation.append(name)).fetchInfo().exists() && fs.getStore(// $NON-NLS-1$
javadocLocation.append(name + "/index.html")).fetchInfo().exists()) {
ITopic topic = new JavaDocTopic(name);
topics.add(topic);
}
}
// Returns an array of the generated topics
ITopic[] retval = new ITopic[topics.size()];
return topics.toArray(retval);
} catch (CoreException e) {
}
// child directories present.
return null;
}
use of org.eclipse.core.filesystem.IFileStore in project linuxtools by eclipse.
the class RemoteProxyCMainTab method checkProgram.
private boolean checkProgram(IProject project) {
String name = fProgText.getText().trim();
if (name.length() == 0) {
setErrorMessage(ProxyLaunchMessages.executable_is_not_specified);
return false;
}
// changed (binary or project name). See bug 277663.
if (name.equals(fPreviouslyCheckedProgram)) {
if (fPreviouslyCheckedProgramErrorMsg != null) {
setErrorMessage(fPreviouslyCheckedProgramErrorMsg);
}
return fPreviouslyCheckedProgramIsValid;
}
fPreviouslyCheckedProgram = name;
// we'll flip this below if
fPreviouslyCheckedProgramIsValid = true;
// not true
// we'll set this below if
fPreviouslyCheckedProgramErrorMsg = null;
// there's an error
IPath exePath;
URI exeURI = null;
boolean passed = false;
try {
exeURI = new URI(name);
String exePathStr = exeURI.getPath();
if (exePathStr == null) {
setErrorMessage(fPreviouslyCheckedProgramErrorMsg = ProxyLaunchMessages.uri_of_executable_is_invalid);
fPreviouslyCheckedProgramIsValid = false;
return false;
}
exePath = Path.fromOSString(exeURI.getPath());
if (!exePath.isAbsolute() && exeURI != null && !exeURI.isAbsolute()) {
URI projectURI = project.getLocationURI();
exeURI = new URI(projectURI.getScheme(), projectURI.getAuthority(), projectURI.getRawPath() + '/' + exePath.toString(), EMPTY_STRING);
}
if (exeURI != null) {
passed = true;
}
} catch (URISyntaxException e) {
setErrorMessage(fPreviouslyCheckedWorkingDirErrorMsg = ProxyLaunchMessages.uri_of_executable_is_invalid);
fPreviouslyCheckedProgramIsValid = false;
return false;
}
if (!passed) {
setErrorMessage(fPreviouslyCheckedProgramErrorMsg = LaunchMessages.CMainTab_Program_does_not_exist);
fPreviouslyCheckedProgramIsValid = false;
return false;
}
passed = false;
try {
IRemoteFileProxy exeFileProxy;
exeFileProxy = RemoteProxyManager.getInstance().getFileProxy(exeURI);
if (exeFileProxy != null) {
String exeFilePath = exeURI.getPath();
IFileStore exeFS = exeFileProxy.getResource(exeFilePath);
if (exeFS != null) {
IFileInfo exeFI = exeFS.fetchInfo();
if (exeFI != null) {
if (dontCheckProgram || enableCopyFromExeButton.getSelection()) {
// The program may not exist yet if we are copying it.
passed = true;
} else {
if (exeFI.exists()) {
if (exeFI.getAttribute(EFS.ATTRIBUTE_EXECUTABLE) && !exeFI.isDirectory()) {
passed = true;
} else {
setErrorMessage(fPreviouslyCheckedProgramErrorMsg = ProxyLaunchMessages.executable_does_not_have_execution_rights);
}
} else {
setErrorMessage(fPreviouslyCheckedProgramErrorMsg = ProxyLaunchMessages.executable_does_not_exist);
}
}
} else {
setErrorMessage(fPreviouslyCheckedProgramErrorMsg = ProxyLaunchMessages.error_accessing_executable);
}
} else {
setErrorMessage(fPreviouslyCheckedProgramErrorMsg = ProxyLaunchMessages.error_accessing_executable);
}
} else {
setErrorMessage(fPreviouslyCheckedProgramErrorMsg = ProxyLaunchMessages.scheme_error_in_executable);
}
} catch (CoreException e) {
setErrorMessage(fPreviouslyCheckedProgramErrorMsg = ProxyLaunchMessages.connection_of_executable_cannot_be_opened);
}
if (!passed) {
fPreviouslyCheckedProgramIsValid = false;
return false;
}
setErrorMessage(null);
return true;
}
use of org.eclipse.core.filesystem.IFileStore in project linuxtools by eclipse.
the class AbstractRemoteTest method deleteResource.
protected void deleteResource(String directory) {
IRemoteServicesManager sm = getServicesManager();
IRemoteConnection conn = sm.getConnectionType("ssh").getConnection(CONNECTION_NAME);
assertNotNull(conn);
IRemoteFileService fileManager = conn.getService(IRemoteFileService.class);
assertNotNull(fileManager);
final IFileStore dstFileStore = fileManager.getResource(directory);
try {
dstFileStore.delete(EFS.NONE, null);
} catch (CoreException e) {
}
}
use of org.eclipse.core.filesystem.IFileStore in project linuxtools by eclipse.
the class AbstractTest method createConfiguration.
protected ILaunchConfiguration createConfiguration(IProject proj) throws CoreException {
String projectName = proj.getName();
String binPath = "";
ILaunchConfigurationType configType = getLaunchConfigType();
ILaunchConfigurationWorkingCopy wc = configType.newInstance(null, getLaunchManager().generateLaunchConfigurationName(projectName));
if (proj.getLocation() == null) {
IFileStore fileStore = null;
try {
fileStore = EFS.getStore(new URI(proj.getLocationURI() + BIN_DIR + IPath.SEPARATOR + projectName));
} catch (URISyntaxException e) {
fail(NLS.bind(Messages.getString("AbstractTest.No_binary"), // $NON-NLS-1$
projectName));
}
if ((fileStore instanceof LocalFile)) {
fail(NLS.bind(Messages.getString("AbstractTest.No_binary"), // $NON-NLS-1$
projectName));
}
binPath = EFSExtensionManager.getDefault().getPathFromURI(proj.getLocationURI()) + BIN_DIR + IPath.SEPARATOR + proj.getName();
} else {
IResource bin = proj.findMember(new Path(BIN_DIR).append(projectName));
if (bin == null) {
fail(NLS.bind(Messages.getString("AbstractTest.No_binary"), // $NON-NLS-1$
projectName));
}
binPath = bin.getProjectRelativePath().toString();
wc.setMappedResources(new IResource[] { bin, proj });
}
wc.setAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_NAME, binPath);
wc.setAttribute(ICDTLaunchConfigurationConstants.ATTR_PROJECT_NAME, projectName);
wc.setAttribute(ICDTLaunchConfigurationConstants.ATTR_WORKING_DIRECTORY, (String) null);
// Make launch run in foreground
wc.setAttribute(IDebugUIConstants.ATTR_LAUNCH_IN_BACKGROUND, false);
setProfileAttributes(wc);
return wc.doSave();
}
Aggregations