Another question concerning my XML-multipage editor. It is possible to contribute to eclipse's tool bar by means of MultiPageEditorActionBarContributor, to be precise by overriding contributeToToolBar(IToolBarManager manager) method and use the passed manager. In this case the contributed button(s) are visible from all pages of the editor.
#Override
public void contributeToToolBar(IToolBarManager manager)
{
manager.add(new Separator());
manager.add(updateTabsAction);
}
Is it possible to make some buttons visible olny if a specific page is selected?
This one was quite easy to solve. Instead of overriding contributeToToolBar I added some code to setActivePage and worked with a ToolBarManager from there:
#Override
public void setActivePage(IEditorPart part)
{
// ...skipped...
IActionBars actionBars = getActionBars();
if (actionBars != null)
{
// ...skipped...
IToolBarManager toolBarManager = actionBars.getToolBarManager();
if (part instanceof StructuredTextEditor)
{
toolBarManager.add(separator);
toolBarManager.add(updateTabsAction);
}
else
{
toolBarManager.removeAll();
}
toolBarManager.update(true); //This is important. Otherwise the
//changes aren't applied to the toolbar.
actionBars.updateActionBars();
}
}
Related
I am navigating between forms in the NEW GUI builder. The old one had a back button on every form by default.
How do I enable the back button on new gui builder in every form, every time i navigate in a new form? Tried through constants in theme.res. It is still not enabled by default.
Furthermore, is the method "new form1.show" the best way to navigate between forms ? (see code)
Assuming name files:
Main.java, myapplication.java, Form1 ,Form2 ,Form3
Code for navigation, assuming names button1 and Form3:
public void onbutton1ActionEvent(com.codename1.ui.events.ActionEvent ev) {
new Form3().show();
}
Back command from old gui builder, not working here:
public Form showForm(String resourceName, Command sourceCommand) {
try {
Form f = (Form)formNameToClassHashMap.get(resourceName).newInstance();
Form current = Display.getInstance().getCurrent();
if(current != null && isBackCommandEnabled() && allowBackTo(resourceName)) {
f.putClientProperty("previousForm", current);
setBackCommand(f, new Command(getBackCommandText(current.getTitle())) {
public void actionPerformed(ActionEvent evt) {
back(null);
}
});
}
if(sourceCommand != null && current != null && current.getBackCommand() == sourceCommand) {
f.showBack();
} else {
f.show();
}
return f;
} catch(Exception err) {
err.printStackTrace();
throw new RuntimeException("Form not found: " + resourceName);
}
}
I've tried:
form.setBackCommand(cmd);
public Command setBackCommand(String title, ActionListener<ActionEvent> listener)
public void setBackCommand(Command cmd)
public Command setBackCommand(String title, BackCommandPolicy policy, ActionListener<ActionEvent> listener)
public void setBackCommand(Command cmd, BackCommandPolicy policy)
boolean onBack() {
return true;
}
https://www.codenameone.com/blog/toolbar-back-easier-material-icons.html
on main.java and myapplication.java did not accept the commands.
Form3.getToolbar().setBackCommand("", e -> Form3.showBack());
althouth is should not work only for form3, but every form.
Did not work either. Putting "back command" on every sidemenu would not be the ideal solution, because we might be navigating to each form from different forms.
EXTRA:
Is there a way to enable global toolbar and global commands for all forms, so i do not copy paste the toolbar code for each new form? If not answered here, i might make a new thread.
Thanks.
The old GUI builder handled navigation as it was designed at a time when Nokia was the worlds leader in the mobile phone industry and a 4in device was considered large. Back then we assumed the UI was simpler for each form and the navigation was the hard part.
This changed. But the bigger problem for most developers was the concept of stateless navigation which triggered a lot of issues both in design and functionality.
The new GUI builder doesn't include any navigation code or any global code. Each form stands on its own.
Having said that you can implement your own state machine by just keeping form instances and showing the form you want to navigate to e.g.:
public static class Controller {
private static Form1 f1;
private static Form2 f2;
public static void showF1() {
if(f1 == null) f1 = new Form1();
f1.show();
}
// etc...
}
I used static context for simplicity but you can implement your own strategy. Notice that you can also insert global logic here e.g. add the toolbar as a function like:
private static void initForm(Form f) {
// add global commands to the toolbar
}
Alternatively you can derive all the forms from a common base class as the new GUI builder doesn't restrict your inheritance.
I have a grid like this one . The default behavior of this widget is to sort the column when clicking on the header. I want to disable that, and leave only the options in the context menu.
grid.addHeaderClickHandler(new HeaderClickHandler() {
#Override
public void onHeaderClick(HeaderClickEvent event) {
event.getEvent().cancelBubble(true);
event.getEvent().preventDefault();
event.getEvent().stopPropagation();
Window.alert("Event caught");
}
});
The alert gets displayed before the sorting. But when clicking Ok the default behavior kicks in.
Do you have any suggestions on how to accomplish this?
A solution that might work is to use the NativePreviewHandler, something similar to
Event.addNativePreviewHandler(new NativePreviewHandler()
{
#Override
public void onPreviewNativeEvent(final NativePreviewEvent event)
{
if (event.getTypeInt() == Event.ONCLICK)
{
Element targetElement = Element.as(event.getNativeEvent().getEventTarget());
if (!tableHeader.asWidget().getElement().isOrHasChild(targetElement))
{
event.getNativeEvent().stopPropagation();
}
}
}
});
In order to disable sorting you have to configure the column(s) to forbid sorting.
E.g. if you create a column like this (based on the source code from http://www.sencha.com/examples/#ExamplePlace:basicgrid)
ColumnConfig<Stock, String> symbolCol = new ColumnConfig<Stock, String>(props.symbol(), 100, "Symbol");
disable sorting by adding
symbolCol.setSortable(false);
See http://dev.sencha.com/deploy/gxt-3.0.0/javadoc/gxt/com/sencha/gxt/widget/core/client/grid/ColumnConfig.html#setSortable%28boolean%29 for documentation (and other options).
Ok I found it grid.getView().setSortingEnabled(false);. This will disable the sorting when clicking on the header, but keep the menu items in place.
I have created new Eclipse IDE (plugin project, Eclipse Kepler, rel. 1) with default template of mail client.
After the first run of the app, the Perspective is stored and remembered (somewhere?) and any changes to Perspective.java has no any effect! Even if I delete the content of createInitialLayout(IPageLayout layout) from the Perspective.java, everything is restored again.
BTW: adding this code to ApplicationWorkbenchAdvisor.java didnt help:
#Override
public void initialize(IWorkbenchConfigurer configurer) {
super.initialize(configurer);
configurer.setSaveAndRestore(false);
}
How can I force the app to not to remmeber the layout?
You could call IWorkbenchPage.resetPerspective() to reinitialize the perspective, perhaps in the WorkbenchWindowAdvisor.postWindowRestore() method.
Thank you. I have added the following code to menu. Now I can reset perspective whenever I need.
public class ApplicationActionBarAdvisor extends ActionBarAdvisor {
private IWorkbenchAction resetPerspectiveAction;
#Override
protected void makeActions(IWorkbenchWindow window) {
// ...
// create and register the actions
resetPerspectiveAction = ActionFactory.RESET_PERSPECTIVE.create(window);
register(resetPerspectiveAction);
// ...
}
#Override
protected void fillMenuBar(IMenuManager menuBar) {
// ...
// create and fill the window menu
MenuManager windowMenu = new MenuManager("&Window", WorkbenchActionConstants.M_WINDOW);
menuBar.add(windowMenu);
windowMenu.add(resetPerspectiveAction);
// ...
}
}
I am developing a multipage Form Editor to edit/create a customized XML file in Eclipse.
structure is looks like:
Implementation class is MyXMLFormEditor which extends FormEditor.
Each page of FormEditor extends FormPage (i.e. MyXMLFormPage extends FormPage).
Between FormEditor and actual XML file I am maintaining JDOM model.
Also I implemented dirty flag handling. So user’s inputs into form editor gets saved into JDOM till the time user presses Save button. When user presses save button JDOM is written/serialized into XML file.
In an editor with above functionality I would like to implement undo/redo functionality as follow:
When editor is dirty (user changed something into form editor and it is not saved) undo operation should revert back the changes in form editor as well as JDOM to its original state (i.e. the state when editor was non-dirty) and redo operation should again bring back the changes into FormEditor as well as JDOM and editor should become dirty.
Following is my code snippet
MyXMLFormEditor.java
public class MyXMLFormEditor extends FormEditor {
MyXMLFormEditor(){
super();
}
#Override
protected FormToolkit createToolkit(Display display) {
// Create a toolkit that shares colors between editors.
return new FormToolkit(Activator.getDefault().getFormColors(display));
}
#Override
public void init(IEditorSite site, IEditorInput editorInput) {
setSite(site);
mSite = site;
setInput(editorInput);
try {
super.init(site, editorInput);
} catch (PartInitException e1) {
e1.printStackTrace();
}
if (!(editorInput instanceof IFileEditorInput))
try {
throw new PartInitException("Invalid Input: Must be IFileEditorInput");
} catch (PartInitException e) {
e.printStackTrace();
}
setPartName(fileName);
}
public void setUpProgFile(IEditorSite site, IEditorInput editorInput){
IFileEditorInput fileInput = ((IFileEditorInput) editorInput);
//create document builder and prepare JDom model for xml file.
}
#Override
protected void addPages() {
try {
//add 'Main' page
objMyXMLFormPage = new MyXMLFormPage (this, "FirstPage","Main");
//set rootNode of MyXMLFormPage
objMyXMLFormPage.rootNode = getRootNode();
objMyXMLFormPage.filePath = filePath;
objMyXMLFormPage.document = document;
addPage(objMyXMLFormPage);
} catch (PartInitException e) {
e.printStackTrace();
}
}
#Override
public void doSave(IProgressMonitor monitor) {
System.out.println("MyXMLFormEditor: doSave");
//logic to write jdom contents into xml file.
objMyXMLFormPage.setDirty(false);
}
#Override
public void doSaveAs() {
System.out.println("MyXMLFormEditor: doSaveAs");
}
#Override
public boolean isSaveAsAllowed() {
System.out.println("MyXMLFormEditor: isSaveAsAllowed");
return true;
}
}
MyXMLFormPage .java
public class MyXMLFormPage extends FormPage{
//private members declaration.
public MyXMLFormPage (MyXMLFormEditor editor,String title, String id) {
// initialize the editor and set its title and name.
super(editor,title,id );
}
#Override
public void createFormContent(IManagedForm managedForm) {
// Set page title
super.createFormContent(managedForm);
FormToolkit mMyXMLFormPage Toolkit = managedForm.getToolkit();
//Logic to creat UI and populating its contents from JDom
}
private void makeEditorDirty() {
updateJdom = true;
setDirty(true);
}
private void updateJDom() {
if(updateJdom){
System.out.println("*** Jdom updated ***");
updateJdom = false;
}
}
#Override
public boolean isDirty() {
return isDirtyFlag;
}
protected void setDirty(boolean value) {
isDirtyFlag = value;
dirtyStateChanged();
}
public void dirtyStateChanged() {
getEditor().editorDirtyStateChanged();
}
#Override
public boolean isSaveAsAllowed() {
System.out.println("MyXMLFormPage .isSaveAsAllowed");
return false;
}
#Override
public void doSave(IProgressMonitor monitor) {
System.out.println("MyXMLFormPage .doSave");
}
}
Can anyone provide me pointer/samples on how to implement undo/redo functionality into FormEditor? It would be good if the approach make use of existing undo/redo framework of Eclipse PDE or workbench.
There are a couple of important points to make about the pattern used by multi-page editor implementations in Eclipse. There may be other ways of doing it, but the editors in Eclipse seem to adhere to these points:
Maintain a model of the data that's shared by the pages in the editor (you're doing this).
Only refresh a page with the model data when the page is about to be displayed. Don't try to keep non-displayed pages in sync with the model.
When you perform an undo or redo, make the appropriate changes to the model (per #Scorpion's comment) and then refresh the current page.
Each page should have a its-ok-to-leave-this-page method (I don't remember the name) which is called to make sure that the displayed data is error free enough to allow the page to be changed (you don't want errors on non-displayed data).
Pages have an about-to-leave-this-page method which is called to save any changes to the model before switching pages. Most pages don't do anything here because the model is modified sometimes by every keystroke, but the source page would use this method to replace the model completely with the parse results on the text editor contents.
What this means is that your forms don't have to perform the undo/redo themselves. Rather, the classes representing the multipage editor pages will interact with the model as it's changed and then pass the correct data to be displayed to the forms.
The forms will need to listen for the undo/redo key events and pass those along to the model via the command pattern.
today I changed my Eclipse IDE from 3.7 to 4.2 and my plugin-project has a new feature in the Statusbar of the UI called QuickAccess. But I dont need it, so how can I disable this feature, because the position of my button bar has changed...
For all who have the same problem, it seems that this new feature is hardcoded and can't be disabled :/ https://bugs.eclipse.org/bugs/show_bug.cgi?id=362420
Go to Help --> Install New Software
https://raw.github.com/atlanto/eclipse-4.x-filler/master/pdt_tools.eclipse-4.x-filler.update/
Install that Plugin and Restart the Eclipse. Quick Access automatically hide.
or else you have an option to hide Window --> Hide Quick Access.
Here's a post that shows a way to hide it with CSS. Verified with Eclipse 4.3
Lars Vogel just reported in his blog post "Porting Eclipse 3.x RCP application to Eclipse 4.4 – now without QuickAccess box":
Bug 411821 ([QuickAccess] Contribute SearchField through a fragment or other means)
is now solved.
Thanks to René Brandstetter:
If a RCP app doesn't provide the QuickAccess element in its model, than it will not be visible. So the default is no QuickAcces, easy enough? :)
See the commit 839ee2 for more details
Provide the "QuickAccess" via a e4 application model fragment inside of the "org.eclipse.ui.ide.application".
This removes the "QuickAccess" search field from every none "org.eclipse.ui.ide.application".
You could also hide it and make it work comparable to how it used to work in Eclipse3.7: when user presses ctrl+3 Quick Access functionality pops up (In Eclipse4.3 the ctrl+3 shortcut is still available).
Example of code you could add to your implementation of WorkbenchWindowAdvisor (for Eclipse4.3 rcp application)
private IHandlerActivation quickAccessHandlerActivation;
#Override
public void postWindowOpen() {
hideQuickAccess();
}
private void hideQuickAccess() {
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
setQuickAccessVisible(window, false);
final IHandlerService service = (IHandlerService) window.getService(IHandlerService.class);
quickAccessHandlerActivation = service.activateHandler(QUICK_ACCESS_COMMAND_ID, new CustomQuickAccessHandler());
}
private void setQuickAccessVisible(IWorkbenchWindow window, boolean visible) {
if (window instanceof WorkbenchWindow) {
MTrimBar topTrim = ((WorkbenchWindow) window).getTopTrim();
for (MTrimElement element : topTrim.getChildren()) {
if (QUICK_ACCESS_ELEMENT_ID.equals(element.getElementId())) {
element.setVisible(visible);
if (visible) {
Composite control = (Composite) element.getWidget();
control.getChildren()[0].addFocusListener(new QuickAccessFocusListener());
}
break;
}
}
}
}
private class QuickAccessFocusListener implements FocusListener {
#Override
public void focusGained(FocusEvent e) {
//not interested
}
#Override
public void focusLost(FocusEvent e) {
((Control) e.widget).removeFocusListener(this);
hideQuickAccess();
}
}
private class CustomQuickAccessHandler extends AbstractHandler {
#Override
public Object execute(ExecutionEvent event) throws ExecutionException {
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
final IHandlerService service = (IHandlerService) window.getService(IHandlerService.class);
setQuickAccessVisible(window, true);
if (quickAccessHandlerActivation != null) {
service.deactivateHandler(quickAccessHandlerActivation);
try {
return service.executeCommand(QUICK_ACCESS_COMMAND_ID, null);
} catch (NotDefinedException e) {
} catch (NotEnabledException e) {
} catch (NotHandledException e) {
}
}
return null;
}
}