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
Related
I´m writing an Eclipse plugin to show the contents of an own file type in an own custom editor.
This file basically consists of 1..n IFile´s from the Project Explorer which are shown in a SWT TreeView.
The entries in this TreeView are some Beans organized in a flat List, but i provide an adapter to convert them to IFile´s.
<extension
point="org.eclipse.core.runtime.adapters">
<factory
adaptableType="de.dstg.delta.collections.model.Collection$Member"
class="de.dstg.delta.collections.CollectionMemberAdapterFactory">
<adapter
type="org.eclipse.ui.views.properties.IPropertySource2">
</adapter>
<adapter
type="org.eclipse.core.resources.IFile">
</adapter>
</factory>
</extension>
Eclipse Screenshot
It´s no problem to show a custom SWT menu but i think the right way is using the Eclipse menu structure, especially by providing default behaviour for Resources.
How can i show the default context popup menu, which is used by right-clicking resources in the Project Explorer, in my SWT TableView?
EDIT second question removed
EDIT2
According to the answer from greg-449, the problem remains that the context menu shows no entries i would like to have for this type of selection.
f.e. i need delete or open with or something like that 'file basics' without implementing it on my own.
We have also some other menus from additional plugins that should be visible here when the appropriate file type is selected. This works in Project Explorer but not in my table view.
I think the problem is the type of the selected element.
Plugin spy shows the following in my table view:
type of the selected element: Collection$Member,
interfaces valid for the selected element: IAdaptable
whereas the Project Explorer shows File and IFile, respectively.
My adapter works generally and delivers the related IFile while being triggered from an unknown Eclipse source.
I think i have to explicitely say, that the context menu should use the IFile type to get the correct menu entries but i dont´t know how.
Or did i miss something?
There isn't really a 'default' menu. Some menu items are defined to be added to all popup menus that define a specific place holder.
To use the place holder you must register your context menu with Eclipse, something like:
private void createContextMenu(Viewer viewer) {
Control menuControl = viewer.getControl();
MenuManager menuMgr = new MenuManager("#PopUp");
menuMgr.setRemoveAllWhenShown(true);
menuMgr.addMenuListener(new IMenuListener() {
#Override
public void menuAboutToShow(IMenuManager mgr) {
fillContextMenu(mgr);
}
});
Menu menu = menuMgr.createContextMenu(menuControl);
menuControl.setMenu(menu);
// register the context menu such that other plugins may contribute to it
getSite().registerContextMenu(menuMgr, viewer);
}
private void fillContextMenu(IMenuManager menu) {
// TODO add your actions
// Standard additions
menu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
}
You will probably also need to set your viewer as the 'selection provider':
getSite().setSelectionProvider(viewer);
Many menu items will check this to see what the type of the current selection is.
There is nothing that will automatically give you things like Open With or Delete, you have to add these yourself in the 'fillContextMenu' section.
You can use org.eclipse.ui.actions.OpenWithMenu for Open With.
IFile file = ... currently selected file
IMenuManager submenu = new MenuManager("Open With...");
submenu.add(new OpenWithMenu(getSite().getPage(), file);
menu.append(submenu);
Using liferay 6.2 api to insert images in document library. The code also moves images from one folder to another folder
But After moving the images their folders do not get guest view permissions and images can't be viewed.
I have two groups (sites) -
GroupA
GroupB
GroupA user creates folders, inserts files and also moves files.
GroupB user should be able to see the files.
All the folders and files are created under Global scope in document library.
public void moveFilesToFolder(final HttpServletRequest request, final List<DLFileEntry> filesToMove, final DLFolder toFolder)
throws Exception {
final ServiceContext sc = ServiceContextFactory.getInstance(request);
sc.setWorkflowAction(WorkflowConstants.STATUS_APPROVED);
sc.setAddGuestPermissions(true);
sc.setAddGroupPermissions(true);
for (final DLFileEntry file : filesToMove) {
DLAppServiceUtil.moveFileEntry(file.getFileEntryId(), toFolder.getFolderId(), sc)
}
// update folders to have guest permissions
DLAppLocalServiceUtil.updateFolder(toFolder.getFolderId(), toFolder.getParentFolderId(), toFolder.getName(),
toFolder.getDescription(), sc);
}
This doesn't seem to work and guest permissions are not set for all the users. The weird behavior is that when the user who performed the move operation looks at the permissions from UI, gues view permission is checked but for any other user the permission is not checked.
As per suggestions below I have used DLAppServiceUtil to move files. But It doesnt change status of file to approved from draft.
Also what is the correct method to use to copy files? There is no method in DLAppServiceUtil to copy files from one folder to another
Anybody knows how to solve this issue?
Using DLAppLocalServiceUtil and DLFileEntryServiceUtil is not the right way. Thery bypass permissions updating and right repository managment.
Use DLAppServiceUtil instead to move and to update.
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.
I wrote a new eclipse view plugin and when you select Window -> Show View --> Other
you can see it in its own folder/category (the view defines a new category)
Is it possible to code the plugin.xml of this view so that when the user clicks on Show View
the view is shown in one of the preexisting JDT folders/categories, like "Java" or "Java Browsing"?
if so, assuming i just need to specify the preexisting category's id
in my view's 'category' attribute, where can one find the list of JDT view categories and their associated ID's?
More Info:
my plugin.xml contains this:
<category
name="MyCat"
id="com.mine">
</category>
which specifies in which category the view will show. so, when deployed, the user can add my new view by: Window - Show View - Other
and there, among all pre-existing categories/folders, the user will see my category
"MyCat" and when opened, it contains my newly developed/contributed view.
my back to my question... i don't want to create a new category, but instead, i want my
new view to show in the existing Java category. can i do that and if so how?
i assume that, if it is possible to do, i would probably need to 1) not use the 'name' attribute in my 'category'
element, and 2) the 'id' attribute should contain the id of the Java category.
(which is what?).
so perhaps there is a place where all pre-existing jdt view categories
are defined, but i couldn't find it....
Define a perspective extension with your views. Here is an example with the debug perspective
org.eclipse.ui.perspectiveExtensions
The category for Java is org.eclipse.jdt.ui.java
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