Eclipse RCP 4.x - Defining workspace location - java

I know that this question was asked many times, but I didn't find an exact answer which would fulfill my desires :)
Long story short:
I've got simple E4 application, product project, feature and main plugin with simple trim window.
Works, after exporting works too.
Now. I add lifeCycleURI property, create bundleclass for it and create simple dialog with Text area and a Button. Run it\export it and it works, before running main Trim Window dialog is shown. Fine.. Cool etc.
But I want to enter location eg. C:\TEST and after clicking button I want it to be my workspace area for the application (with .metedata and so on). HOW ???
Of course I've tried with :
Location instanceLocation = Platform.getInstanceLocation();
instanceLocation.set(new URL("file", null, "C:\TEST"), false);
But... It says that I can't change location cause it is already set... Tried to use above in Activator. The same. Tried to add
-data #noDefault in products Launching Arguments ... The same...
I always try to accomplish my tasks by myself but this.... this... ehh... Help ?

You should be able to do this in the #PostContextCreate method of the life cycle class. Don't specify the '-data' argument
#PostContextCreate
public void postContextCreate()
{
Location instanceLoc = Platform.getInstanceLocation();
// Stop if location is set
if (instanceLoc.isSet())
return;
File file = new File("C:\\TEST");
instanceLocation.set(file.toURL(), false);
}
Note: You need '\\' in your file path.
This is adapted from code which I use in my e4 RCP.
If you are currently testing the application from within Eclipse you will need to clear the workspace location in the 'Run Configuration' for the application. Open 'Run > Run Configurations', find your application and clear the 'Location' field on the 'Main' tab.

Related

Set the initial directory in SWT FileDialog

I'm working on an Eclipse RCP project and need to let the user select some file.
For convenience, based on some conditions, the initial directory of the file choosing dialog should be set prior to opening it.
As I'm bound to Eclipse RCP / SWT, I am working with the org.eclipse.swt.widgets.FileDialog.
The documentation of this FileDialog points out to use the setFilterPath(String string)-method which should do exactly what I need (see documentation).
FileDialog dialog = new FileDialog(shell, SWT.OPEN);
dialog.setFilterExtensions(new String [] {"*.html"});
dialog.setFilterPath("c:\\temp");
String result = dialog.open();
Unfortunately it is not working, at least not "every time".
I have currently no installation to check on it, but I'm quite sure that the feature would work totally fine on a Windows 200/XP/Vista machine.
I am working with a Windows 7 machine and I think I am suffering from the behaviour described here for lpstrInitialDir.
At least, this is exactly the behaviour I am facing: The path is good the first time I open the dialog, but the second time, the path is initially set to the last chosen path.
This seems to be convenient in most cases, but it is not in mine.
Can this be right?
If so, have I any chance on changing the behaviour according to my needs?
Thanks for any helping answer!
I ran into the same problem on Windows 10 and found a solution that seems to be working for me. A code snippet from the DirectoryDialog led to the right direction:
if (filterPath != null && filterPath.length() > 0) {
String path = filterPath.replace('/', '\\');
char[] buffer = new char[path.length() + 1];
path.getChars(0, path.length(), buffer, 0);
if (COM.SHCreateItemFromParsingName(buffer, 0, COM.IID_IShellItem, ppv) == OS.S_OK) {
IShellItem psi = new IShellItem(ppv[0]);
/*
* SetDefaultDirectory does not work if the dialog has
* persisted recently used folder. The fix is to clear the
* persisted data.
*/
fileDialog.ClearClientData();
fileDialog.SetDefaultFolder(psi);
psi.Release();
}
}
The FileDialog misses this statement 'fileDialog.ClearClientData()'. My solution is to execute the following code before setting the path and open the dialog:
long [] ppv = new long [1];
if (COM.CoCreateInstance(COM.CLSID_FileOpenDialog, 0, COM.CLSCTX_INPROC_SERVER, COM.IID_IFileOpenDialog, ppv) == OS.S_OK) {
IFileDialog fileDialog = new IFileDialog(ppv[0]);
fileDialog.ClearClientData();
fileDialog.Release();
}
Now you can set the filterpath without Windows messing things up.
I found a simple Solution for the Problem you described (I had the exact same Problem).
Just rearrange the your code like this:
FileDialog dialog = new FileDialog(shell, SWT.OPEN);
dialog.setFilterPath("c:\\temp"); // This line is switched with the following line
dialog.setFilterExtensions(new String [] {"*.html"});
String result = dialog.open();
Somehow the Order of the methods called is relevant.
Are you using the same FileDialog object when you re-open it?
I ran a few quick tests and found that, if you re-set the filterPath, the dialog opens in the correct location.
If I open the same object again, it starts in the previously selected location.

