Automatic SVN sync Eclipse - java

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.

Related

How can I disable a dialog in ImageJ?

I'm using ImageJ a lot to look at image stacks composed of a number of single images sitting in one folder. I can just drag and drop the respective folder into the ImageJ GUI and it creates a scrollable visualization, which is very convenient. It could be even more convenient though since each time I do it, a dialog appears asking whether I want to open all images in the folder as a stack. Is it possible to make it default to "Yes"? Would I need to change the source code and compile it myself..? If that is the case, where could I start looking?
A suggestion would be to make a feature request to the author of Imagej Wayne rasband, e.g., at the Github repository:
https://github.com/imagej/imagej1
Or you can write a small macro (use the macro recorder with the menu actions!) which can be also be installed in ImageJ. Something like:
run("Image Sequence...", "open=C:\\images\\ sort");
Here the macro docs:
https://imagej.nih.gov/ij/developer/macro/macros.html
https://imagej.nih.gov/ij/docs/guide/146-14.html
To disable the dialog in the source code: Find the source file ij>plugin>DragAndDrop.java. From its openDirectory method, delete the dialog-related lines and assign boolean values to convertToRGB and virtualStack, both of which are normally defined by check boxes in the now defunct dialog window. The code should now look like this:
private void openDirectory(File f, String path) {
if (path==null) return;
if (!(path.endsWith(File.separator)||path.endsWith("/")))
path += File.separator;
String[] names = f.list();
names = (new FolderOpener()).trimFileList(names);
if (names==null)
return;
convertToRGB = false;
virtualStack = false;
String options = " sort";
if (convertToRGB) options += " convert_to_rgb";
if (virtualStack) options += " use";
IJ.run("Image Sequence...", "open=[" + path + "]"+options);
DirectoryChooser.setDefaultDirectory(path);
IJ.register(DragAndDrop.class);
}
I did this with ImageJ 1.51p. The source code can be downloaded here. After making these changes, just run the build.xml ant script.
Note that writing a macro might provide a cleaner and more portable way to achieve this--refer to Marcel's answer for further reading.

Eclipse RCP: Set active part programmatically or get selection of inactive part

in my Eclipse Plugin I have this workflow:
Get the currently selected project in the Package Explorer
Do something
Get the currently selected project in the Package Explorer (same as 1)
Do something different
1 (and 3) are realized like that:
ISelectionService selectionService = PlatformUI.getWorkbench()
.getActiveWorkbenchWindow().getSelectionService();
ISelection selection = selectionService.getSelection();
[...]
Now, the problem is that before 1, the Package Explorer is selected, because that's the only way to trigger the workflow. But step 2 changes the active part because it refreshes a TreeView which makes it the active part. When I now try to run 3, which is the same method as 1, I have a problem: The Package Explorer is no longer the activePart of the selectionService and therefore selection is null.
My questions are: Is there any way to get the ISelectionService for a particular View which is not the active one? If not, is there a way to programmatically set the active part before executing step 3?
Btw that's an Eclipse 3.x plugin.
If you find the IViewPart for the package explorer you can access its ISelectionProvider directly using:
IViewPart part = .. find package explorer view part
IViewSite viewSite = part.getViewSite();
ISelectionProvider provider = viewSite.getSelectionProvider();
ISelection selection = provider.getSelection();

Eclipse RCP 4.x - Defining workspace location

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.

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

How to programmatically refresh an Eclipse view, or RSE file subsystem?

How can I programmatically update an Eclipse view? (I suppose this might not need to be specific to RSE?).
Background: I use Remote System Explorer (RSE) for Eclipse, do some stuff by executing remote commands via SSH, which creates new files on the remote host. I realized that the SFTP file listing in the Remote systems view does not automatically get updated to show the newly created file.
I have managed so far to get the relevant view, like so:
IWorkbench workbench = PlatformUI.getWorkbench();
IViewRegistry viewReg = workbench.getViewRegistry();
IViewDescriptor[] views = viewReg.getViews();
for (IViewDescriptor view : views) {
String viewID = view.getId();
System.out.println("View ID: " + viewID);
if (viewID.equals("org.eclipse.rse.ui.view.systemView")) {
// Do something with the view here
}
}
... and for possibly doing something RSE specific, I tried grabbing the RemoteFileSubSystem:
IRemoteFileSubSystem rfss = RemoteFileUtility.getFileSubSystem(HPCUtils.getApplication().getHPCHost());
... but neither in the ViewDescriptor object, nor the FileSubSystem, I have found any way to refresh the view, or the file subsystem. What have I missed?
Are you looking to refresh a container that you constructed? IOW, a class that you wrote that extends org.eclipse.rse.core.subsystems.AbstractResource?
If so, try this code ...
ISystemRegistry registry = SystemStartHere.getSystemRegistry();
SystemResourceChangeEvent event = new SystemResourceChangeEvent(this,
ISystemResourceChangeEvents.EVENT_REFRESH, yoursubsystem);
registry.fireEvent(event);
If you're NOT inside your own resource container, but you know the resource container's object, replace this in the SystemResourceChangeEvent construction with the object.
I'm not familar with RSE but AFAIK it uses a virtual filesystem. That means refreshing can be done via the normal Resource-API, something like:
IFolder folder = ResourcesPlugin.getWorkspace().getRoot().getFolder(new Path("path/to/theparent/folder/on/remote/system"));
folder.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
The Filesystem manager of Eclipse will check your EFS-specific implementation of org.eclipse.core.filesystem.IFileInfo for a changed modification date. Make sure that your virtual filesystem will return correct File-Information

Categories

Resources