Monday, August 17, 2009

jarsigner error: java.lang.NegativeArraySizeException

This error occurs when there is a problem with the keystore file. Regenerate the keystore file to fix it. The problem in my case was that my keystore was checked into CVS as a ascii text file which corrupted it. I regenerated the keystore and checked it in as binary to fix it.

Friday, February 06, 2009

GridbagLayout anchor ignored

I banged my head at this all morning... I hope you dont have to go through this so posting it here.
The problem is that in some cases the GridBagConstraints.anchor setting is ignored and I couldnt quite figure out why. Until I read this in the javadocs :
weightx, weighty
Specifying weights is an art that can have a significant impact on the appearance of the components a GridBagLayout controls. Weights are used to determine how to distribute space among columns (weightx) and among rows (weighty); this is important for specifying resizing behavior.

Unless you specify at least one non-zero value for weightx or weighty, all the components clump together in the center of their container. This is because when the weight is 0.0 (the default), the GridBagLayout puts any extra space between its grid of cells and the edges of the container.

Now if you do not specify weight params, the anchor setting seems to be ignored completely. I dont know why. Also I have noticed in some other cases that the anchor works despite the weight params not being set. In those cases the ipad constraints were set. So it could be that setting ipad also works.

Thursday, December 20, 2007

Eclipse RCP, add new wizard to the workbench File menu and toolbar at the root level

Here is how you add your wizard as an option under the File > New menu, and toolbar drop down button.

If you were like me, you should have been easily be able to add a new wizard, but when you added it to the file menu, it added your wizard under the Others... category.

Here is how you get it at the root level, i.e. the same level as the new File and Folder wizards.


Step 1: Add the newWizards extension and your new wizard under it.
Step 2: Add the perspectivesExtensions extension and a newWizardShortcut extension under it.

Here is how the plugin.xml looks:

<plugin>

<extension id="application" point="org.eclipse.core.runtime.applications">
<application>
<run class="edu.pitt.dbmi.odie.Application">
</run>
</application>
</extension>
<extension point="org.eclipse.ui.perspectives">
<perspective name="RCP Perspective" class="edu.pitt.dbmi.odie.Perspective" id="edu.pitt.dbmi.odie.perspective">
</perspective>
</extension>
<extension point="org.eclipse.ui.newWizards">
<wizard class="edu.pitt.dbmi.odie.NewDocumentCollectionWizard"
id="edu.pitt.dbmi.odie.NewDocumentCollectionWizard"
name="Document Collection">
</wizard>
</extension>
<extension point="org.eclipse.ui.perspectiveExtensions">
<perspectiveExtension targetID="edu.pitt.dbmi.odie.perspective">
<newWizardShortcut id="edu.pitt.dbmi.odie.NewDocumentCollectionWizard">
</newWizardShortcut>
</perspectiveExtension>
</extension>

</plugin>


Step 3: create the actions and add it to the menu and toolbar.
You can edit the ApplicationActionBarAdvisor.java. You will need to override the makeActions, fillMenuBar and fillCoolBar methods.

Here are how they look:

IWorkbenchAction quitAction;
private IWorkbenchAction newWizardDropDownAction;
private IContributionItem newWizardMenu;
public ApplicationActionBarAdvisor(IActionBarConfigurer configurer) {
super(configurer);
}


protected void makeActions(IWorkbenchWindow window) {
newWizardDropDownAction = ActionFactory.NEW_WIZARD_DROP_DOWN.create(window);
register(newWizardDropDownAction);

newWizardMenu = ContributionItemFactory.NEW_WIZARD_SHORTLIST.create(window);
}

protected void fillMenuBar(IMenuManager menuBar) {


MenuManager menu = new MenuManager("File", IWorkbenchActionConstants.M_FILE);

{
// create the New submenu, using the same id for it as the New action
MenuManager newMenu = new MenuManager("New", "new");
newMenu.add(this.newWizardMenu);
menu.add(newMenu);
}

menuBar.add(menu);

}

@Override
protected void fillCoolBar(ICoolBarManager coolBar) {
ToolBarManager toolbar = new ToolBarManager(SWT.FLAT);
toolbar.add(newWizardDropDownAction);

coolBar.add(toolbar);
}


Note, Step 2 can also be done in code. Just add this line to the createInitialLayout method of your perspective

public void createInitialLayout(IPageLayout layout) {
layout.addNewWizardShortcut("edu.pitt.dbmi.odie.NewDocumentCollectionWizard");
}

IMPORTANT: Donot forget to clear workspace data to see your changes.

Monday, January 16, 2006

How to detect changes in a JTextField

textField.getDocument().addDocumentListener(new DocumentListener(){

public void changedUpdate(DocumentEvent arg0) {
}


public void insertUpdate(DocumentEvent arg0) {

}

public void removeUpdate(DocumentEvent arg0) {
}

});

Wednesday, March 02, 2005

Calculating execution time of a block of code

org.apache.xindice.Stopwatch has a nice stopwatch

Wednesday, January 19, 2005

convert String to InputStream

byte[] bytes = str.getBytes();

ByteArrayInputStream bais = new ByteArrayInputStream(bytes);

Thursday, January 13, 2005

How to have a page start from the top of the browser window, and occupy entire height of the browser

Using XTHML and CSS:

html, body {
height: 100%;
margin: 0;
padding: 0;
}
table {
height: 100%;
width: 100%;
background-color: #CCC;
}

avoid JDialog from being hidden when user switches to another application window

Common frustration with Java. Your child dialogs seem to disappear if you switch to another application window and come back. The only way to switch to the dialog box seems to be thru the task switching function ( Alt+Tab )


Actually, that only happens when you pass null to the constructor of JDialog. If you pass the parent frame's reference to the JDialog constructor, the jdialog is automatically made visibile when the user returns to your application.