Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "Eclipse Plug-in Development FAQ"

m (I need help debugging my plug-in...)
m (How do I associate my executed process with its command line counterpart?)
Line 87: Line 87:
 
  attributes.put(IProcess.ATTR_CMDLINE, commandLine);
 
  attributes.put(IProcess.ATTR_CMDLINE, commandLine);
 
  Process process = Runtime.getRuntime().exec(commandLine);
 
  Process process = Runtime.getRuntime().exec(commandLine);
  // this assumes that you 'launch' is a non-null reference to an ILaunch implementation
+
  // this assumes that 'launch' is a non-null reference to an ILaunch implementation
 
  DebugPlugin.newProcess(launch, process, "make", attributes);
 
  DebugPlugin.newProcess(launch, process, "make", attributes);
  
 
[[Category:FAQ]]
 
[[Category:FAQ]]

Revision as of 07:41, 31 December 2007

This page is a collection of FAQs that is intended to help a developer write Eclipse plug-ins.

This FAQ is intended to be complimentary to the Official Eclipse FAQ and RCP FAQ wiki pages. If you cannot find your question here, you should try checking those other two pages.

General Development

How do I find a class from Eclipse?

See here.

I see these $NON-NLS-1$ tags all over the place when I'm browsing Eclipse's source code? What do they mean?

They are meant to mark a string literal as not needing to be externalized (as in, translated / localized). You will often see something like...

if (string.equals("")) { //$NON-NLS-1$
    // do stuff
}

...this would be a scenario where a string wouldn't need to be localized because it is a string for the code to "manipulate", per se, over it being part of a message to the user at the UI level.

I need help debugging my plug-in...

Are you getting errors like "Unhandled loop event exception" messages in your console with nothing useful after it? Make sure you have -consoleLog as a Program Argument in your launch configuration. You may also want to take a look at these runtime tools.

User Interface

There's a view / editor that I want to model. How do I find out how it was designed?

Views and editors generally extend ViewPart and EditorPart respectively. Placing a breakpoint in its constructor when you show the view or editor will help you figure out what the class is composed of.

There's a preference / property page that I want to model. How do I find out how they designed it?

Put a breakpoint in the constructors of the PreferencePage / PropertyPage class. Open the preferences / properties dialog, and then select the page you are interested about. Now you can identify which class is constructing that page based on the stack trace.

There's a window / dialog / popup that I want to model. How do I find out how it was designed?

There are two usual suspects, an SWT Shell or a JFace Window. Generally, most developers subclass's JFace's Dialog class (which is a subclass of Window) for their dialog needs. So you should first try and put a breakpoint in Window's open() method and see if the window you're trying to model stops at that breakpoint when it has been opened (shown). If not, try Shell's open() or setVisible(boolean) methods.

There's a wizard page that I want to model. How do I find out how they designed it?

Wizard pages usually extend the WizardPage class. Putting a breakpoint in its constructor will help you identify the class that is creating that page.

Text

How do I add those rectangles in my source editor like what JDT does for parameter names during code completion?

To achieve this, you will need to use a LinkedModeModel and a LinkedModeUI. Open the 'Call Hierarchy' on either of the two constructors to find out how to use those two classes.

How do I implement a 'Quick Outline' for my editor?

JDT's implementing class is named 'org.eclipse.jdt.internal.ui.text.JavaOutlineInformationControl', you should take a look at that.

How can I leverage the 'Outline' view?

In your IEditorPart implementation, you should override the getAdapter(Class) method and return your own implementation of IContentOutlinePage or you can choose to subclass ContentOutlinePage.

public Object getAdapter(Class adapter) {
    if (adapter.equals(IContentOutlinePage.class)) {
        return page;
    }
    // do NOT forget this line
    return super.getAdapter(adapter);
}

How do I get an editor's StyledText widget?

Since you cannot access the editor's ITextViewer, you will have to try using the code below.

StyledText text = (StyledText) editor.getAdapter(Control.class);

How can I get the IDocument from an editor?

Assuming your editor implements the ITextEditor interface, you can try the code below.

IDocumentProvider provider = editor.getDocumentProvider();
IDocument document = provider.getDocument(editor.getEditorInput());

This code should work on most text editors.

How do I get an IFile given an IEditorPart?

The code below will demonstrate how to do this.

IFile file = (IFile) editorPart.getEditorInput().getAdapter(IFile.class);
if (file != null) {
    // do stuff
}

Note that IFiles are meant to represent files within the workspace and will not work if the file that has been opened is not contained within the workspace.

Debug

How do I invoke a process and have its output managed by the 'Console' view?

Use DebugPlugin's newProcess(ILaunch, Process, String) or newProcess(ILaunch, Process, String, Map) method. You will probably be calling this in your ILaunchConfigurationDelegate implementation.

How do I associate my executed process with its command line counterpart?

Your IProcess implementation must return a valid string that corresponds to the IProcess.ATTR_CMDLINE attribute. The sample code below will demonstrate how this is done with the DebugPlugin's newProcess(ILaunch, Process, String, Map) method.

String commandLine = "/usr/bin/make";
Map attributes = new HashMap();
attributes.put(IProcess.ATTR_CMDLINE, commandLine);
Process process = Runtime.getRuntime().exec(commandLine);
// this assumes that 'launch' is a non-null reference to an ILaunch implementation
DebugPlugin.newProcess(launch, process, "make", attributes);

Back to the top