Trying to use the Netbeans ProgressBar to show long running tasks, having problems with dependancies and libraries

I have an application built on top of NetBeans. We have some long running jobs that I'd like to keep running in the background, but allow the user to see progress on the bar on the lower right.
E.G:
I can't seem to access it from my code.
Initially I didn't have this library
org.netbeans.api.progress.ProgressHandle;
org.netbeans.api.progress.ProgressHandleFactory;
I had to go out and hunt down the JAR file. That doesn't make whole lot of sense to me, I figure it should be available.
This creates an error when I try to call the ProgressHandle into effect, I get this error
java.lang.ClassNotFoundException: org.openide.awt.StatusLineElementProvider …
Followed by a stack trace. Obviously I don't have all the packages necessary to operate this.
What the big question is then, what am I missing as far as accessing these NetBeans libraries correctly?
Thanks,
Here's the code when I'm trying to call the progressbar into action
`
ProgressHandle progr;
if (thread == null) {
thread = new Thread() {
#Override
public void run() {
progr.start();
progr.progress("Sending backup to remote server.");
… //Some code that sends a backup
progr.finish();
`
I'll be rewriting this question a few times, until I think it's clear, I'm open to input
Add a module dependency on Progress API. Right click on your module > properties.Select Libraries from the left panel. Click Add to open up the module dependency dialog. Select Progress API and click OK. Now you have the dependency on Progress API and you can use it as
ProgressHandle ph = ProgressHandleFactory.createSystemHandle("My Task");
ph.start(100);
Edit:
Also u dont have to add any jar files.. The Progress API module dependency will take care of that

Eclipse: Ctrl+Shift+Right is incorrect

Consider this simple class:
package net.zomis.test;
public class Test {
public Test() {
}
public void registerSomething(String key) {
}
}
When I have the cursor placed right before registerSomething and pressing CtrlShift→, I'm used to Eclipse only selecting register at first. But now, it selects the entire registerSomething text, when I press it again it selects the entire method (from public void to }), when I press it again it selects the entire class, and the last time the entire file is selected. The exactly same thing happens if I press CtrlShift←.
Also, when I simply click the End key, I get an option to choose: Line End or Text End.
What has gone wrong in my settings for this to happen? Where can I find these keybindings?
If it matters, I have this workspace within my Dropbox-folder to synchronize it between my PC and Mac.
Turns our that the fact that I had the workspace in my Dropbox folder matters a lot. Note to everybody else: Do not share your workspace between computers. How I solved this is the following:
Create a new workspace on each computer
In the computer-specific workspace, import projects from your shared Dropbox/other folder
I noticed that when having a shared workspace on the computers, the Mac somehow changed the key-bindings to the Mac-version, which made them not work on the PC. The correct Ctrl+Shift+→ key-binding on Mac is Alt+Shift+→.
So by using a separate workspace on each computer, I can use that computer's specific key-bindings, without mixing them up.
Open the preferences dialog from the Main Menu: Window->Preferences.
In the dialog, open General->Keys. You'll see a table of keybindings, with a field with type filter text. In that field, type: Ctrl+Shift+Right, and you'll narrow the table down to this key.
The behavior that you expect - only register is selected with the first keypress - is the behavior that I see when using Ctrl+Shift+Right, and the keybinding for me is: Select Next Word.
There is a Restore Command button that should reset this binding if it has been changed.

Is there a way to expand a JFileChooser directory without a mouse

Using a JFileChooser, I can select a directory by double clicking the directory (going down a level) with my mouse. Is there a way to select a directory without the mouse? For example, is there a key binding to go down a directory level or do I have to somehow add a key listener to the JFileChooser?
You should be able to use tab to move between the different parts of the chooser, and then use the arrow keys to change which directory is highlighted, and then press Enter to change the directory to the highlighted one.
I have tested the following example code on my machine (Vista/JDK 1.6) and it works as I would expect:
import javax.swing.*;
public class test {
public static void main(String[] args) {
(new JFileChooser("")).showOpenDialog(new JFrame());
System.out.println("OK!");
}
}
If your project is not responding similiarly in your JFileChooser, I would debug as follows:
Create test.java with only the code necessary to pop up a chooser.
If the test app differently than within your app, its something in your code causing it to fail, such as UI skinning code, keyboard listeners, etc. Modify the example, one change at a time to closer replicate your settings for your chooser in your app and see if you can pinpoint where it breaks.
If even a basic test app doesn't work right, it is probably something about your setup, such as a bug in your JDK version, your OS, etc. Troubleshoot your setup.
Have you tried the space-bar or enter key?
Try using ctrl+enter key to select directory.
This behavior is happened when you set to JFileChooser file selection mode to “files and direcories”:
JFileChooser fileBrowser = new JFileChooser();
fileBrowser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);

