How can I change the title of my Eclipse RCP at runtime? - eclipse

I'd like to change at runtime the name of my eclipse RCP application, so to include the name of the project the user is working on.
This seems a pretty simple question, but I was only able to find a way to set the name statically (in the article "branding your application").

There is a simpler way to do it, after I tried to do it as suggested here, I got into problems getting a hold of the Application or WorkbenchWindowAdvisor. The solution was simply to get the shell of the workbench window and setText:
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell().setText("My new title");

In your ApplicationWorkbenchWindowAdvisor get hold of the IWorkbenchWindowConfigurer and set the title there. e.g:
public void preWindowOpen()
{
IWorkbenchWindowConfigurer configurer = getWindowConfigurer();
configurer.setTitle("Custom Name...");
}

You can update the title at any time by burrowing down through the Application object:
Application.getApplication().getWorkbenchAdvisor().getWorkbenchWindowAdvisor().setTitle();

I do the same thing. I hold the getWindowConfigurer(); in some static reference.
Utility.configurer = getWindowConfigurer();
Then use this reference anywhere to update application title.
Utility.configurer.setTitle("My New Title");

Related

Apache Isis: How to implement your custom submit form or page properly?

I'm new at Apache Isis and I'm stuck.
I want to create my own submit form with editable parameters for search some entities and a grid with search results below.
Firstly, I created #DomainObject(nature=Nature.VIEW_MODEL) with search results collection, parameters for search and #Action for search.
After deeper research, I found out strict implementations for actions (For exapmle ActionParametersFormPanel). Can I use #Action and edit #DomainObject properties(my search parameters for action) without prompts?
Can I implement it by layout.xml?
Then I tried to change a component as described here: 6.2 Replacing page elements, but I was confused which ComponentType and IModel should I use, maybe ComponentType.PARAMETERS and ActionModel or implement my own IModel for my case.
Should I implement my own Wicket page for search and register it by PageClassList interface, as described here: 6.3 Custom pages
As I understood I need to replace page class for one of PageType, but which one should I change?
So, the question is how to implement such issues properly? Which way should I choose?
Thank you!
===================== UPDATE ===================
I've implemented HomePageViewModel in this way:
#DomainObject(
nature = Nature.VIEW_MODEL,
objectType = "homepage.HomePageViewModel"
)
#Setter #Getter
public class HomePageViewModel {
private String id;
private String type;
public TranslatableString title() {
return TranslatableString.tr("My custom search");
}
public List<SimpleObject> getObjects() {
return simpleObjectRepository.listAll();
}
#Action
public HomePageViewModel search(
#ParameterLayout(named = "Id")
String id,
#ParameterLayout(named = "Type")
String type
){
setId(id);
setType(type);
// finding objects by entered parameters is not implemented yet
return this;
}
#javax.inject.Inject
SimpleObjectRepository simpleObjectRepository;
}
And it works in this way:
I want to implement a built-in-ViewModel action with parameters without any dialog windows, smth like this:
1) Is it possible to create smth like ActionParametersFormPanel based on ComponentType.PARAMETERS and ActionModel and use this component as #Action in my ViewModel?
2) Or I should use, as you said, ComponentType.COLLECTION_CONTENTS? As I inderstand my search result grid and my search input panel will be like ONE my stub component?
Thank you.
We have a JIRA ticket in our JIRA to implement a filterable/searchable component, but it hasn't yet made it to the top of the list for implementation.
As an alternative, you could have a view model that provides the parameters you want to filter on as properties, with a table underneath. (I see you asked another question here on SO re properties on view models, so perhaps you are moving in that direction also... I've answered that question).
If you do want to have a stab at implementing that ticket, then the ComponentTYpe to use is COLLECTION_CONTENTS. If you take a look at the isisaddons, eg for excel or gmap3 then it might help get you started.
======= UPDATE TO ANSWER (based on update made to query) ==========
I have some good news for you. v1.15.0-SNAPSHOT, which should be released in the couple of weeks, has support for "inline prompts". You should find these give a user experience very similar to what you are after, with no further work needed on your part.
To try it out, check out the current trunk, and then load the simpleapp (in examples/application/simpleapp). You should see that editing properties and invoking actions uses the new inline prompt style.
HTH
Dan

Trigger formatter in a custom plug-in in Eclipse

I writing my own text editor plugin for eclipse. I am now working on my own formatter. Actually, following that link http://wiki.eclipse.org/FAQ_How_do_I_support_formatting_in_my_editor%3F.
I have written my Strategy, I have overridden getContentFormatter in my SourceViewerConfiguration..
As I run my plugin and press Ctrl+Shift+F - and nothing happens.
I think that I'm missing a step here. Should I create a handler or something?
Thanks
Might it be you skipped the last part of the linked page?
Finally, you will need to create an action that invokes the formatter. No generic formatting action is defined by the text infrastructure, but it is quite easy to create one of your own. The action’s run method can simply call the following on the source viewer to invoke the formatter:
sourceViewer.doOperation(ISourceViewer.FORMAT);
What helped me. I have created a handler with the following executors body:
//get the editorPart
if (editorPart != null) {
ITextOperationTarget target = (ITextOperationTarget) editorPart
.getAdapter(ITextOperationTarget.class);
if (target instanceof ISourceViewer) {
ISourceViewer textViewer = (ISourceViewer) target;
((ITextOperationTarget) textViewer)
.doOperation(ISourceViewer.FORMAT);
}
}
Then just create menu items and bind them to the handler.

Enforce Hyphens in .NET MVC 4.0 URL Structure

I'm looking specifically for a way to automatically hyphenate CamelCase actions and views. That is, I'm hoping I don't have to actually rename my views or add decorators to every ActionResult in the site.
So far, I've been using routes.MapRouteLowercase, as shown here. That works pretty well for the lowercase aspect of URL structure, but not hyphens. So I recently started playing with Canonicalize (install via NuGet), but it also doesn't have anything for hyphens yet.
I was trying...
routes.Canonicalize().NoWww().Pattern("([a-z0-9])([A-Z])", "$1-$2").Lowercase().NoTrailingSlash();
My regular expression definitely works the way I want it to as far as restructuring the URL properly, but those URLs aren't identified, of course. The file is still ChangePassword.cshtml, for example, so /account/change-password isn't going to point to that.
BTW, I'm still a bit rusty with .NET MVC. I haven't used it for a couple years and not since v2.0.
This might be a tad bit messy, but if you created a custom HttpHandler and RouteHandler then that should prevent you from having to rename all of your views and actions. Your handler could strip the hyphen from the requested action, which would change "change-password" to changepassword, rendering the ChangePassword action.
The code is shortened for brevity, but the important bits are there.
public void ProcessRequest(HttpContext context)
{
string controllerId = this.requestContext.RouteData.GetRequiredString("controller");
string view = this.requestContext.RouteData.GetRequiredString("action");
view = view.Replace("-", "");
this.requestContext.RouteData.Values["action"] = view;
IController controller = null;
IControllerFactory factory = null;
try
{
factory = ControllerBuilder.Current.GetControllerFactory();
controller = factory.CreateController(this.requestContext, controllerId);
if (controller != null)
{
controller.Execute(this.requestContext);
}
}
finally
{
factory.ReleaseController(controller);
}
}
I don't know if I implemented it the best way or not, that's just more or less taken from the first sample I came across. I tested the code myself so this does render the correct action/view and should do the trick.
I've developed an open source NuGet library for this problem which implicitly converts EveryMvc/Url to every-mvc/url.
Uppercase urls are problematic because cookie paths are case-sensitive, most of the internet is actually case-sensitive while Microsoft technologies treats urls as case-insensitive. (More on my blog post)
NuGet Package: https://www.nuget.org/packages/LowercaseDashedRoute/
To install it, simply open the NuGet window in the Visual Studio by right clicking the Project and selecting NuGet Package Manager, and on the "Online" tab type "Lowercase Dashed Route", and it should pop up.
Alternatively, you can run this code in the Package Manager Console:
Install-Package LowercaseDashedRoute
After that you should open App_Start/RouteConfig.cs and comment out existing route.MapRoute(...) call and add this instead:
routes.Add(new LowercaseDashedRoute("{controller}/{action}/{id}",
new RouteValueDictionary(
new { controller = "Home", action = "Index", id = UrlParameter.Optional }),
new DashedRouteHandler()
)
);
That's it. All the urls are lowercase, dashed, and converted implicitly without you doing anything more.
Open Source Project Url: https://github.com/AtaS/lowercase-dashed-route
Have you tried working with the URL Rewrite package? I think it pretty much what you are looking for.
http://www.iis.net/download/urlrewrite
Hanselman has a great example herE:
http://www.hanselman.com/blog/ASPNETMVCAndTheNewIIS7RewriteModule.aspx
Also, why don't you download something like ReSharper or CodeRush, and use it to refactor the Action and Route names? It's REALLY easy, and very safe.
It would time well spent, and much less time overall to fix your routing/action naming conventions with an hour of refactoring than all the hours you've already spent trying to alter the routing conventions to your needs.
Just a thought.
I tried the solution in the accepted answer above: Using the Canonicalize Pattern url strategy, and then also adding a custom IRouteHandler which then returns a custom IHttpHandler. It mostly worked. Here's one caveat I found:
With the typical {controller}/{action}/{id} default route, a controller named CatalogController, and an action method inside it as follows:
ActionResult QuickSelect(string id){ /*do some things, access the 'id' parameter*/ }
I noticed that requests to "/catalog/quick-select/1234" worked perfectly, but requests to /catalog/quick-select?id=1234 were 500'ing because once the action method was called as a result of controller.Execute(), the id parameter was null inside of the action method.
I do not know exactly why this is, but the behavior was as if MVC was not looking at the query string for values during model binding. So something about the ProcessRequest implementation in the accepted answer was screwing up the normal model binding process, or at least the query string value provider.
This is a deal breaker, so I took a look at default MVC IHttpHandler (yay open source!): http://aspnetwebstack.codeplex.com/SourceControl/latest#src/System.Web.Mvc/MvcHandler.cs
I will not pretend that I grok'ed it in its entirety, but clearly, it's doing ALOT more in its implementation of ProcessRequest than what is going on in the accepted answer.
So, if all we really need to do is strip dashes from our incoming route data so that MVC can find our controllers/actions, why do we need to implement a whole stinking IHttpHandler? We don't! Simply rip out the dashes in the GetHttpHandler method of DashedRouteHandler and pass the requestContext along to the out of the box MvcHandler so it can do its 252 lines of magic, and your route handler doesn't have to return a second rate IHttpHandler.
tl:dr; - Here's what I did:
public class DashedRouteHandler : IRouteHandler
{
public IHttpHandler GetHttpHandler(RequestContext requestContext)
{
requestContext.RouteData.Values["action"] = requestContext.RouteData.GetRequiredString("action").Replace("-", "");
requestContext.RouteData.Values["controller"] = requestContext.RouteData.GetRequiredString("controller").Replace("-", "");
return new MvcHandler(requestContext);
}
}

Eclipse RCP - project selected (Package Explorer)

How do I retrieve the name and path of the project selected? (Package Explorer)
example: c:\project\test\projectName
someone has some code that explains how to complete I get the project name or full path of a particular project in my workspace?
Eclipse defines an extension point
"org.eclipse.ui.navigator.linkHelper"
If you contribute a class to these EP you have to implement ILinkHelper
The ILInkHelper interface notifies you, when something was selected in the explorer
public void activateEditor(IWorkbenchPage aPage, IStructuredSelection aSelection)
You can check the type of the selection
if (aSelection.getFirstElement() instanceof IFile) {
// Do something
}
Old memories but maybe useful for you. I guess package explorer provides its selection, so you can get the current selection in your code by calling:
ISelectionService service = getSite().getWorkbenchWindow().getSelectionService()
than you can get the package explorer view by its id (plugin.xml for more details):
IStructuredSelection selection = (IStructuredSelection) service.getSelection("org.eclipse.jdt.ui.PackageExplorer");
Please note AFAIK you can always safely cast ISelection to IStructuredSelection. Then call structured.getFirstElement() and I think the first element will be an IFile object. I hope my "pseudo code" whould be enough for you. And IFile has lots of usefule methods for your convenience

Eclipse RCP Main window not resizable

does anyone know how to disable the possibility of resizing the main window of my Eclipse application
Thanks a lot
You can try a restrictive ShellStyle, as suggested in this thread and detailed in this one (SWT.DIALOG_TRIM):
public void preWindowOpen() {
IWorkbenchWindowConfigurer configurer = getWindowConfigurer();
configurer.setInitialSize(new Point(800, 600));
configurer.setShowCoolBar(false);
configurer.setShowStatusLine(false);
configurer.setTitle("RFID demo");
}
You need to call setShellStyle(). See the Javadoc for the Shell(int) constructor for an explanation of how to form the argument.
According to WorkbenchWindowConfigurer the default value is SWT.SHELL_TRIM, which includes the SWT.RESIZE option.
You'll have to formulate a value that does not include SWT.RESIZE.
It was exactly what I was searching for,
configurer.setShellStyle(SWT.DIALOG_TRIM);