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
Related
I am developing plugin of graph that use the objects in the current file that open. If I change the file that open, I want the graph will update.
Now, I am using setFocus() method in my class that extends ViewPart, and update the graph in every call to this function.
This is not what I want, I want to update the graph only when the resource change.
I found this link:
link to similar question
This is like my question, but there is no answer
I need to put the following code in the activator.java file of my plugin?:
IWorkspace workspace = ResourcesPlugin.getWorkspace();
IResourceChangeListener listener = new IResourceChangeListener() {
public void resourceChanged(IResourceChangeEvent event) {
System.out.println("Something changed!");
}
};
workspace.addResourceChangeListener(listener);
//... some time later one ...
workspace.removeResourceChangeListener(listener);
If I need to add this code, where to put it? In which method to put it in the activator.java file?
If not, what I need to do?
Set up the listener in the view part createPartControl.
The activator is not a suitable place to set up listeners as it is only run when some other code in the plugin runs.
I am developing a eclipse plugin. I need to open my prespective when we open the eclipse at first time. Any ways to achieve this? i guess some listener must be available but could not trace out.
We can open a prespective after eclipse start using PlatformUI.getWorkbench().showPrespective(<prespective id>)
Similarly is there a way to open the prespective on eclipse startup, so that our desired prespective gets opened when starting the eclipse.
You can use the org.eclipse.ui.startup extension point in your plugin. When the plugin is activated, check/set a preference to decide if you want to switch perspectives and then schedule a UIJob do do it.
Implement the extension point. Some class in the plugin needs implements org.eclipse.ui.IStartup. The activator class is fine in this case. Particularly, since you don't need anything in the earlyStartup method.
In the start method, make the decision to switch and schedule it:
public void start(BundleContext context) throws Exception {
super.start(context);
plugin = this;
final boolean switchPerpective = processPluginUpgrading();
if (switchPerpective) {
final IWorkbench workbench = PlatformUI.getWorkbench();
new UIJob("Switching perspectives"){
#Override
public IStatus runInUIThread(IProgressMonitor monitor) {
try {
workbench.showPerspective(perspectiveId, workbench.getActiveWorkbenchWindow());
} catch (WorkbenchException e) {
return new Status(IStatus.ERROR,PLUGIN_ID,"Error while switching perspectives", e);
}
return Status.OK_STATUS;
}}
.run(new NullProgressMonitor());
}
}
Use the preference store to keep data for your decision logic. In this implementation, the perspective is switched once per workspace whenever the plugin is upgraded. The data recorded in the preference store will allow a future version to have a difference policy. It uses the getPreferenceStore from AbstractUIPlugin so it is scoped per workspace. If you want to use other scopes, see the FAQ.
private Boolean processPluginUpgrading() {
final Version version = getDefault().getBundle().getVersion();
final IPreferenceStore preferenceStore = getDefault().getPreferenceStore();
final String preferenceName = "lastVersionActivated";
final String lastVersionActivated = preferenceStore.getString(preferenceName);
final boolean upgraded =
"".equals(lastVersionActivated)
|| (version.compareTo(new Version(lastVersionActivated)) > 0);
preferenceStore.setValue(preferenceName, version.toString());
return upgraded;
}
One thing I am doing to open my custom perspective in my plugin is to configure it in config.ini in eclipe's installation folder as below:
-perspective <my perspective id>
and it is working fine. I got this information from Lars Vogel's tutorial, which you can find here. Hope this helps.
Other way:
org.eclipse.ui.IPerspectiveRegistry.setDefaultPerspective(id) this sets default perspective to the given id. API Docs for the same.
Go to
D:\{MyTestSpace}\eclipse\features\myCustom.plugin.feature_3.1.0.201607220552
you can see feature.xml under plugin tag you get the id.
Use this id in config.ini which you can find under
D:\{MyTestSpace}\eclipse\configuration
As
-perspective <myCustum.plugin>
I have an Eclipse RCP application for which I need to create a file browser view. I want to pass it a root (some location on the local computer) and the view should populate all the files and folders at that location. Currently I am using CNF in my view hence,
public class CurrDirExplorerView extends CommonNavigator
I have overriden the getInitialInput() to return a custom root object which contains a directory path in it. I am using java.io.File since IResources are linked to the workspace. I have created an element object which is like a wrapper class for the java.io.File and returns the name etc for supporting the label and content providers. My view displays all the folders and files at the location specified in my root object but since they are not IResources, when I double-click on a file, it does not open up in the editor.
Is there any way to do this?
CommonNavigator has a protected method:
protected void handleDoubleClick(DoubleClickEvent anEvent);
unfortunatelly its javadoc says "This method is for internal use only", however still avail if there is no better option.
Other way would be: getCommonViewer(), which has addDoubleClickListener() and you will be able to define your own logic for handling doubleclick. Hope this helps.
There is a global Preference (see picture) that is used by the Navigator. If you want to preset this preference you have to set the preference key (boolean) OPEN_ON_SINGLE_CLICK in the preferencestore of bundle org.eclipse.ui.workbench
We are using NetBeans Platform 7.0.1, and have implemented support for a new language using this (now “obsolete”) tutorial.
Since all our contents are stored in a database, and not on files, we open them like this:
FileSystem fs = FileUtil.createMemoryFileSystem();
FileObject fo = fs.getRoot().createData(fileName, fileExtension);
… write contents from database to `fo` ….
DataObject data = MyMultiDataObject.find(fo);
EditorCookie.Observable cookie = data.getCookie(EditorCookie.Observable.class);
cookie.open();
… forces undock of editor window …
And, in our layer.xml, have added a custom button to Save that sends the content back to the database.
However, when the user closes the file (by either closing the tab or the window), we haven’t figured a way of saving it.
Adding a PropertyChangeListener to the Cookie and watching for PROP_DOCUMENT (and newValue() == null) seems to do the trick for when the window is closed. But how does one get the return value from the confirmation window (I’m referring to when the file is closed after changes, the message File xxx.xxx is modified. Save it?)?
Well, it seems we've been approaching the problem in the wrong way.
Since we are opening the file in-memory, it was suggested in the netbeans-dev list that we should listen for changes in the file itself, by using
fo.addFileChangeListener(new CustomFileChangeListener());
public class CustomFileChangeListener implements FileChangeListener {
#Override
public void fileChanged(FileEvent fe) {
... file has been saved in the editor, sync with database ...
}
}
And keep it synchronized that way, taking advantage of the built-in NetBeans Platform "save" functionality.
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.