Automatic SVN sync Eclipse

I'm starting with SVN. Is there any way of configuring subclipse to automatically sync with the repo in order to know when a file was modified as soon as possible?
In case of Subversive (and I believe, the same option should be available in case of Subclipse as well) the Synchronize view allows automatic synchronization.
Initialize a synchronization using either Team/Synchronize from the context menu of some projects, or open the Team Synchronizing perspective, and select the set of synchronized projects using the Synchronize button of the Synchronize view (the button is the first button of the view toolbar).
Then the synchronization is performed, and the changes are displayed there. At this point, you could select the Schedule... option from the view menu (down-pointing triangle icon near the top right corner of the Synchronize view), and there you could set the synchronization.
AFAIK this synchronization does not update your workspace automatically (that is a sound idea, e.g. conflict resolution must happen manually), but at least you can look at the changes when needed.
You really do not want to do this. Synchronization with repository is a heavy operation with a lot of side effects. For example you can change file that is being changed in repository now. You do not want to get mismatch of your and other's changes while you are working. You wish to work and then update all files together and resolve conflicts (if any)
In the context menu (right-click on project) there should be an option "Team>Synchronize with repository".
I did find this tutorial useful.
As far as I know, subclipse provides no such option. You could write a cron job that uses the SVN command-line tools to perform an update at regular intervals, but I wouldn't recommend this. You can't automate synchronizing with SVN because updating may cause conflicts which cannot be automatically merged.
Although I agree that in some situations it might be a bad idea to have an automated commit feature, there might be some reasons why you could want to have this option anyway.
I created a small EASE-script that replaced my regular save key binding (ctrl+s). It first saves the file, tries to update the file (which also automatically merges the versions if possible or creates conflicts in which case the script terminates) and commits the file at last.
// ********************************************************************************
// name : SaveUpdateCommit
// keyboard : CTRL+S
// toolbar : PHP Explorer
// script-type : JavaScript
// description : Save a file, update from the repository and commit automatically
// ********************************************************************************
var UI = loadModule("/System/UI");
UI.executeUI(function(){
var editor = UI.getActiveEditor();
editor.doSave(null);
var site = editor.getSite();
var commandService = site.getService(org.eclipse.ui.commands.ICommandService);
var handlerService = site.getService(org.eclipse.ui.handlers.IHandlerService);
var subclipse = org.tigris.subversion.subclipse.core.SVNProviderPlugin.getPlugin();
try
{
var file = editor.getEditorInput().getFile();
}
catch(e)
{
return;
}
var filePath = file.getFullPath();
var project = file.getProject();
var projectPath = project.getWorkingLocation(subclipse.toString());
var workspace = project.getWorkspace();
var localFile = org.tigris.subversion.subclipse.core.resources.SVNWorkspaceRoot.getSVNFileFor(file);
localFile.refreshStatus();
if(localFile.isDirty()){
var remoteFile = localFile.getBaseResource();
var empty = java.lang.reflect.Array.newInstance(org.eclipse.core.resources.IResource, 0);
var commitFiles = java.lang.reflect.Array.newInstance(org.eclipse.core.resources.IResource, 1);
commitFiles[0] = remoteFile.getResource();
var update = new org.tigris.subversion.subclipse.ui.operations.UpdateOperation(editor, remoteFile.getResource(), org.tigris.subversion.svnclientadapter.SVNRevision.HEAD);
update.run(null);
var commit = new org.tigris.subversion.subclipse.ui.operations.CommitOperation(editor, empty, empty, empty, commitFiles, "AutoCommit", false);
commit.run(null);
}
For this, you need to install Eclipse EASE (http://download.eclipse.org/ease/update/release) and to make this script available through the settings. Also, the script needs UI-access, again this needs to be configured in the settings.
So for your needs you may want to change that behavior to frequent updates. I never played around with timers in eclipse, but i guess it is possible though.

Categories

Resources