Save option in RCP Product - eclipse-plugin

Iam developing a RCP application which consists of views and editors. I can change the values and edit the values of some parameters in editor. When a value has been changed, i need to make the editor dirty as well as would also like to enable the save button. Till now, i have not implemented my save button. Could anyone guide me how to make the save button enabled as well as how can i make an editor dirty when some modifications happen in editor.
Thanks in advance. Any help will be greatly appreciated.
Regards,
Girish

Here is an overview of the Form editor logic, hop it will help you.
public class TestEditor extends FormEditor {
#Override
protected void addPages() {
// this method is called when the editor is being created
// to add the necessary pages
// page classes should be like following
// class TestEditorPage extends FormPage
try {
TestEditorPage pageTest = new TestEditorPage(this);
addPage(pageTest);
} catch (PartInitException e) {
}
}
#Override
public void doSave(IProgressMonitor monitor) {
// this method will be called on save action
// (or Ctrl + s shortcut)
}
#Override
public void doSaveAs() {
// this method will be called on save-as
//call (or Ctrl + Shift + s shortcut)
}
#Override
public boolean isSaveAsAllowed() {
// put here the call to the logic that
// check if the save is allowed
return true;
}
#Override
public boolean isDirty() {
// Here the call for the logic that
// defines if the editor is dirty or not
return true;
}
}

Related

How do I make the "user operation is waiting" dialog invisible in Eclipse RCP?

I'm creating a web development framework with Eclipse RCP.
The wizard is creating a feature that creates a project when you press Finish.
I want to show Process Monitor at the bottom of the wizard
I wrote the code as below.
public abstract class CreateProjectWizard extends Wizard {
public CreateProjectWizard () {
...
setNeedsProgressMonitor(true);
}
...
#Override
public boolean performFinish() {
IRunnableWithProgress runnable= new IRunnableWithProgress() {
#Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
...
IStatus status = createProject(input, monitor);
...
}
};
try {
getContainer().run(true, true, runnable);
}
...
return true;
}
}
How do I make the "user operation is waiting" dialog invisible?
I will let you know if you need additional information.
It looks like you should be able to call Dialog.setBlockedHandler with something that implements IDialogBlockedHandler to change this dialog (both in org.eclipse.jface.dialogs).
The blocked handler does not have to display a dialog, the default JFace handler is just:
new IDialogBlockedHandler() {
#Override
public void clearBlocked() {
// No default behavior
}
#Override
public void showBlocked(IProgressMonitor blocking,
IStatus blockingStatus, String blockedName) {
// No default behavior
}
#Override
public void showBlocked(Shell parentShell, IProgressMonitor blocking,
IStatus blockingStatus, String blockedName) {
// No default behavior
}
};
Eclipse normally replaces this with org.eclipse.ui.internal.dialogs.WorkbenchDialogBlockedHandler which shows the dialog you see (BlockedJobsDialog).
Note that this will not stop the operation waiting for the blocking jobs to finish it will just stop the dialog appearing.

Eclipse Plugin: How can I tell the plugin to open a new Editor every time instead of switching the focus to an existing Editor?

In my Plugin there is an action to open an Editor (extends EditorPart). When I try to open it a second time, its init method isn't called. Instead the focus is shifted to the editor that is already open.
The Editor is associated with a filetype. Here is the excerpt from the plugin.xml:
<extension point="org.eclipse.ui.editors">
<editor
class="de.blub.tool.ide.editors.GRASPEditor"
default="true"
extensions="grasp"
filenames="*.grasp"
icon="icons/newGraspFile.png"
id="de.blub.tool.ide.editors.GRASPEditor"
name="GRASP File Editor">
</editor>
</extension>
I have an Action to open a new Editor. When I try to click that Action twice it reuses the first Editor. I also tried to use an EditorMatcher that implements IEditorMatchingStrategy and always returns false in its matches() method. Even that doesn't change the behavior.
This seems to be a desired/default behavior in eclipse. How can I change that so that the user can initialize a new Editor each time?
Eclipse looks for the equals method of the IEditorInput instance. The Editor somewhere in its code (in my case in the doSave method) uses a setInput method like this:
#Override
public void init(IEditorSite site, IEditorInput input) throws PartInitException {
// Initialize the editor input
this.input = new MyInputClass(resource);
...
}
#Override
public void doSave(IProgressMonitor monitor) {
...
setInput(input);
}
MyInputClass is the class that extends IEditorInput. The logic for eclipse to reuse an Editor or create a new one is in its equals method. The following example checks the path of an IResource field:
public class MyInputClass implements IEditorInput {
private IResource resource;
public MyInputClass(IResource resource) {
this.resource = resource;
}
public IResource getResource() {
return resource;
}
public void setResource(IResource resource) {
this.resource = resource;
}
#Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj instanceof MyEditorClass) {
MyEditorClass other = (MyEditorClass) obj;
if (getResource().getFullPath().equals(other.getResource().getFullPath())) {
return true;
}
}
return false;
}
}
Of course one can define another logic inside the equals method. Make sure to not create a chaos, which is very well possible, as greg-449 pointed out in a comment.

