How to open my TopComponent in "explorer" mode? - netbeans

I am doing netBeans platform application.when I creating top component I give it as "explorer" mode to start.But in default it start in "editor" mode.Here the annotations which top component automatically generated.
#ConvertAsProperties(
dtd = "-//MyApplication.windows//MyViewer//EN",
autostore = false)
#TopComponent.Description(
preferredID = "MyViewerTopComponent",
//iconBase="SET/PATH/TO/ICON/HERE",
persistenceType = TopComponent.PERSISTENCE_ALWAYS)
#TopComponent.Registration(mode = "explorer", openAtStartup = true)
#ActionID(category = "Window", id = "MyApplication.windows.MyViewerTopComponent")
#ActionReference(path = "Menu/Window" /*, position = 333 */)
#TopComponent.OpenActionRegistration(
displayName = "#CTL_MyViewerAction",
preferredID = "MyViewerTopComponent")
#Messages(
{
"CTL_MyViewerAction=MyViewer",
"CTL_MyViewerTopComponent=MyViewer Window",
"HINT_MyViewerTopComponent=This is a MyViewer window"
})
Please give me any suggestion for this problem.

I just had this problem. I unchecked a module dependency called RCP Platform and the windows would only open in editor position. I was trying to find the minimum modules needed to run my program.
You can see which modules are used by right clicking the project node and choosing properties. Look at libraries and expand the Platform node. Make sure RCP Platform is checked. If it gives an error, just click resolve. Make sure you do a clean and build afterwords.
There is one easier thing you should check first. When you run a NB platform program, it opens windows in the last used position. If you moved a window, it will reopen where you last moved it to. You have to do a clean and build to reset this.

Related

How to get the list of external tools in eclipse

