Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

ensure database is loaded

  • Loading branch information...
commit cea65bb59d9c82b312a58c3c215d3df6ee210396 1 parent 0f15ca7
@JPMoresmau authored
View
1  docs/releasenotes/net.sf.eclipsefp.haskell_2.4.3.txt
@@ -10,6 +10,7 @@ Necessary Haskell packages:
Fixes:
+ - Viewing a package in the browser from the Cabal Packages view the first time could cause a NullPointerException
Features:
- Cabal Packages view shows a green tick on installed packages and versions when you display the list of all hackage packages.
View
388 ...clipsefp.haskell.ui/src/net/sf/eclipsefp/haskell/browser/views/packages/PackagesView.java
@@ -1,187 +1,203 @@
-/**
- * (c) 2011, Alejandro Serrano
- * Released under the terms of the EPL.
- */
-package net.sf.eclipsefp.haskell.browser.views.packages;
-
-import java.net.URL;
-import net.sf.eclipsefp.haskell.browser.BrowserEvent;
-import net.sf.eclipsefp.haskell.browser.BrowserPlugin;
-import net.sf.eclipsefp.haskell.browser.DatabaseLoadedEvent;
-import net.sf.eclipsefp.haskell.browser.IDatabaseLoadedListener;
-import net.sf.eclipsefp.haskell.browser.util.HtmlUtil;
-import net.sf.eclipsefp.haskell.browser.views.NoDatabaseContentProvider;
-import net.sf.eclipsefp.haskell.browser.views.NoDatabaseLabelProvider;
-import net.sf.eclipsefp.haskell.browser.views.NoDatabaseRoot;
-import org.eclipse.jface.viewers.DoubleClickEvent;
-import org.eclipse.jface.viewers.IContentProvider;
-import org.eclipse.jface.viewers.IDoubleClickListener;
-import org.eclipse.jface.viewers.ISelectionChangedListener;
-import org.eclipse.jface.viewers.SelectionChangedEvent;
-import org.eclipse.jface.viewers.StructuredSelection;
-import org.eclipse.jface.viewers.TreeSelection;
-import org.eclipse.jface.viewers.TreeViewer;
-import org.eclipse.jface.viewers.ViewerSorter;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.browser.Browser;
-import org.eclipse.swt.custom.SashForm;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.ui.browser.IWebBrowser;
-import org.eclipse.ui.browser.IWorkbenchBrowserSupport;
-import org.eclipse.ui.part.ViewPart;
-
-/**
- * View part for the 'packages' in the Browser.
- * @author Alejandro Serrano
- *
- */
-public class PackagesView extends ViewPart implements IDatabaseLoadedListener,
- ISelectionChangedListener, IDoubleClickListener {
-
- /**
- * The ID of the view as specified by the extension.
- */
- public static final String ID = "net.sf.eclipsefp.haskell.browser.views.packages.PackagesView";
-
- TreeViewer viewer;
- Browser doc;
- IContentProvider provider;
-
- @Override
- public void createPartControl( final Composite parent ) {
- SashForm form = new SashForm( parent, SWT.VERTICAL );
- viewer = new TreeViewer( form );
- doc = new Browser( form, SWT.NONE );
- doc.setFont( viewer.getControl().getFont() );
- form.setWeights( new int[] { 75, 25 } );
-
- // Set database
- if (BrowserPlugin.getDefault().isAnyDatabaseLoaded()) {
- databaseLoaded( null );
- } else {
- databaseUnloaded( null );
- }
- // Hook for listeners
- BrowserPlugin.getDefault().addDatabaseLoadedListener( this );
- // Hook for changes in selection
- viewer.addPostSelectionChangedListener( this );
- // Hook for double clicking
- viewer.addDoubleClickListener( this );
- // Register as selection provider
- getSite().setSelectionProvider( viewer );
- }
-
- @Override
- public void setFocus() {
- viewer.getControl().setFocus();
- }
-
- @Override
- public void databaseLoaded( final DatabaseLoadedEvent e ) {
- Display.getDefault().asyncExec( new Runnable() {
-
- @Override
- public void run() {
- // Set real content provider
- PackagesContentProvider daProvider = new PackagesContentProvider();
- provider = daProvider;
- viewer.setContentProvider( provider );
- viewer.setLabelProvider( new PackagesLabelProvider() );
- viewer.setSorter( new PackagesSorter() );
- // Refresh with the items
- viewer.setInput( PackagesRoot.ROOT );
- // Use the new provider
- daProvider.uncache();
- viewer.refresh();
- }
- } );
- }
-
- @Override
- public void databaseUnloaded( final BrowserEvent e ) {
- Display.getDefault().asyncExec( new Runnable() {
-
- @Override
- public void run() {
- if (!BrowserPlugin.getDefault().isAnyDatabaseLoaded()) {
- // Put the "no database" content and label
- viewer.setLabelProvider( new NoDatabaseLabelProvider( false ) );
- viewer.setSorter( new ViewerSorter() );
- provider = new NoDatabaseContentProvider();
- viewer.setContentProvider( provider );
- viewer.setInput( NoDatabaseRoot.ROOT );
- viewer.refresh();
- } else {
- PackagesContentProvider daProvider =
- (PackagesContentProvider)viewer.getContentProvider();
- // Refresh with the items
- viewer.setInput( PackagesRoot.ROOT );
- // Use the new provider
- daProvider.uncache();
- viewer.refresh();
- }
- }
- } );
- }
-
- @Override
- public void selectionChanged( final SelectionChangedEvent event ) {
- TreeSelection selection = ( TreeSelection )event.getSelection();
- Object o = selection.getFirstElement();
- if( o == null || !( o instanceof PackagesItem ) ) {
- doc.setText( "" );
- } else {
- PackagesItem item = ( PackagesItem )o;
- doc.setText( HtmlUtil.generateDocument( null, item.getPackage().getDoc() ) );
- }
- }
-
- @Override
- public void doubleClick( final DoubleClickEvent event ) {
- TreeSelection selection = ( TreeSelection )event.getSelection();
- Object o = selection.getFirstElement();
- if( o == null || !( o instanceof PackagesItem ) ) {
- return;
- }
-
- PackagesItem item = ( PackagesItem )o;
- // Open browser
- try {
- IWorkbenchBrowserSupport browserSupport = this.getSite()
- .getWorkbenchWindow().getWorkbench().getBrowserSupport();
- URL webUrl = new URL( HtmlUtil.generatePackageUrl( item.getPackage().getIdentifier() ) );
- IWebBrowser browser = browserSupport.createBrowser(
- IWorkbenchBrowserSupport.AS_EDITOR
- | IWorkbenchBrowserSupport.LOCATION_BAR, null, "Haskell Browser",
- "Haskell Browser" );
- browser.openURL( webUrl );
- } catch( Throwable ex ) {
- // Do nothing
- }
- }
-
- public boolean has(final String name) {
- PackagesContentProvider pcp=(PackagesContentProvider)viewer.getContentProvider();
- for (PackagesItem[] items : new PackagesItem[][]{ pcp.getLocalCache(), pcp.getHackageCache() }) {
- for (PackagesItem pi : items){
- if (pi.getPackage().getIdentifier().toString().equals( name )){
- return true;
- }
- }
- }
- return false;
- }
-
- public void select(final String name){
- PackagesContentProvider pcp=(PackagesContentProvider)viewer.getContentProvider();
- for (PackagesItem[] items : new PackagesItem[][]{ pcp.getLocalCache(), pcp.getHackageCache() }) {
- for (PackagesItem pi : items){
- if (pi.getPackage().getIdentifier().toString().equals( name )){
- viewer.setSelection( new StructuredSelection(pi) );
- return;
- }
- }
- }
- }
+/**
+ * (c) 2011, Alejandro Serrano
+ * Released under the terms of the EPL.
+ */
+package net.sf.eclipsefp.haskell.browser.views.packages;
+
+import java.net.URL;
+import net.sf.eclipsefp.haskell.browser.BrowserEvent;
+import net.sf.eclipsefp.haskell.browser.BrowserPlugin;
+import net.sf.eclipsefp.haskell.browser.DatabaseLoadedEvent;
+import net.sf.eclipsefp.haskell.browser.IDatabaseLoadedListener;
+import net.sf.eclipsefp.haskell.browser.util.HtmlUtil;
+import net.sf.eclipsefp.haskell.browser.views.NoDatabaseContentProvider;
+import net.sf.eclipsefp.haskell.browser.views.NoDatabaseLabelProvider;
+import net.sf.eclipsefp.haskell.browser.views.NoDatabaseRoot;
+import org.eclipse.jface.viewers.DoubleClickEvent;
+import org.eclipse.jface.viewers.IContentProvider;
+import org.eclipse.jface.viewers.IDoubleClickListener;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.viewers.TreeSelection;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.jface.viewers.ViewerSorter;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.browser.Browser;
+import org.eclipse.swt.custom.SashForm;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.browser.IWebBrowser;
+import org.eclipse.ui.browser.IWorkbenchBrowserSupport;
+import org.eclipse.ui.part.ViewPart;
+
+/**
+ * View part for the 'packages' in the Browser.
+ * @author Alejandro Serrano
+ *
+ */
+public class PackagesView extends ViewPart implements IDatabaseLoadedListener,
+ ISelectionChangedListener, IDoubleClickListener {
+
+ /**
+ * The ID of the view as specified by the extension.
+ */
+ public static final String ID = "net.sf.eclipsefp.haskell.browser.views.packages.PackagesView";
+
+ TreeViewer viewer;
+ Browser doc;
+ IContentProvider provider;
+
+ private String delayedSelect=null;
+
+ @Override
+ public void createPartControl( final Composite parent ) {
+ SashForm form = new SashForm( parent, SWT.VERTICAL );
+ viewer = new TreeViewer( form );
+ doc = new Browser( form, SWT.NONE );
+ doc.setFont( viewer.getControl().getFont() );
+ form.setWeights( new int[] { 75, 25 } );
+
+ // Set database
+ if (BrowserPlugin.getDefault().isAnyDatabaseLoaded()) {
+ databaseLoaded( null );
+ } else {
+ databaseUnloaded( null );
+ }
+ // Hook for listeners
+ BrowserPlugin.getDefault().addDatabaseLoadedListener( this );
+ // Hook for changes in selection
+ viewer.addPostSelectionChangedListener( this );
+ // Hook for double clicking
+ viewer.addDoubleClickListener( this );
+ // Register as selection provider
+ getSite().setSelectionProvider( viewer );
+ }
+
+ @Override
+ public void setFocus() {
+ viewer.getControl().setFocus();
+ }
+
+ @Override
+ public void databaseLoaded( final DatabaseLoadedEvent e ) {
+ Display.getDefault().asyncExec( new Runnable() {
+
+ @Override
+ public void run() {
+ // Set real content provider
+ PackagesContentProvider daProvider = new PackagesContentProvider();
+ provider = daProvider;
+ viewer.setContentProvider( provider );
+ viewer.setLabelProvider( new PackagesLabelProvider() );
+ viewer.setSorter( new PackagesSorter() );
+ // Refresh with the items
+ viewer.setInput( PackagesRoot.ROOT );
+ // Use the new provider
+ daProvider.uncache();
+ viewer.refresh();
+ if (delayedSelect!=null){
+ String sel=delayedSelect;
+ delayedSelect=null;
+ select( sel );
+
+ }
+ }
+ } );
+ }
+
+ @Override
+ public void databaseUnloaded( final BrowserEvent e ) {
+ Display.getDefault().asyncExec( new Runnable() {
+
+ @Override
+ public void run() {
+ delayedSelect=null;
+ if (!BrowserPlugin.getDefault().isAnyDatabaseLoaded()) {
+ // Put the "no database" content and label
+ viewer.setLabelProvider( new NoDatabaseLabelProvider( false ) );
+ viewer.setSorter( new ViewerSorter() );
+ provider = new NoDatabaseContentProvider();
+ viewer.setContentProvider( provider );
+ viewer.setInput( NoDatabaseRoot.ROOT );
+ viewer.refresh();
+ } else {
+ PackagesContentProvider daProvider =
+ (PackagesContentProvider)viewer.getContentProvider();
+ // Refresh with the items
+ viewer.setInput( PackagesRoot.ROOT );
+ // Use the new provider
+ daProvider.uncache();
+ viewer.refresh();
+ }
+ }
+ } );
+ }
+
+ @Override
+ public void selectionChanged( final SelectionChangedEvent event ) {
+ TreeSelection selection = ( TreeSelection )event.getSelection();
+ Object o = selection.getFirstElement();
+ if( o == null || !( o instanceof PackagesItem ) ) {
+ doc.setText( "" );
+ } else {
+ PackagesItem item = ( PackagesItem )o;
+ doc.setText( HtmlUtil.generateDocument( null, item.getPackage().getDoc() ) );
+ }
+ }
+
+ @Override
+ public void doubleClick( final DoubleClickEvent event ) {
+ TreeSelection selection = ( TreeSelection )event.getSelection();
+ Object o = selection.getFirstElement();
+ if( o == null || !( o instanceof PackagesItem ) ) {
+ return;
+ }
+
+ PackagesItem item = ( PackagesItem )o;
+ // Open browser
+ try {
+ IWorkbenchBrowserSupport browserSupport = this.getSite()
+ .getWorkbenchWindow().getWorkbench().getBrowserSupport();
+ URL webUrl = new URL( HtmlUtil.generatePackageUrl( item.getPackage().getIdentifier() ) );
+ IWebBrowser browser = browserSupport.createBrowser(
+ IWorkbenchBrowserSupport.AS_EDITOR
+ | IWorkbenchBrowserSupport.LOCATION_BAR, null, "Haskell Browser",
+ "Haskell Browser" );
+ browser.openURL( webUrl );
+ } catch( Throwable ex ) {
+ // Do nothing
+ }
+ }
+
+ public boolean has(final String name) {
+ PackagesContentProvider pcp=(PackagesContentProvider)viewer.getContentProvider();
+ if (pcp!=null){
+ for (PackagesItem[] items : new PackagesItem[][]{ pcp.getLocalCache(), pcp.getHackageCache() }) {
+ for (PackagesItem pi : items){
+ if (pi.getPackage().getIdentifier().toString().equals( name )){
+ return true;
+ }
+ }
+ }
+ }
+ return false;
+ }
+
+ public void select(final String name){
+ PackagesContentProvider pcp=(PackagesContentProvider)viewer.getContentProvider();
+ if (pcp==null){
+ delayedSelect=name;
+ return;
+ }
+ delayedSelect=null;
+ for (PackagesItem[] items : new PackagesItem[][]{ pcp.getLocalCache(), pcp.getHackageCache() }) {
+ for (PackagesItem pi : items){
+ if (pi.getPackage().getIdentifier().toString().equals( name )){
+ viewer.setSelection( new StructuredSelection(pi) );
+ return;
+ }
+ }
+ }
+ }
}
View
4 net.sf.eclipsefp.haskell.ui/src/net/sf/eclipsefp/haskell/ui/views/CabalPackagesView.java
@@ -402,9 +402,7 @@ public void widgetSelected( final SelectionEvent e ) {
try {
IWorkbenchPage page=getViewSite().getWorkbenchWindow().getWorkbench().showPerspective( BrowserPerspective.class.getName(), getViewSite().getWorkbenchWindow() );
PackagesView view=(PackagesView)page.showView( PackagesView.ID );
- if (view.has( currentNameWithVersion )) {
- view.select(currentNameWithVersion);
- }
+ view.select(currentNameWithVersion);
} catch (Throwable t){
HaskellUIPlugin.log( t );
}
Please sign in to comment.
Something went wrong with that request. Please try again.