Bug 76230 - Null pointer exception for custom-made composites
Summary: Null pointer exception for custom-made composites
Status: NEW
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: VE (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: David J. Orme CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-10-13 23:25 EDT by Andrei Adrian CLA
Modified: 2011-06-13 11:36 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Andrei Adrian CLA 2004-10-13 23:25:07 EDT
Null pointer exception for custom code with different "initialize" method name
and JFace controls. Code example:
package xxx.composite;

import java.util.Map;

import org.eclipse.jface.viewers.IDoubleClickListener;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Composite;

import xxx.model.OutputMapContentProvider;
import xxx.OutputMapLabelProvider;

/**
 * Class Outliner implementation.
 *
 * @author aandrei
 * @version $Revision$
 */
public class Outliner extends Composite {
 /**
  * Field m_treeViewer
  */
 private TreeViewer m_treeViewer;
 /**
  * Field m_contentProvider
  */
 private OutputMapContentProvider m_contentProvider = new 
OutputMapContentProvider();
 /**
  * Field m_labelProvider
  */
 private OutputMapLabelProvider m_labelProvider = new 
OutputMapLabelProvider();

 public Outliner(Composite arg0, int arg1) {
  super(arg0, arg1);
  setLayout(new FormLayout());
  createContents();
 }

 /**
  * Method createContents
  */
 public void createContents() {
  Composite composite = new Composite(this, SWT.NONE);
  composite.setLayout(new FillLayout());
  final FormData formData = new FormData();
  formData.bottom = new FormAttachment(100, 0);
  formData.right = new FormAttachment(100, 0);
  formData.top = new FormAttachment(0, 0);
  formData.left = new FormAttachment(0, 0);
  composite.setLayoutData(formData);
  {
   m_treeViewer = new TreeViewer(composite, SWT.BORDER);
   m_treeViewer.setLabelProvider(m_labelProvider);
   m_treeViewer.setContentProvider(m_contentProvider);
  }
 }

 public void setContent(Map outputMap) {
  m_treeViewer.setInput(outputMap);
 }

 /**
  * Sets the content owner. It acts like a key so the controller knows when
  * to refresh it or not. To release the owner a call with null argument
  * should be placed.
  *
  * @param key Object - can be null
  */
 public void setOwner(Object key) {
  setData(key);
 }

 /**
  * Returns true if the content has the same key as the argument. The
  * comparison if done using equal for a non-null argument.
  *
  * @param key Object - owner's key, can be null. If null it returns if
  * the content has no key.
  *
  * @return true if the content has the same as the argument
  */
 public boolean isOwner(Object key) {
  if(key == null) {
   return getData()==null;
  } else {
   return key.equals(key);
  }
 }

 /**
  * Sets the outliner content empty, resets the owner.
  */
 public void setNoContent() {
  setOwner(null);
  m_treeViewer.setInput(null);
 }

 /**
  * Delegates the double click listener.
  *
  * @param arg0 IDoubleClickListener - new event
  */
 public void addContentDoubleClickListener(IDoubleClickListener arg0) {
  m_treeViewer.addDoubleClickListener(arg0);
 }

}