Eclipse knows external tools (menu run->external tools) and I would like to show the list of external tools on a right click in my view so the user can select a tool which I then execute.
I however simply fail to find the external tools.
The code I have now dumps the commands (and there are plenty) but I do not find the external tools I created.
ICommandService commandService=PlatformUI.getWorkbench().getService(ICommandService.class);
Command[] allCommands = commandService.getDefinedCommands();
for(Command curCommand :allCommands) {
Category cat = curCommand.getCategory();
System.out.print(cat.getName()+" ");
System.out.println(curCommand.getName());
}
Where can I find a list of external tools?
Based on the info of greg I found the following to work in my case.
ILaunchManager manager = DebugPlugin.getDefault().getLaunchManager();
ILaunchConfigurationType type = manager.getLaunchConfigurationType("org.eclipse.ui.externaltools.ProgramLaunchConfigurationType"); //$NON-NLS-1$
ILaunchConfiguration[] lcs = manager.getLaunchConfigurations(type);
This works for program launch configurations because I use the key ("org.eclipse.ui.externaltools.ProgramLaunchConfigurationType".
If you do not know which type is your command use getLaunchConfigurationTypes() to find all types and list the names to find the Type you need.
There are plenty.

Poltergeist-phantomjs - switching to the new popped up window

Test env: Capybara,poltergeist, phantomjs.
A new window opens up when I click a link in my test case. I was able to switch to the new window and verify text using selenium driver. However, I am unable to switch to the new window with poltergeist. I tried the following method to switch to the new window and none of them worked.
I wanted to see if a new browser is getting open at all and looks like it is.
main = page.driver.browser.window_handles.first
puts main (gives 0)
popup = page.driver.browser.window_handles.last
puts popup (gives 1)
1. within_window(->{ page.title == '2015-11-5.pdf' }) { assert_text(facility_name) }
2. page.switch_to_window(window=popup)
3. page.switch_to_window(page.driver.browser.window_handles.last)
4. page.driver.browser.switch_to().window(page.driver.browser.window_handles.last)
Could someone provide any inputs here? Thanks!
I used the following and the popup is getting generated and the control switches to it.
page.switch_to_window(page.window_opened_by{click_link('Generate Report')})
The new window has a pdf embedded in it.I was able to read and verify the contents of the document when I use selenium driver. With poltergeist, I am unable to read the pdf. Could you give me some pointers on how to proceed?
Capybara has a number of cross driver methods for dealing with this without having to go to driver specific methods.
popup = page.window_opened_by {
click_link('whatever link opens the new window')
}
within_window(popup) do
# perform actions in the new window
end

How to get .java file path to my eclipse plugin

I am developing a eclipse plugin to ease the development using a proprietary version control system.
Right now there is only a command prompt version of the system available for this VCS and its run in terminal. So from my eclipse plugin I want to provide a simple menu options to do the things like check-out and check-in and internally call these commands.
But to run these commands I need to pass the argument 'path' of the selected .java file in the editor/project explorer. How can I get the path of the source file to the plugin?
Get the current workbench page:
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
the workbench page implements ISelectionService so you can get the current selection:
ISelection selection = page.getSelection();
this will generally by an IStructuredSelection (but you need to check)
IStructuredSelection sel = (IStructuredSelection)selection;
See if this adapts to an IFile:
Object selObject = sel.getFirstElement(); // or iterate through all the selection elements
IFile file = Platform.getAdapterManager().getAdapter(selObject, IFile.class);
if you get a file the full path is:
String location = file.getLocation().toOSString();
If the current part is an editor then the selection you receive might be a text string. So you need to deal with editors separately:
IWorkbenchPart activePart = page.getActivePart();
if (activePart instanceof IEditorPart)
{
IEditorInput input = ((IEditorPart)activePart).getEditorInput();
if (input instanceof IFileEditorInput)
{
IFile file = ((IFileEditorInput)input).getFile();
...
}
}

How can I create a custom project layout based on another eclipse plugin?

My ultimate goal is to create an eclipse plugin that sets up a PDT project, but with some added builders (and custom build scripts) as well as a specific folder layout (and different folders should be treated as source and some as regular folders).
I've looked at / followed eclipse plugin development tutorials, and ok. I get the gist of creating a wizard that creates a file, but I'm having trouble trying to figure out how to create a project, and more importantly, make that project associated with the PDT (PHP Development Tools) feature.
Answer:
I did stumble upon a solution myself before the answer was given, but it's quite similar.
First, WizardNewProjectCreationPage was used as the first page of my wizard.
Second, on performFinish() I ran the following code:
IProgressMonitor m = new NullProgressMonitor();
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
IProject project = root.getProject(_pageOne.getProjectName());
if (!project.exists())
{
IProjectDescription desc = project.getWorkspace().newProjectDescription(project.getName());
URI projectLocation = _pageOne.getLocationURI();
// desc.setLocationURI(projectLocation);
String[] natures = desc.getNatureIds();
String[] newNatures = new String[natures.length + 1];
System.arraycopy(natures, 0, newNatures, 0, natures.length);
newNatures[natures.length] = PHPNature.ID;
desc.setNatureIds(newNatures);
project.create(desc, m);
project.open(m);
}
how to create a project
Take a look at BasicNewProjectResourceWizard.createNewProject() method.
make that project associated with the PDT (PHP Development Tools) feature
You need to add "org.eclipse.php.core.PHPNature" to the project (that's what Add PHP Support... action does). Use IProjectDescription.setNatureIds().

Finding currently open files in Eclipse plugin

I'm trying to create a plugin that annotates eclipse java projects based on external output. Currently, I'm traversing all of the open projects based on this tutorial: http://www.vogella.de/articles/EclipseJDT/article.html However, I'm looking for a way to get a full list of only the files that are currently open in the java editor. Is there a way or command for me to get that?
//get all active editor references,check if reference is of type java editor
IEditorReference[] ref = PlatformUI.getWorkbench()
.getActiveWorkbenchWindow().getActivePage()
.getEditorReferences();
List<IEditorReference> javaEditors = new ArrayList<IEditorReference>();
for (IEditorReference reference : ref) {
if ("org.eclipse.jdt.ui.CompilationUnitEditor".equals(reference.getId())){
javaEditors.add(reference);
}
}