1 19 20 package org.netbeans.modules.project.ui; 21 22 import java.awt.EventQueue ; 23 import java.beans.PropertyChangeEvent ; 24 import java.beans.PropertyChangeListener ; 25 import java.lang.reflect.Method ; 26 import java.text.MessageFormat ; 27 import java.util.HashSet ; 28 import java.util.Set ; 29 import org.netbeans.api.project.FileOwnerQuery; 30 import org.netbeans.api.project.Project; 31 import org.netbeans.api.project.ProjectUtils; 32 import org.openide.filesystems.FileObject; 33 import org.openide.loaders.DataObject; 34 import org.openide.loaders.TemplateWizard; 35 import org.openide.nodes.Node; 36 import org.openide.util.Lookup; 37 import org.openide.util.NbBundle; 38 import org.openide.util.RequestProcessor; 39 import org.openide.windows.TopComponent; 40 import org.openide.windows.WindowManager; 41 42 45 public class Hacks { 46 47 private static final String BUILD_NUMBER = System.getProperty("netbeans.buildnumber"); 49 53 static void keepCurrentProjectNameUpdated() { 54 final TopComponent.Registry r = TopComponent.getRegistry(); 55 final RequestProcessor.Task task = RequestProcessor.getDefault().create(new Runnable () { 56 public void run() { 57 Node[] sel = r.getActivatedNodes(); 58 Set <Project> projects = new HashSet <Project>(); 59 for (int i = 0; i < sel.length; i++) { 60 Lookup l = sel[i].getLookup(); 61 Project p = l.lookup(Project.class); 62 if (p != null) { 63 projects.add(p); 64 } else { 65 DataObject d = l.lookup(DataObject.class); 66 if (d != null) { 67 FileObject f = d.getPrimaryFile(); 68 p = FileOwnerQuery.getOwner(f); 69 if (p != null) { 70 projects.add(p); 71 } 72 } 73 } 74 } 75 final String pname; 76 if (projects.size() == 1) { 77 Project p = projects.iterator().next(); 78 pname = ProjectUtils.getInformation(p).getDisplayName(); 79 assert pname != null : p; 80 } else if (projects.isEmpty()) { 81 pname = null; 82 } else { 83 pname = NbBundle.getMessage(Hacks.class, "LBL_MultipleProjects"); 84 } 85 Project p = OpenProjectList.getDefault().getMainProject(); 86 final String mname = p != null? 87 ProjectUtils.getInformation(p).getDisplayName(): 88 NbBundle.getMessage(Hacks.class, "LBL_NoMainProject"); 89 EventQueue.invokeLater(new Runnable () { 90 public void run() { 91 String format = NbBundle.getBundle("org.netbeans.core.windows.view.ui.Bundle"). 93 getString(pname != null ? "CTL_MainWindow_Title" : "CTL_MainWindow_Title_No_Project"); 94 String title = pname != null? 95 MessageFormat.format(format, BUILD_NUMBER, pname, mname) : 97 MessageFormat.format(format, BUILD_NUMBER, mname); 98 WindowManager.getDefault().getMainWindow().setTitle(title); 99 } 100 }); 101 } 102 }); 103 r.addPropertyChangeListener(new PropertyChangeListener () { 104 public void propertyChange(PropertyChangeEvent ev) { 105 if (TopComponent.Registry.PROP_ACTIVATED_NODES.equals(ev.getPropertyName())) { 106 task.schedule(200); 107 } 108 } 109 }); 110 } 111 112 113 121 static void reloadPanelsInWizard (final TemplateWizard tw, final DataObject dobj) { 122 try { 123 Class <?> twClazz = Class.forName( 124 "org.openide.loaders.TemplateWizard", true, Thread.currentThread().getContextClassLoader()); 126 if (twClazz != null) { 127 Method reloadPanels = twClazz.getDeclaredMethod("reload", DataObject.class); reloadPanels.setAccessible (true); 129 reloadPanels.invoke(tw, dobj); 130 } 131 } catch (Exception e) { 132 e.printStackTrace(); 134 } 135 } 136 } 137 | Popular Tags |