1 19 20 package org.netbeans.spi.java.project.support.ui; 21 22 import java.awt.Dialog ; 23 import java.awt.Frame ; 24 import java.awt.event.WindowAdapter ; 25 import java.io.IOException ; 26 import javax.swing.JButton ; 27 import javax.swing.SwingUtilities ; 28 import org.netbeans.api.project.Project; 29 import org.netbeans.api.project.ProjectManager; 30 import org.netbeans.api.project.ProjectUtils; 31 import org.netbeans.modules.java.project.BrokenReferencesAlertPanel; 32 import org.netbeans.modules.java.project.BrokenReferencesCustomizer; 33 import org.netbeans.modules.java.project.BrokenReferencesModel; 34 import org.netbeans.modules.java.project.JavaProjectSettings; 35 import org.netbeans.spi.project.support.ant.AntProjectHelper; 36 import org.netbeans.spi.project.support.ant.ReferenceHelper; 37 import org.openide.DialogDescriptor; 38 import org.openide.DialogDisplayer; 39 import org.openide.ErrorManager; 40 import org.openide.util.NbBundle; 41 import org.openide.windows.WindowManager; 42 43 57 public class BrokenReferencesSupport { 58 59 60 private static long brokenAlertLastTime = 0; 61 62 63 private static boolean brokenAlertShown = false; 64 65 66 private static int BROKEN_ALERT_TIMEOUT = 1000; 67 68 private BrokenReferencesSupport() {} 69 70 86 public static boolean isBroken(AntProjectHelper projectHelper, 87 ReferenceHelper referenceHelper, String [] properties, String [] platformProperties) { 88 return BrokenReferencesModel.isBroken(projectHelper, 89 projectHelper.getStandardPropertyEvaluator(), properties, platformProperties); 90 } 91 92 106 public static void showCustomizer(AntProjectHelper projectHelper, 107 ReferenceHelper referenceHelper, String [] properties, String [] platformProperties) { 108 BrokenReferencesModel model = new BrokenReferencesModel(projectHelper, referenceHelper, properties, platformProperties); 109 BrokenReferencesCustomizer customizer = new BrokenReferencesCustomizer(model); 110 JButton close = new JButton (NbBundle.getMessage(BrokenReferencesCustomizer.class,"LBL_BrokenLinksCustomizer_Close")); close.getAccessibleContext ().setAccessibleDescription (NbBundle.getMessage(BrokenReferencesCustomizer.class,"ACSD_BrokenLinksCustomizer_Close")); String projectDisplayName = "???"; try { 114 Project project = ProjectManager.getDefault().findProject(projectHelper.getProjectDirectory()); 115 if (project != null) { 116 projectDisplayName = ProjectUtils.getInformation(project).getDisplayName(); 117 } 118 } catch (IOException e) { 119 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e); 120 } 121 DialogDescriptor dd = new DialogDescriptor(customizer, 122 NbBundle.getMessage(BrokenReferencesCustomizer.class, 123 "LBL_BrokenLinksCustomizer_Title", projectDisplayName), true, new Object [] {close}, close, DialogDescriptor.DEFAULT_ALIGN, null, null); 125 Dialog dlg = null; 126 try { 127 dlg = DialogDisplayer.getDefault().createDialog(dd); 128 dlg.setVisible(true); 129 } finally { 130 if (dlg != null) 131 dlg.dispose(); 132 } 133 } 134 135 142 public static synchronized void showAlert() { 143 if (brokenAlertShown || 146 brokenAlertLastTime+BROKEN_ALERT_TIMEOUT > System.currentTimeMillis() || 147 !JavaProjectSettings.isShowAgainBrokenRefAlert()) { 148 return; 149 } 150 brokenAlertShown = true; 151 final Runnable task = new Runnable () { 152 public void run() { 153 try { 154 JButton closeOption = new JButton (NbBundle.getMessage(BrokenReferencesAlertPanel.class, "CTL_Broken_References_Close")); 155 closeOption.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(BrokenReferencesAlertPanel.class, "AD_Broken_References_Close")); 156 DialogDescriptor dd = new DialogDescriptor(new BrokenReferencesAlertPanel(), 157 NbBundle.getMessage(BrokenReferencesAlertPanel.class, "MSG_Broken_References_Title"), 158 true, 159 new Object [] {closeOption}, 160 closeOption, 161 DialogDescriptor.DEFAULT_ALIGN, 162 null, 163 null); dd.setMessageType(DialogDescriptor.WARNING_MESSAGE); 165 Dialog dlg = DialogDisplayer.getDefault().createDialog(dd); 166 dlg.setVisible(true); 167 } finally { 168 synchronized (BrokenReferencesSupport.class) { 169 brokenAlertLastTime = System.currentTimeMillis(); 170 brokenAlertShown = false; 171 } 172 } 173 } 174 }; 175 SwingUtilities.invokeLater(new Runnable () { 176 public void run () { 177 Frame f = WindowManager.getDefault().getMainWindow(); 178 if (f == null || f.isShowing()) { 179 task.run(); 180 } 181 else { 182 new MainWindowListener (f,task); 183 } 184 } 185 }); 186 } 187 188 189 private static class MainWindowListener extends WindowAdapter { 190 191 private Frame frame; 192 private Runnable task; 193 194 198 public MainWindowListener (Frame frame, Runnable task) { 199 assert frame != null && task != null; 200 assert SwingUtilities.isEventDispatchThread(); 201 this.frame = frame; 202 this.task = task; 203 frame.addWindowListener(this); 204 } 205 206 public void windowOpened(java.awt.event.WindowEvent e) { 207 MainWindowListener.this.frame.removeWindowListener (this); 208 SwingUtilities.invokeLater(this.task); 209 } 210 } 211 212 213 } 214 | Popular Tags |