NetBeans platform - open file from output console - java

I would like to open file specified by its path in NetBeans editor (IOProvider.getDefault().getIO(...);).
I would like the same functionality as is when some Java/C/C++ or any other programming language prints an Exception. As far as I went for now:
Write the output in console (see the example at the end)
By using OutputListener resolve what should be printed as hypertext
OutputListener.outputLineAction that defines what to do when clicked on hypertext IOColorPrint.print(InputOutput io, CharSequence text, OutputListener listener, boolean important, Color color)
Open the file on the system when clicking on
An example of error message I need to resolve:
The export was successful. The exported file can be found in: C:\Users\MY_USER\Desktop\myFile.xml
The problem that I have is that I have to print all the output in one line and the OutputEvent gives me all the line. Is there any way to get only the Highlited text (The path) ?

This call open new console output tab:
IOProvider.getDefault().getIO(...)
You should take inputStream and use class while(x=is.read()!=n ....
IOProvider.getDefault().getIO(...).getInputStream
Let me know, if this was usefull.

Here the Listener :
public class HyperlinkToFileOutputListener implements OutputListener {
private final File file;
public HyperlinkToFileOutputListener(File file) {
this.file = file;
}
#Override
public void outputLineSelected(OutputEvent oe) {
}
#Override
public void outputLineAction(OutputEvent oe) {
try {
if (file.exists()) {
Desktop.getDesktop().open(file);
}
} catch (IOException ex) {
Exceptions.printStackTrace(ex);
}
}
#Override
public void outputLineCleared(OutputEvent oe) {
}
}
here the call
IOColorPrint.print(io, file.getName(), new HyperlinkToFileOutputListener(file), true, Color.BLUE);
best regards

Related

Uploading a file from android phone that contains a space in its path

I'm having a hard time passing files with spaces in their names into Twilio chat.
Forgetting about the fact that I'm using Twilio, and just concentrating that I'm trying to upload a file from within the Android phone. I have an image on my android phone which I found its path as /Internal storage/Download/4893079.jpg
Below is the full code:
public void testing() {
Messages messagesObject = channel.getMessages();
try {
messagesObject.sendMessage(
Message.options()
.withMedia(new FileInputStream("/Internal%20storage/Download/4893079.jpg"), "image/jpeg")
.withMediaFileName("4893079.jpg")
.withMediaProgressListener(new ProgressListener() {
#Override
public void onStarted() {
System.out.println("Upload started");
}
#Override
public void onProgress(long bytes) {
System.out.println("Uploaded " + bytes + " bytes");
}
#Override
public void onCompleted(String mediaSid) {
System.out.println("Upload completed");
}
}),
new CallbackListener<Message>() {
#Override
public void onSuccess(Message msg) {
System.out.println("Successfully sent MEDIA message");
}
#Override
public void onError(ErrorInfo error) {
System.out.println("Error sending MEDIA message");
}
});
} catch (FileNotFoundException e) {
System.out.println("FAILED HORRIBLY");
System.out.println(e);
e.printStackTrace();
}
}
However running the app I end up with the error,
java.io.FileNotFoundException: /Internal%20storage/Download/4893079.jpg (No such file or directory)
As shown I've tried replacing space with %20, but that didn't work. I've also tried \ , \\ . However non of them worked. I've looked at Opening a local Android File with spaces, Save file in Android with spaces in file name.
How should I be replacing the space?
You need to get the actual path programmatically. So the real path is
Environment.getExternalStorageDirectory().toString() + "/Download/4893079.jpg"
Internal storage is just something the user sees, but not a real path on the machine.

How to catch file opening eclipse plugin

I'm new at plugin development. I have my own editor for files *.example.
I extend org.eclipse.ui.editors.text.TextEditor to edit it.
I want to catch the moment when this file is opened and post it to log (something like "file new.example is opened). But I really don't understand how to do it.
One way is to override the init method of the editor and use the editor input parameter:
#Override
public void init(final IEditorSite site, final IEditorInput input) throws PartInitException {
super.init(site, input);
if (input instanceof IFileEditorInput) {
IFile file = ((IFileEditorInput)input).getFile();
// TODO log the IFile
}
}
Note: The editor input is not always IFileEditorInput, see this answer for more details.

File upload and download in vaadin

Am very very new to Vaadin. Am setting up the project by looking into Github and other docs, where am using Spring-security, Vaadin, Maven.
I created sample vaadin-maven with spring security project. Now am getting login page then after suucessful login, am getting some MainView.java.
Am trying to change the upload .xls file and read that file and do some functionality and then download pop-up.
I have followed http://demo.vaadin.com/sampler/#ui/data-input/other/upload , but errors. unable to reproduce my output.
For now, am able to read the file using path " final String FILE_PATH = "F://input.xls";" But, i need option to upload the file and then use that file for further functionality.
After the functionality completed, i need to download the file.
Please suggest me how can i browse the file and upload and use the uploaded file for ding some read and write operation and then download Vaadin.
Am having sleepless nights for this. Please suggest me how can i come out of this.
Here is my code:
#Component
#Scope("prototype")
#VaadinView(RoleAdminView.NAME)
#Secured("ROLE_ADMIN")
public class RoleAdminView extends Panel implements View
{
public static final String NAME = "role_admin";
#PostConstruct
public void PostConstruct()
{
LoggerFactory.getLogger(this.getClass()).debug("POST");
setSizeFull();
VerticalLayout layout = new VerticalLayout();
layout.setSpacing(true);
layout.setMargin(true);
layout.addComponent(new Button());
layout.addComponent(new Label("ROLE_ADMIN"));
layout.addComponent(new Link("Go back", new ExternalResource("#!" +
MainView.NAME)));
setContent(layout);
}
#Override
public void enter(ViewChangeListener.ViewChangeEvent event)
{
}
}
A big thank you in advance. Hope you guys sort out my issue :)
You can do,
public class RoleAdminView extends Panel implements View{
//add a button view
//
#Override
public void uploadFailed(Upload.FailedEvent event) {
Notification.show(event.getFilename() + "----" + event.getMIMEType());
//here it will show the error if upload failed
}
#Override
public void uploadSucceeded(SucceededEvent event) {
/// do your functionlity
}
#Override
public OutputStream receiveUpload(String filename, String mimeType) {
FileOutputStream fos = null;
// do your functionality to save in any path or server path
return fos; // Return the output stream to write to
}
}
I hope this my help you :)

