use of org.eclipse.core.filesystem.IFileStore in project linuxtools by eclipse.
the class PerfSaveSessionHandler method saveData.
@Override
public IPath saveData(String filename) {
// get paths
IPath newDataLoc = getNewDataLocation(filename, DATA_EXT);
IPath defaultDataLoc = PerfPlugin.getDefault().getPerfProfileData();
URI newDataLocURI = null;
URI defaultDataLocURI = null;
// get files
IRemoteFileProxy proxy = null;
try {
newDataLocURI = new URI(newDataLoc.toPortableString());
defaultDataLocURI = new URI(defaultDataLoc.toPortableString());
proxy = RemoteProxyManager.getInstance().getFileProxy(newDataLocURI);
} catch (URISyntaxException e) {
openErroDialog(Messages.MsgProxyError, Messages.MsgProxyError, newDataLoc.lastSegment());
} catch (CoreException e) {
openErroDialog(Messages.MsgProxyError, Messages.MsgProxyError, newDataLoc.lastSegment());
}
IFileStore newDataFileStore = proxy.getResource(newDataLocURI.getPath());
IFileStore defaultDataFileStore = proxy.getResource(defaultDataLocURI.getPath());
if (canSave(newDataLoc)) {
// copy default data into new location
try {
defaultDataFileStore.copy(newDataFileStore, EFS.OVERWRITE, null);
PerfPlugin.getDefault().setPerfProfileData(newDataLoc);
try {
PerfProfileView view = (PerfProfileView) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView(PerfPlugin.VIEW_ID);
view.setContentDescription(newDataLoc.toOSString());
} catch (PartInitException e) {
// fail silently
}
IFileInfo info = newDataFileStore.fetchInfo();
info.setAttribute(EFS.ATTRIBUTE_READ_ONLY, true);
newDataFileStore.putInfo(info, EFS.SET_ATTRIBUTES, null);
return newDataLoc;
} catch (CoreException e) {
openErroDialog(Messages.PerfSaveSession_failure_title, Messages.PerfSaveSession_failure_msg, newDataLoc.lastSegment());
}
}
return null;
}
use of org.eclipse.core.filesystem.IFileStore in project linuxtools by eclipse.
the class PerfSaveStatsHandler method saveData.
@Override
public IPath saveData(String filename) {
IPath newDataLoc = getNewDataLocation(filename, DATA_EXT);
IPerfData statData = PerfPlugin.getDefault().getStatData();
BufferedWriter writer = null;
OutputStreamWriter osw = null;
try {
IRemoteFileProxy proxy = null;
proxy = RemoteProxyManager.getInstance().getFileProxy(getWorkingDirURI());
if (proxy == null) {
openErroDialog(Messages.PerfSaveStat_error_title, Messages.PerfSaveStat_error_msg, newDataLoc.lastSegment());
return null;
}
IFileStore newDataFileStore = proxy.getResource(newDataLoc.toOSString());
osw = new OutputStreamWriter(newDataFileStore.openOutputStream(EFS.NONE, null));
writer = new BufferedWriter(osw);
writer.write(statData.getPerfData());
closeResource(writer);
IFileInfo info = newDataFileStore.fetchInfo();
info.setAttribute(EFS.ATTRIBUTE_READ_ONLY, true);
newDataFileStore.putInfo(info, EFS.SET_ATTRIBUTES, null);
return newDataLoc;
} catch (IOException | CoreException e) {
openErroDialog(Messages.PerfSaveStat_error_title, Messages.PerfSaveStat_error_msg, newDataLoc.lastSegment());
} finally {
closeResource(writer);
}
return null;
}
use of org.eclipse.core.filesystem.IFileStore in project linuxtools by eclipse.
the class LaunchOptions method isValid.
/**
* Determines whether the global oprofile options represented by this
* object are valid
* @return whether the options are valid
*/
public boolean isValid() {
IRemoteFileProxy proxy = null;
try {
proxy = RemoteProxyManager.getInstance().getFileProxy(getOprofileProject());
} catch (CoreException e) {
e.printStackTrace();
}
// The only point of contention is whether the specified vmlinux *file* exists.
String fn = options.getKernelImageFile();
if (fn != null && fn.length() > 0) {
IFileStore fileStore = proxy.getResource(options.getKernelImageFile());
return (fileStore.fetchInfo().exists() && !fileStore.fetchInfo().isDirectory());
}
return true;
}
use of org.eclipse.core.filesystem.IFileStore in project linuxtools by eclipse.
the class OprofileSetupTab method handleKernelImageFileTextModify.
// handles text modification events for all text boxes in this tab
private void handleKernelImageFileTextModify(Text text) {
String errorMessage = null;
String filename = text.getText();
if (filename.length() > 0) {
try {
proxy = RemoteProxyManager.getInstance().getFileProxy(getOprofileProject());
} catch (CoreException e) {
e.printStackTrace();
}
IFileStore fileStore = proxy.getResource(filename);
if (!fileStore.fetchInfo().exists() || fileStore.fetchInfo().isDirectory()) {
// $NON-NLS-1$
String msg = OprofileLaunchMessages.getString("tab.global.kernelImage.kernel.nonexistent");
errorMessage = MessageFormat.format(msg, filename);
}
// seems odd, but must set it even if it is invalid so that performApply
// and isValid work properly
options.setKernelImageFile(filename);
} else {
// no kernel image file
// $NON-NLS-1$
options.setKernelImageFile("");
}
// Update dialog and error message
setErrorMessage(errorMessage);
updateLaunchConfigurationDialog();
}
use of org.eclipse.core.filesystem.IFileStore in project linuxtools by eclipse.
the class OprofileSetupTab method showFileDialog.
// Displays a file dialog to allow the user to select the kernel image file
private void showFileDialog(Shell shell) {
try {
proxy = RemoteProxyManager.getInstance().getFileProxy(getOprofileProject());
} catch (CoreException e) {
e.printStackTrace();
}
FileDialog d = new FileDialog(shell, SWT.OPEN);
IFileStore kernel = proxy.getResource(options.getKernelImageFile());
if (!kernel.fetchInfo().exists()) {
// $NON-NLS-1$
kernel = proxy.getResource("/boot");
if (!kernel.fetchInfo().exists()) {
// $NON-NLS-1$
kernel = proxy.getResource("/");
}
}
d.setFileName(kernel.toString());
// $NON-NLS-1$
d.setText(OprofileLaunchMessages.getString("tab.global.selectKernelDialog.text"));
String newKernel = d.open();
if (newKernel != null) {
kernel = proxy.getResource(newKernel);
if (!kernel.fetchInfo().exists()) {
MessageBox mb = new MessageBox(shell, SWT.ICON_ERROR | SWT.RETRY | SWT.CANCEL);
// $NON-NLS-1$
mb.setMessage(OprofileLaunchMessages.getString("tab.global.selectKernelDialog.error.kernelDoesNotExist.text"));
switch(mb.open()) {
case SWT.RETRY:
// Ok, it's recursive, but it shouldn't matter
showFileDialog(shell);
break;
default:
case SWT.CANCEL:
break;
}
} else {
kernelImageFileText.setText(newKernel);
}
}
}
Aggregations