Showing link inside custom hover (Eclipse plugin development)

I have a custom hover inside CDT editor (see the linked SO question) and now I want to show link inside my IAnnotationHover hover:
public class MyAwesomeHover implements IAnnotationHover {
#Override
public String getHoverInfo(ISourceViewer sw, int ln) {
return "<a href='www.stackoverflow.com'>so</a>"
}
}
Unfortunately the link is not shown - the hover window shows only simple text (i.e "so"). Other HTML elements I tried work OK (ul, li, p, font ...). Can anyone help me please?
As was mentioned in the comments, the RevisionHover was a good starting point. The magic is in implementing the IAnnotationHoverExtension and creation of a custom AbstractReusableInformationControlCreator. I am posting a code snippet with solution that worked for me.
public class MyHover implements IAnnotationHover, IAnnotationHoverExtension {
...
#Override
public IInformationControlCreator getHoverControlCreator() {
return new MyCreator();
}
...
#Override
public Object getHoverInfo(ISourceViewer sv, ILineRange lr, int vnl) {
return "<a href='www.stackoverflow.com'>so</a>";
}
...
private final class MyCreator extends AbstractReusableInformationControlCreator {
protected IInformationControl doCreateInformationControl(Shell parent) {
BrowserInformationControl control =
new BrowserInformationControl(
parent,
JFaceResources.DIALOG_FONT,
false);
control.addLocationListener(
new LocationAdapter() {
#Override
public void changing(LocationEvent ev) {
if (ev.location.startsWith("file:")) {
// !This opens the link!
openUrl(ev.location)
}
}
});
return control;
}
}
}

SharePoint webparts requesting information prior to load

Here is how it works:
Filter web part sends row of data to all other webparts on the page.
It's control is rendered at load time, rendering the control selects which row is sent back to the other webparts on the page.
This causes the issue on the first page load where the other webparts will request the row from provider before it has finished loading and therefore has no information to provide yet.
The only solution (which is really ugly, slow and horrible) is to run all of the code that would be run in the control class the webpart uses in the webpart's constructor and use it to predict what values the control will have on the first run. This also leads to a whole bunch of issues with deploying that I really would rather avoid.
Here's the webpart code:
public class FilterProjectHeader : WebPart, IWebPartRow
{
// Visual Studio might automatically update this path when you change the Visual Web Part project item.
private const string _ascxPath = #"[link goes here]";
public DataRowView data;
public DataTable table;
private FilterProjectHeaderUserControl control;
public FilterProjectHeader()
{
//Code I want to avoid using:
//var web = SPContext.Current.Web;
//table = web.Lists["foo"].Items.GetDataTable();
//data = foo();
}
protected override void CreateChildControls()
{
control = Page.LoadControl(_ascxPath) as FilterProjectHeaderUserControl;
control.provider = this;
Controls.Add(control);
}
public PropertyDescriptorCollection Schema
{
get
{
return TypeDescriptor.GetProperties(table.DefaultView[0]);
}
}
[ConnectionProvider("Row")]
public IWebPartRow GetConnectionInterface()
{
return this;
}
public void GetRowData(RowCallback callback)
{
callback(data);
}
}
And for the control:
public partial class FilterProjectHeaderUserControl : UserControl
{
public FilterProjectHeader provider { get; set; }
private String _selectedValue;
//Both OnLoad and OnInit have the same result.
protected override void OnInit(EventArgs e)
{
//This is what gets run the first time:
if (!IsPostBack)
{
//Code here finds data then sends it back to webpart like this:
//All of the code in this method definitely does run; I have stepped
//through it and it works but it seems to happen too late to have any
//effect.
provider.data = item;
provider.table = profilesTable;
}
}
protected void filterDropDown_SelectedIndexChanged(object sender, EventArgs e)
{
//Post back method code exempted... it works.
provider.data = item;
provider.table = profilesTable;
}
So after a lot of time working with this, I found the issue is actually with what Microsoft recommends to do as best practice (they say to always use CreateChildControls to load controls onto the page).
CreateChildControls runs AFTER OnLoad when it is the first time a page is loading, but runs BEFORE OnLoad on a repost.
This is why it works on reposts, but not on first page load.
Switching CreateChildControls to OnInit solves the problem, because OnInit will always run before OnLoad.

Stop Intellij / Android Studio Preview adding newlines when formatting anonymous inner class parameters

I'm trying to stop Android Studio Preview (ie IntelliJ) from adding in a newline / carriage return after an anonymous inner class when it's defined as a method parameter. It changes this:
runOnUiThread(new Runnable() {
#Override
public void run() {
//Some code
}
});
to this:
runOnUiThread(new Runnable() {
#Override
public void run() {
//Some code
}
}
);
I've looked through the formatting settings, but can't seem to find the relevant setting.
Check out these options:
Let me know if it doesn't work for you