Opening file geodatabase using ESRI android API

for some time I am trying to open file godatabase on android using ESRI api in version 10.2.
I have a file godatabase made with Arccatalog 10.1. It contains one layer. I can open it in Arcmap so everything looks fine here.
The geodatabase is in folder named android.gdb
I copied it to microSD card and tried to open it using this code:
new com.esri.core.gdb.Geodatabase("/mnt/sdcard2/android.gdb");
The "/mnt/sdcard2/android.gdb" file exists and is a folder and I have read and write permissions.
I get a RuntimeException with the message that the goedatabase file could not be opened.
Anyone had similiar issues with that ?
The ESRI runtime api for android wont be able to open that kind of database. It uses a proprietary version of a geodatabase built in SQLLite. You will need to publish a service in ArcGisOnline or ArcServer 10.2 and call the GeodatabaseSyncTask object in order to get a version of your database in the right format onto the device. On your published feature service you will need to make sure Sync is enabled. Then you can utilize this code to call your feature service and store it locally. This code is based on this ESRI sample -- https://developers.arcgis.com/android/sample-code/offline-editor/
public void LoadGdb(UserCredentials credentials, Polygon extent, SpatialReference spatRef){
mapExtent = extent;
mapSpatialRef = spatRef;
String replicaUrl = callingActivity.getResources().getString(R.string.feature_service_url);
gdbTask = new GeodatabaseSyncTask(replicaUrl, credentials);
gdbTask.fetchFeatureServiceInfo(new CallbackListener<FeatureServiceInfo>() {
#Override
public void onError(Throwable e) {
Log.e(TAG, "", e);
}
#Override
public void onCallback(FeatureServiceInfo objs) {
if (objs.isSyncEnabled()) {
requestGdbInOneMethod(gdbTask, mapExtent, mapSpatialRef);
}
}
});
}
protected void requestGdbInOneMethod(GeodatabaseSyncTask geodatabaseSyncTask, Polygon extent, SpatialReference spatRef) {
GenerateGeodatabaseParameters params = new GenerateGeodatabaseParameters({0, 1}, extent,
spatRef, true, SyncModel.LAYER, spatRef);
CallbackListener<String> gdbResponseCallback = new CallbackListener<String>() {
#Override
public void onCallback(String obj) {
try {
// This onCallback gets called after the generateGeodatabase
// function on the GeodatabaseSyncTask is called.
// You can store a reference to this database or you can load it
// with your code and point it to the gdbFileName location
Geodatabase myGeodatabase = (Geodatabase)obj;
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
#Override
public void onError(Throwable e) {
Log.e(TAG, "", e);
}
};
GeodatabaseStatusCallback statusCallback = new GeodatabaseStatusCallback() {
#Override
public void statusUpdated(GeodatabaseStatusInfo status) {
showMessage(callingActivity, status.getStatus().toString());
}
};
// !! THE gdbFileName is a string of the path and filename
// where the geodatabse will be stored.
geodatabaseSyncTask.generateGeodatabase(params, gdbFileName, false, statusCallback, gdbResponseCallback);
}
To load a local file you need to use ArcGIS Desktop 10.2.1 or higher to generate a Runtime Geodatabase file with a *.geodatabase file extension. See the instructions here: http://resources.arcgis.com/en/help/main/10.2/index.html#//00660000045q000000

How to fetch path of a file from preference page and print the Output on console via Button on Workbench?

I have made one preference page whose programming is:
public class SAML
extends FieldEditorPreferencePage
implements IWorkbenchPreferencePage {
public SAML() {
super(GRID);
setPreferenceStore(RmpPlugin.getDefault().getPreferenceStore());
setDescription("Browse Appropriate files");
}
public FileFieldEditor f;
public FileFieldEditor f1;
public void createFieldEditors() {
f=new FileFieldEditor(PreferenceConstants.P_PATH,
"&Prism.bat File:", getFieldEditorParent());
addField(f);
f1=new FileFieldEditor(PreferenceConstants.P_PATH1,
"&NuSMV Application File:", getFieldEditorParent());
addField(f1);
}
I want to get path of FileFieldEditor f and want this path to run on a button which is embedded on workbench (but programming of that button is in different project on the same workspace).
The button programming which has hard coded path of "prism.bat" file is:
try {
//to clear the console on every click of button
IViewPart view = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView(IConsoleConstants.ID_CONSOLE_VIEW);
if (view != null) {
(myConsole).clearConsole();
}
ProcessBuilder pb=new ProcessBuilder("C:\\Program Files\\prism-4.0\\bin\\prism.bat");
pb.directory(new File("C:\\Program Files\\prism-4.0\\bin"));
Process p=pb.start();
BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
String in;
while((in = input.readLine()) != null) {
out.println(in);
}
int exitVal=p.waitFor();
if(exitVal==0)
{
out.println("Process Successful");
out.println("Printing on console with Exitvalue =0");
}
else
{out.println("Process failed");
out.println("Exitvalue = 1");
}
}
catch (Exception e)
{
out.println(e.toString());
e.printStackTrace();
}
But I want to fetch file from my preference page FileFieldEditor f and want this path to embed in button programming so that when button is pressed, result is shown.
You need two parts:
Code that initialize the default for the preference
Code that use the current value
To set the default, you use the following code in the Activator:
public class Activator extends AbstractUIPlugin {
#Override
public void start(BundleContext context) throws Exception {
super.start(context);
IPreferenceStore ps = getPreferenceStore();
ps.setDefault(SHOW_IMAGE, true);
}
public static final String SHOW_IMAGE = "showImage";
}
Alternatively, you can use the org.eclipse.core.runtime.preferences extension point...
Note that the code above assume that the type of the preference is Boolean - there are other methods for numbers, strings, etc... A file name is a string.
To use the current value, just use
if (Activator.getDefault().getPreferenceStore().getBoolean(Activator.SHOW_IMAGE)) {
…
}
The following slides contains a little more information...

Categories

Resources