PageRenderTime 30ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 1ms

/projects/netbeans-7.3/cnd.makeproject/src/org/netbeans/modules/cnd/makeproject/ui/wizards/SelectBinaryPanelVisual.java

https://gitlab.com/essere.lab.public/qualitas.class-corpus
Java | 1095 lines | 955 code | 73 blank | 67 comment | 209 complexity | badc3c25c439d1302efbca1636e817fe MD5 | raw file
  1. /*
  2. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
  3. *
  4. * Copyright 2010 Oracle and/or its affiliates. All rights reserved.
  5. *
  6. * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
  7. * Other names may be trademarks of their respective owners.
  8. *
  9. * The contents of this file are subject to the terms of either the GNU
  10. * General Public License Version 2 only ("GPL") or the Common
  11. * Development and Distribution License("CDDL") (collectively, the
  12. * "License"). You may not use this file except in compliance with the
  13. * License. You can obtain a copy of the License at
  14. * http://www.netbeans.org/cddl-gplv2.html
  15. * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
  16. * specific language governing permissions and limitations under the
  17. * License. When distributing the software, include this License Header
  18. * Notice in each file and include the License file at
  19. * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
  20. * particular file as subject to the "Classpath" exception as provided
  21. * by Oracle in the GPL Version 2 section of the License file that
  22. * accompanied this code. If applicable, add the following below the
  23. * License Header, with the fields enclosed by brackets [] replaced by
  24. * your own identifying information:
  25. * "Portions Copyrighted [year] [name of copyright owner]"
  26. *
  27. * If you wish your version of this file to be governed by only the CDDL
  28. * or only the GPL Version 2, indicate your decision by adding
  29. * "[Contributor] elects to include this software in this distribution
  30. * under the [CDDL or GPL Version 2] license." If you do not indicate a
  31. * single choice of license, a recipient has the option to distribute
  32. * your version of this file under either the CDDL, the GPL Version 2 or
  33. * to extend the choice of license to its licensees as provided above.
  34. * However, if you add GPL Version 2 code and therefore, elected the GPL
  35. * Version 2 license, then the option applies only if the new code is
  36. * made subject to such option by the copyright holder.
  37. *
  38. * Contributor(s):
  39. *
  40. * Portions Copyrighted 2010 Sun Microsystems, Inc.
  41. */
  42. /*
  43. * SelectBinaryPanelVisual.java
  44. *
  45. * Created on Sep 22, 2010, 12:24:57 PM
  46. */
  47. package org.netbeans.modules.cnd.makeproject.ui.wizards;
  48. import java.awt.BorderLayout;
  49. import java.awt.Color;
  50. import java.awt.Component;
  51. import java.awt.Dimension;
  52. import java.awt.Point;
  53. import java.awt.Rectangle;
  54. import java.awt.event.ActionEvent;
  55. import java.awt.event.ActionListener;
  56. import java.awt.event.InputEvent;
  57. import java.awt.event.ItemEvent;
  58. import java.awt.event.ItemListener;
  59. import java.awt.event.MouseAdapter;
  60. import java.awt.event.MouseEvent;
  61. import java.io.File;
  62. import java.io.IOException;
  63. import java.util.ArrayList;
  64. import java.util.Collections;
  65. import java.util.HashMap;
  66. import java.util.HashSet;
  67. import java.util.List;
  68. import java.util.Map;
  69. import java.util.Set;
  70. import java.util.TreeMap;
  71. import java.util.concurrent.atomic.AtomicBoolean;
  72. import java.util.concurrent.atomic.AtomicInteger;
  73. import java.util.logging.Logger;
  74. import javax.swing.DefaultCellEditor;
  75. import javax.swing.JButton;
  76. import javax.swing.JCheckBox;
  77. import javax.swing.JComponent;
  78. import javax.swing.JFileChooser;
  79. import javax.swing.JLabel;
  80. import javax.swing.JPanel;
  81. import javax.swing.JTable;
  82. import javax.swing.JTextField;
  83. import javax.swing.SwingUtilities;
  84. import javax.swing.UIManager;
  85. import javax.swing.border.Border;
  86. import javax.swing.border.EmptyBorder;
  87. import javax.swing.border.LineBorder;
  88. import javax.swing.event.DocumentEvent;
  89. import javax.swing.filechooser.FileFilter;
  90. import javax.swing.table.DefaultTableModel;
  91. import javax.swing.table.TableCellRenderer;
  92. import javax.swing.table.TableColumnModel;
  93. import org.netbeans.api.progress.ProgressHandle;
  94. import org.netbeans.api.progress.ProgressHandleFactory;
  95. import org.netbeans.modules.cnd.api.toolchain.CompilerSet;
  96. import org.netbeans.modules.cnd.api.toolchain.CompilerSetManager;
  97. import org.netbeans.modules.cnd.makeproject.api.wizards.CommonUtilities;
  98. import org.netbeans.modules.cnd.makeproject.api.wizards.IteratorExtension;
  99. import org.netbeans.modules.cnd.makeproject.api.wizards.WizardConstants;
  100. import org.netbeans.modules.cnd.utils.CndPathUtilitities;
  101. import org.netbeans.modules.cnd.utils.FSPath;
  102. import org.netbeans.modules.cnd.utils.FileFilterFactory;
  103. import org.netbeans.modules.cnd.utils.MIMENames;
  104. import org.netbeans.modules.cnd.utils.cache.CndFileUtils;
  105. import org.netbeans.modules.cnd.utils.ui.DocumentAdapter;
  106. import org.netbeans.modules.cnd.utils.ui.EditableComboBox;
  107. import org.netbeans.modules.cnd.utils.ui.FileChooser;
  108. import org.netbeans.modules.nativeexecution.api.ExecutionEnvironment;
  109. import org.netbeans.modules.nativeexecution.api.ExecutionEnvironmentFactory;
  110. import org.netbeans.modules.remote.spi.FileSystemProvider;
  111. import org.openide.WizardDescriptor;
  112. import org.openide.filesystems.FileObject;
  113. import org.openide.filesystems.FileSystem;
  114. import org.openide.util.Lookup;
  115. import org.openide.util.NbBundle;
  116. import org.openide.util.NbPreferences;
  117. import org.openide.util.RequestProcessor;
  118. /**
  119. *
  120. * @author Alexander Simon
  121. */
  122. public class SelectBinaryPanelVisual extends javax.swing.JPanel {
  123. private final SelectBinaryPanel controller;
  124. private static final RequestProcessor RP = new RequestProcessor("Binary Artifact Discovery", 1); // NOI18N
  125. private final AtomicInteger checking = new AtomicInteger(0);
  126. private static final Logger logger = Logger.getLogger("org.netbeans.modules.cnd.discovery.projectimport.ImportExecutable"); // NOI18N
  127. private DefaultTableModel tableModel;
  128. private static final String BINARY_FILE_KEY = "binaryField"; // NOI18N
  129. private final List<AtomicBoolean> cancelable = new ArrayList<AtomicBoolean>();
  130. private static final class Lock {}
  131. private final Object lock = new Lock();
  132. private final AtomicBoolean searching = new AtomicBoolean(false);
  133. private ExecutionEnvironment env;
  134. private FileSystem fileSystem;
  135. /** Creates new form SelectBinaryPanelVisual */
  136. public SelectBinaryPanelVisual(SelectBinaryPanel controller) {
  137. this.controller = controller;
  138. initComponents();
  139. dependeciesComboBox.removeAllItems();
  140. dependeciesComboBox.addItem(new ProjectKindItem(IteratorExtension.ProjectKind.Minimal));
  141. dependeciesComboBox.addItem(new ProjectKindItem(IteratorExtension.ProjectKind.IncludeDependencies));
  142. dependeciesComboBox.addItem(new ProjectKindItem(IteratorExtension.ProjectKind.CreateDependencies));
  143. dependeciesComboBox.setSelectedIndex(1);
  144. viewComboBox.removeAllItems();
  145. viewComboBox.addItem(new ProjectView(false));
  146. viewComboBox.addItem(new ProjectView(true));
  147. addListeners();
  148. }
  149. private void addListeners(){
  150. ((EditableComboBox)binaryField).addChangeListener(new ActionListener() {
  151. @Override
  152. public void actionPerformed(ActionEvent e) {
  153. String path = ((EditableComboBox)binaryField).getText().trim();
  154. controller.getWizardStorage().setBinaryPath(new FSPath(fileSystem, path));
  155. updateRoot();
  156. }
  157. });
  158. sourcesField.getDocument().addDocumentListener(new DocumentAdapter() {
  159. @Override
  160. protected void update(DocumentEvent e) {
  161. String path = sourcesField.getText().trim();
  162. controller.getWizardStorage().setSourceFolderPath(new FSPath(fileSystem, path));
  163. }
  164. });
  165. table.addMouseListener(new MouseAdapter() {
  166. @Override
  167. public void mouseClicked(MouseEvent e) {
  168. int clickedLine = table.rowAtPoint(e.getPoint());
  169. if (clickedLine != -1) {
  170. if ((e.getModifiers() == InputEvent.BUTTON1_MASK)){
  171. if (e.getClickCount() == 1){
  172. onClickAction(e);
  173. }
  174. }
  175. }
  176. }
  177. });
  178. dependeciesComboBox.addItemListener(new ItemListener() {
  179. @Override
  180. public void itemStateChanged(ItemEvent e) {
  181. validateController();
  182. }
  183. });
  184. updateRoot();
  185. }
  186. private void validateController() {
  187. controller.getWizardStorage().validate();
  188. }
  189. private FileObject findProjectCreator() {
  190. for(CompilerSet set : CompilerSetManager.get(env).getCompilerSets()) {
  191. if (set.getCompilerFlavor().isSunStudioCompiler()) {
  192. String directory = set.getDirectory();
  193. FileObject creator = fileSystem.findResource(directory+"/../lib/ide_project/bin/ide_project");
  194. if (creator != null && creator.isValid()) {
  195. return creator;
  196. }
  197. }
  198. }
  199. return null;
  200. }
  201. private void updateRoot(){
  202. sourcesField.setEnabled(false);
  203. sourcesButton.setEnabled(false);
  204. dependeciesComboBox.setEnabled(false);
  205. viewComboBox.setEnabled(false);
  206. table.setModel(new DefaultTableModel(0, 0));
  207. if (validBinary()) {
  208. if (env.isRemote() && findProjectCreator() == null) {
  209. controller.getWizardDescriptor().putProperty(WizardDescriptor.PROP_ERROR_MESSAGE, getString("ERROR_FIND_PROJECT_CREATOR", env.getDisplayName())); // NOI18N
  210. return;
  211. }
  212. controller.getWizardDescriptor().putProperty(WizardDescriptor.PROP_ERROR_MESSAGE, "");
  213. checking.incrementAndGet();
  214. validateController();
  215. final IteratorExtension extension = Lookup.getDefault().lookup(IteratorExtension.class);
  216. final Map<String, Object> map = new HashMap<String, Object>();
  217. map.put("DW:buildResult", controller.getWizardStorage().getBinaryPath().getPath()); // NOI18N
  218. if (env.isRemote()) {
  219. map.put("DW:fileSystem", fileSystem); // NOI18N
  220. }
  221. if (extension != null) {
  222. RP.post(new Runnable() {
  223. @Override
  224. public void run() {
  225. extension.discoverArtifacts(map);
  226. @SuppressWarnings("unchecked")
  227. List<String> dlls = (List<String>) map.get("DW:dependencies"); // NOI18N
  228. String root = (String) map.get("DW:rootFolder"); // NOI18N
  229. if (root == null) {
  230. root = "";
  231. }
  232. @SuppressWarnings("unchecked")
  233. List<String> searchPaths = (List<String>) map.get("DW:searchPaths"); // NOI18N
  234. final Map<String, String> resolvedDlls = searchingTable(dlls);
  235. updateArtifacts(root, map, resolvedDlls);
  236. checkDll(resolvedDlls, root, searchPaths, controller.getWizardStorage().getBinaryPath());
  237. }
  238. });
  239. }
  240. } else {
  241. String path = ((EditableComboBox)binaryField).getText().trim();
  242. if (!path.isEmpty() && controller.getWizardDescriptor() != null) {
  243. if (CndPathUtilitities.isPathAbsolute(path)) {
  244. FileObject fo = CndFileUtils.toFileObject(CndFileUtils.normalizeAbsolutePath(path));
  245. if (fo == null || !fo.isValid()) {
  246. controller.getWizardDescriptor().putProperty(WizardDescriptor.PROP_ERROR_MESSAGE, getString("SelectBinaryPanelVisual.FileNotFound")); // NOI18N
  247. } else {
  248. controller.getWizardDescriptor().putProperty(WizardDescriptor.PROP_ERROR_MESSAGE, getString("SelectBinaryPanelVisual.Unsupported.Binary")); // NOI18N
  249. }
  250. } else {
  251. controller.getWizardDescriptor().putProperty(WizardDescriptor.PROP_ERROR_MESSAGE, getString("SelectBinaryPanelVisual.FileNotFound")); // NOI18N
  252. }
  253. }
  254. }
  255. }
  256. private void updateArtifacts(final String root, final Map<String, Object> map, final Map<String, String> dlls){
  257. SwingUtilities.invokeLater(new Runnable() {
  258. @Override
  259. public void run() {
  260. if (env.isLocal()) {
  261. CompilerSet compiler = detectCompilerSet((String) map.get("DW:compiler")); // NOI18N
  262. if (compiler != null) {
  263. controller.getWizardDescriptor().putProperty(WizardConstants.PROPERTY_TOOLCHAIN, compiler);
  264. controller.getWizardDescriptor().putProperty(WizardConstants.PROPERTY_HOST_UID, ExecutionEnvironmentFactory.getLocal().getHost());
  265. // allow user to select right tool collection if discovery detected wrong one
  266. controller.getWizardDescriptor().putProperty(WizardConstants.PROPERTY_READ_ONLY_TOOLCHAIN, Boolean.FALSE);
  267. } else {
  268. controller.getWizardDescriptor().putProperty(WizardConstants.PROPERTY_READ_ONLY_TOOLCHAIN, Boolean.FALSE);
  269. }
  270. sourcesField.setText(root);
  271. int i = checking.decrementAndGet();
  272. if (i == 0) {
  273. boolean validBinary = validBinary();
  274. String validBinaryPath = getValidBinaryPath();
  275. sourcesField.setEnabled(validBinary);
  276. sourcesButton.setEnabled(validBinary);
  277. dependeciesComboBox.setEnabled(validBinary);
  278. viewComboBox.setEnabled(validBinary);
  279. if (validBinary && validBinaryPath != null) {
  280. String binaryRoot = CndPathUtilitities.getDirName(validBinaryPath);
  281. if (binaryRoot != null) {
  282. if (binaryRoot.startsWith(root) || root.startsWith(binaryRoot)) {
  283. binaryRoot = null;
  284. }
  285. }
  286. updateTableModel(dlls, root, binaryRoot, true);
  287. } else {
  288. updateTableModel(Collections.<String, String>emptyMap(), root, null, true);
  289. }
  290. }
  291. @SuppressWarnings("unchecked")
  292. List<String> errors = (List<String>) map.get("DW:errors"); // NOI18N
  293. if (errors != null && errors.size() > 0) {
  294. controller.getWizardDescriptor().putProperty(WizardDescriptor.PROP_ERROR_MESSAGE, errors.get(0));
  295. } else {
  296. controller.getWizardDescriptor().putProperty(WizardDescriptor.PROP_ERROR_MESSAGE, "");
  297. }
  298. } else {
  299. sourcesField.setText(root);
  300. int i = checking.decrementAndGet();
  301. if (i == 0) {
  302. boolean validBinary = validBinary();
  303. String validBinaryPath = getValidBinaryPath();
  304. sourcesField.setEnabled(validBinary);
  305. sourcesButton.setEnabled(validBinary);
  306. dependeciesComboBox.setEnabled(false);
  307. viewComboBox.setEnabled(validBinary);
  308. if (validBinary && validBinaryPath != null) {
  309. String binaryRoot = CndPathUtilitities.getDirName(validBinaryPath);
  310. if (binaryRoot != null) {
  311. if (binaryRoot.startsWith(root) || root.startsWith(binaryRoot)) {
  312. binaryRoot = null;
  313. }
  314. }
  315. updateTableModel(dlls, root, binaryRoot, true);
  316. } else {
  317. updateTableModel(Collections.<String, String>emptyMap(), root, null, true);
  318. }
  319. }
  320. controller.getWizardDescriptor().putProperty(WizardDescriptor.PROP_ERROR_MESSAGE, "");
  321. }
  322. validateController();
  323. }
  324. });
  325. }
  326. private void updateDllArtifacts(final String root, final Map<String, String> checkDll, final boolean searching){
  327. SwingUtilities.invokeLater(new Runnable() {
  328. @Override
  329. public void run() {
  330. int i = checking.get();
  331. if (i == 0) {
  332. boolean validBinary = validBinary();
  333. String validBinaryPath = getValidBinaryPath();
  334. if (validBinary && validBinaryPath != null) {
  335. String binaryRoot = CndPathUtilitities.getDirName(validBinaryPath);
  336. if (binaryRoot != null) {
  337. if (binaryRoot.startsWith(root) || root.startsWith(binaryRoot)) {
  338. binaryRoot = null;
  339. }
  340. }
  341. updateTableModel(checkDll, root, binaryRoot, searching);
  342. } else {
  343. updateTableModel(Collections.<String, String>emptyMap(), root, null, searching);
  344. }
  345. }
  346. validateController();
  347. }
  348. });
  349. }
  350. private void updateTableModel(Map<String, String> dlls, String root, String binaryRoot, boolean searching) {
  351. tableModel = new MyDefaultTableModel(this, dlls, root, binaryRoot, searching);
  352. table.setModel(tableModel);
  353. table.getColumnModel().getColumn(0).setPreferredWidth(20);
  354. table.getColumnModel().getColumn(0).setMinWidth(15);
  355. table.getColumnModel().getColumn(0).setCellRenderer(new CheckBoxCellRenderer());
  356. table.getColumnModel().getColumn(0).setCellEditor(new CheckBoxTableCellEditor());
  357. table.getColumnModel().getColumn(1).setPreferredWidth(80);
  358. table.getColumnModel().getColumn(1).setMinWidth(50);
  359. if (table.getWidth() > 200) {
  360. table.getColumnModel().getColumn(2).setPreferredWidth(table.getWidth()-100);
  361. } else {
  362. table.getColumnModel().getColumn(2).setPreferredWidth(100);
  363. }
  364. table.getColumnModel().getColumn(2).setCellRenderer(new PathCellRenderer(fileSystem));
  365. }
  366. private void cancelSearch() {
  367. for(AtomicBoolean cancel : cancelable) {
  368. cancel.set(true);
  369. }
  370. }
  371. private Map<String,String> searchingTable(List<String> dlls) {
  372. Map<String,String> dllPaths = new TreeMap<String, String>();
  373. if (dlls != null) {
  374. for(String dll : dlls) {
  375. dllPaths.put(dll, null);
  376. }
  377. }
  378. return dllPaths;
  379. }
  380. private void checkDll(Map<String, String> dllPaths, String root, List<String> searchPaths, FSPath binary) {
  381. cancelSearch();
  382. if (validBinary()) {
  383. searching.set(true);
  384. validateController();
  385. synchronized (lock) {
  386. final AtomicBoolean cancel = new AtomicBoolean(false);
  387. cancelable.add(cancel);
  388. ActionListener actionListener = new ActionListener(){
  389. @Override
  390. public void actionPerformed(ActionEvent e) {
  391. cancel.set(true);
  392. }
  393. };
  394. cancelSearch.addActionListener(actionListener);
  395. SwingUtilities.invokeLater(new Runnable() {
  396. @Override
  397. public void run() {
  398. cancelSearch.setEnabled(true);
  399. }
  400. });
  401. processDlls(searchPaths, binary, dllPaths, cancel, root);
  402. cancelSearch.removeActionListener(actionListener);
  403. SwingUtilities.invokeLater(new Runnable() {
  404. @Override
  405. public void run() {
  406. cancelSearch.setEnabled(false);
  407. }
  408. });
  409. }
  410. searching.set(false);
  411. validateController();
  412. }
  413. }
  414. private void processDlls(List<String> searchPaths, FSPath binary, Map<String, String> dllPaths, final AtomicBoolean cancel, String root) {
  415. Set<String> checkedDll = new HashSet<String>();
  416. checkedDll.add(binary.getPath());
  417. String ldLibPath = CommonUtilities.getLdLibraryPath(env);
  418. ldLibPath = CommonUtilities.addSearchPaths(ldLibPath, searchPaths, binary.getPath());
  419. for(String dll : dllPaths.keySet()) {
  420. if (cancel.get()) {
  421. break;
  422. }
  423. String p = findLocation(dll, ldLibPath);
  424. if (p != null) {
  425. dllPaths.put(dll, p);
  426. } else {
  427. dllPaths.put(dll, null);
  428. }
  429. }
  430. while(true) {
  431. List<String> secondary = new ArrayList<String>();
  432. for(Map.Entry<String,String> entry : dllPaths.entrySet()) {
  433. if (cancel.get()) {
  434. break;
  435. }
  436. if (entry.getValue() != null) {
  437. if (!checkedDll.contains(entry.getValue())) {
  438. checkedDll.add(entry.getValue());
  439. final IteratorExtension extension = Lookup.getDefault().lookup(IteratorExtension.class);
  440. final Map<String, Object> map = new HashMap<String, Object>();
  441. map.put("DW:buildResult", entry.getValue()); // NOI18N
  442. if (env.isRemote()) {
  443. map.put("DW:fileSystem", fileSystem); // NOI18N
  444. }
  445. if (extension != null) {
  446. extension.discoverArtifacts(map);
  447. @SuppressWarnings("unchecked")
  448. List<String> dlls = (List<String>) map.get("DW:dependencies"); // NOI18N
  449. if (dlls != null) {
  450. for(String so : dlls) {
  451. if (!dllPaths.containsKey(so)) {
  452. secondary.add(so);
  453. }
  454. }
  455. //@SuppressWarnings("unchecked")
  456. //List<String> searchPaths = (List<String>) map.get("DW:searchPaths"); // NOI18N
  457. }
  458. }
  459. }
  460. }
  461. }
  462. for(String so : secondary) {
  463. if (cancel.get()) {
  464. break;
  465. }
  466. dllPaths.put(so, findLocation(so, ldLibPath));
  467. }
  468. int search = 0;
  469. for(Map.Entry<String,String> entry : dllPaths.entrySet()) {
  470. if (entry.getValue() == null) {
  471. search++;
  472. }
  473. }
  474. updateDllArtifacts(root, dllPaths, search > 0);
  475. if (!cancel.get() && search > 0 && root.length() > 1) {
  476. ProgressHandle progress = ProgressHandleFactory.createHandle(getString("SearchForUnresolvedDLL")); //NOI18N
  477. progress.start();
  478. try {
  479. gatherSubFolders(fileSystem.findResource(root), new HashSet<String>(), dllPaths, cancel);
  480. } finally {
  481. progress.finish();
  482. }
  483. updateDllArtifacts(root, dllPaths, false);
  484. }
  485. int newSearch = 0;
  486. for(Map.Entry<String,String> entry : dllPaths.entrySet()) {
  487. if (entry.getValue() == null) {
  488. newSearch++;
  489. }
  490. }
  491. if (newSearch == search && secondary.isEmpty()) {
  492. break;
  493. }
  494. }
  495. }
  496. private void gatherSubFolders(FileObject d, HashSet<String> set, Map<String,String> result, AtomicBoolean cancel){
  497. if (cancel.get()) {
  498. return;
  499. }
  500. if (d != null && d.isFolder() && d.canRead()){
  501. //String path = d.getPath();
  502. String path;
  503. try {
  504. path = FileSystemProvider.getCanonicalPath(d);
  505. } catch (IOException ex) {
  506. return;
  507. }
  508. path = path.replace('\\', '/'); // NOI18N
  509. if (!set.contains(path)){
  510. set.add(path);
  511. FileObject[] ff = d.getChildren();
  512. if (ff != null) {
  513. for (int i = 0; i < ff.length; i++) {
  514. if (cancel.get()) {
  515. return;
  516. }
  517. String ffPath = ff[i].getPath();
  518. if (set.contains(ffPath)){
  519. continue;
  520. }
  521. String name = ff[i].getNameExt();
  522. if (result.containsKey(name)) {
  523. result.put(name, ffPath);
  524. boolean finished = true;
  525. for (Map.Entry<String,String> entry : result.entrySet()) {
  526. if (entry.getValue() == null) {
  527. finished = false;
  528. break;
  529. }
  530. }
  531. if (finished) {
  532. return;
  533. }
  534. }
  535. gatherSubFolders(ff[i], set, result, cancel);
  536. }
  537. }
  538. }
  539. }
  540. }
  541. private String findLocation(String dll, String ldPath){
  542. if (ldPath != null) {
  543. String pathSepararor = ":"; // NOI18N
  544. if (ldPath.indexOf(';')>0) {
  545. pathSepararor = ";"; // NOI18N
  546. }
  547. for(String search : ldPath.split(pathSepararor)) { // NOI18N
  548. FileObject file = fileSystem.findResource(search+"/"+dll);
  549. if (file != null && file.isValid() && file.isData()) {
  550. String path = file.getPath();
  551. return path.replace('\\', '/');
  552. }
  553. }
  554. }
  555. return null;
  556. }
  557. private CompilerSet detectCompilerSet(String compiler){
  558. boolean isSunStudio = true;
  559. if (compiler != null) {
  560. isSunStudio = compiler.indexOf("Sun") >= 0; // NOI18N
  561. }
  562. CompilerSetManager manager = CompilerSetManager.get(ExecutionEnvironmentFactory.getLocal());
  563. if (isSunStudio) {
  564. CompilerSet def = manager.getDefaultCompilerSet();
  565. if (def != null && def.getCompilerFlavor().isSunStudioCompiler()) {
  566. return def;
  567. }
  568. def = null;
  569. for(CompilerSet set : manager.getCompilerSets()) {
  570. if (set.getCompilerFlavor().isSunStudioCompiler()) {
  571. if ("OracleSolarisStudio".equals(set.getName())) { // NOI18N
  572. def = set;
  573. }
  574. if (def == null) {
  575. def = set;
  576. }
  577. }
  578. }
  579. return def;
  580. } else {
  581. CompilerSet def = manager.getDefaultCompilerSet();
  582. if (def != null && !def.getCompilerFlavor().isSunStudioCompiler()) {
  583. return def;
  584. }
  585. def = null;
  586. for(CompilerSet set : manager.getCompilerSets()) {
  587. if (!set.getCompilerFlavor().isSunStudioCompiler()) {
  588. if (def == null) {
  589. def = set;
  590. }
  591. }
  592. }
  593. return def;
  594. }
  595. }
  596. /** This method is called from within the constructor to
  597. * initialize the form.
  598. * WARNING: Do NOT modify this code. The content of this method is
  599. * always regenerated by the Form Editor.
  600. */
  601. @SuppressWarnings("unchecked")
  602. // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
  603. private void initComponents() {
  604. java.awt.GridBagConstraints gridBagConstraints;
  605. binaryLabel = new javax.swing.JLabel();
  606. binaryButton = new javax.swing.JButton();
  607. jSeparator1 = new javax.swing.JSeparator();
  608. sourcesLabel = new javax.swing.JLabel();
  609. sourcesField = new javax.swing.JTextField();
  610. sourcesButton = new javax.swing.JButton();
  611. dependenciesLabel = new javax.swing.JLabel();
  612. dependeciesComboBox = new javax.swing.JComboBox();
  613. jScrollPane1 = new javax.swing.JScrollPane();
  614. table = new javax.swing.JTable();
  615. viewLabel = new javax.swing.JLabel();
  616. viewComboBox = new javax.swing.JComboBox();
  617. binaryField = new EditableComboBox();
  618. cancelSearch = new javax.swing.JButton();
  619. setPreferredSize(new java.awt.Dimension(450, 350));
  620. setLayout(new java.awt.GridBagLayout());
  621. binaryLabel.setLabelFor(binaryField);
  622. org.openide.awt.Mnemonics.setLocalizedText(binaryLabel, org.openide.util.NbBundle.getMessage(SelectBinaryPanelVisual.class, "SelectBinaryPanelVisual.binaryLabel.text")); // NOI18N
  623. gridBagConstraints = new java.awt.GridBagConstraints();
  624. gridBagConstraints.gridx = 0;
  625. gridBagConstraints.gridy = 0;
  626. gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
  627. gridBagConstraints.insets = new java.awt.Insets(6, 6, 0, 6);
  628. add(binaryLabel, gridBagConstraints);
  629. org.openide.awt.Mnemonics.setLocalizedText(binaryButton, org.openide.util.NbBundle.getMessage(SelectBinaryPanelVisual.class, "SelectBinaryPanelVisual.binaryButton.text")); // NOI18N
  630. binaryButton.addActionListener(new java.awt.event.ActionListener() {
  631. public void actionPerformed(java.awt.event.ActionEvent evt) {
  632. binaryButtonActionPerformed(evt);
  633. }
  634. });
  635. gridBagConstraints = new java.awt.GridBagConstraints();
  636. gridBagConstraints.gridx = 2;
  637. gridBagConstraints.gridy = 0;
  638. gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
  639. gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
  640. gridBagConstraints.insets = new java.awt.Insets(6, 6, 0, 6);
  641. add(binaryButton, gridBagConstraints);
  642. gridBagConstraints = new java.awt.GridBagConstraints();
  643. gridBagConstraints.gridx = 0;
  644. gridBagConstraints.gridy = 20;
  645. gridBagConstraints.fill = java.awt.GridBagConstraints.VERTICAL;
  646. add(jSeparator1, gridBagConstraints);
  647. sourcesLabel.setLabelFor(sourcesField);
  648. org.openide.awt.Mnemonics.setLocalizedText(sourcesLabel, org.openide.util.NbBundle.getMessage(SelectBinaryPanelVisual.class, "SelectBinaryPanelVisual.sourcesLabel.text")); // NOI18N
  649. gridBagConstraints = new java.awt.GridBagConstraints();
  650. gridBagConstraints.gridx = 0;
  651. gridBagConstraints.gridy = 1;
  652. gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
  653. gridBagConstraints.insets = new java.awt.Insets(6, 6, 0, 0);
  654. add(sourcesLabel, gridBagConstraints);
  655. sourcesField.setText(org.openide.util.NbBundle.getMessage(SelectBinaryPanelVisual.class, "SelectBinaryPanelVisual.sourcesField.text")); // NOI18N
  656. gridBagConstraints = new java.awt.GridBagConstraints();
  657. gridBagConstraints.gridx = 1;
  658. gridBagConstraints.gridy = 1;
  659. gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
  660. gridBagConstraints.insets = new java.awt.Insets(6, 6, 0, 0);
  661. add(sourcesField, gridBagConstraints);
  662. org.openide.awt.Mnemonics.setLocalizedText(sourcesButton, org.openide.util.NbBundle.getMessage(SelectBinaryPanelVisual.class, "SelectBinaryPanelVisual.sourcesButton.text")); // NOI18N
  663. sourcesButton.addActionListener(new java.awt.event.ActionListener() {
  664. public void actionPerformed(java.awt.event.ActionEvent evt) {
  665. sourcesButtonActionPerformed(evt);
  666. }
  667. });
  668. gridBagConstraints = new java.awt.GridBagConstraints();
  669. gridBagConstraints.gridx = 2;
  670. gridBagConstraints.gridy = 1;
  671. gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
  672. gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
  673. gridBagConstraints.insets = new java.awt.Insets(6, 6, 0, 6);
  674. add(sourcesButton, gridBagConstraints);
  675. dependenciesLabel.setLabelFor(dependeciesComboBox);
  676. org.openide.awt.Mnemonics.setLocalizedText(dependenciesLabel, org.openide.util.NbBundle.getMessage(SelectBinaryPanelVisual.class, "SelectBinaryPanelVisual.dependenciesLabel.text")); // NOI18N
  677. gridBagConstraints = new java.awt.GridBagConstraints();
  678. gridBagConstraints.gridx = 0;
  679. gridBagConstraints.gridy = 3;
  680. gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
  681. gridBagConstraints.insets = new java.awt.Insets(6, 6, 0, 0);
  682. add(dependenciesLabel, gridBagConstraints);
  683. gridBagConstraints = new java.awt.GridBagConstraints();
  684. gridBagConstraints.gridx = 1;
  685. gridBagConstraints.gridy = 3;
  686. gridBagConstraints.gridwidth = 2;
  687. gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
  688. gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
  689. gridBagConstraints.insets = new java.awt.Insets(6, 6, 0, 6);
  690. add(dependeciesComboBox, gridBagConstraints);
  691. jScrollPane1.setPreferredSize(new java.awt.Dimension(300, 200));
  692. table.setModel(new DefaultTableModel());
  693. jScrollPane1.setViewportView(table);
  694. gridBagConstraints = new java.awt.GridBagConstraints();
  695. gridBagConstraints.gridx = 0;
  696. gridBagConstraints.gridy = 6;
  697. gridBagConstraints.gridwidth = 3;
  698. gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
  699. gridBagConstraints.weighty = 1.0;
  700. gridBagConstraints.insets = new java.awt.Insets(6, 6, 6, 6);
  701. add(jScrollPane1, gridBagConstraints);
  702. viewLabel.setLabelFor(viewComboBox);
  703. org.openide.awt.Mnemonics.setLocalizedText(viewLabel, org.openide.util.NbBundle.getMessage(SelectBinaryPanelVisual.class, "SelectBinaryPanelVisual.viewLabel.text")); // NOI18N
  704. gridBagConstraints = new java.awt.GridBagConstraints();
  705. gridBagConstraints.gridx = 0;
  706. gridBagConstraints.gridy = 2;
  707. gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
  708. gridBagConstraints.insets = new java.awt.Insets(6, 6, 0, 0);
  709. add(viewLabel, gridBagConstraints);
  710. gridBagConstraints = new java.awt.GridBagConstraints();
  711. gridBagConstraints.gridx = 1;
  712. gridBagConstraints.gridy = 2;
  713. gridBagConstraints.gridwidth = 2;
  714. gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
  715. gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
  716. gridBagConstraints.insets = new java.awt.Insets(6, 6, 0, 6);
  717. add(viewComboBox, gridBagConstraints);
  718. gridBagConstraints = new java.awt.GridBagConstraints();
  719. gridBagConstraints.gridx = 1;
  720. gridBagConstraints.gridy = 0;
  721. gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
  722. gridBagConstraints.weightx = 1.0;
  723. gridBagConstraints.insets = new java.awt.Insets(6, 6, 0, 0);
  724. add(binaryField, gridBagConstraints);
  725. org.openide.awt.Mnemonics.setLocalizedText(cancelSearch, org.openide.util.NbBundle.getMessage(SelectBinaryPanelVisual.class, "SelectBinaryPanelVisual.cancelSearch.text")); // NOI18N
  726. cancelSearch.setEnabled(false);
  727. gridBagConstraints = new java.awt.GridBagConstraints();
  728. gridBagConstraints.gridx = 0;
  729. gridBagConstraints.gridy = 7;
  730. gridBagConstraints.gridwidth = 3;
  731. gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
  732. gridBagConstraints.insets = new java.awt.Insets(0, 6, 0, 6);
  733. add(cancelSearch, gridBagConstraints);
  734. }// </editor-fold>//GEN-END:initComponents
  735. private void binaryButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_binaryButtonActionPerformed
  736. String path = selectBinaryFile(((EditableComboBox)binaryField).getText());
  737. if (path == null) {
  738. return;
  739. }
  740. ((EditableComboBox)binaryField).setText(path);
  741. }//GEN-LAST:event_binaryButtonActionPerformed
  742. private void sourcesButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sourcesButtonActionPerformed
  743. String seed = sourcesField.getText();
  744. JFileChooser fileChooser;
  745. fileChooser = new FileChooser(
  746. getString("SelectBinaryPanelVisual.Source.Browse.Title"), // NOI18N
  747. getString("SelectBinaryPanelVisual.Source.Browse.Select"), // NOI18N
  748. JFileChooser.DIRECTORIES_ONLY,
  749. null,
  750. seed,
  751. false);
  752. int ret = fileChooser.showOpenDialog(this);
  753. if (ret == JFileChooser.CANCEL_OPTION) {
  754. return;
  755. }
  756. File selectedFile = fileChooser.getSelectedFile();
  757. if (selectedFile != null) { // seems paranoidal, but once I've seen NPE otherwise 8-()
  758. String path = selectedFile.getPath();
  759. sourcesField.setText(path);
  760. }
  761. }//GEN-LAST:event_sourcesButtonActionPerformed
  762. void read(WizardDescriptor wizardDescriptor) {
  763. env = (ExecutionEnvironment) wizardDescriptor.getProperty(WizardConstants.PROPERTY_REMOTE_FILE_SYSTEM_ENV);
  764. if (env == null) {
  765. env = ExecutionEnvironmentFactory.getLocal();
  766. } else {
  767. wizardDescriptor.putProperty(WizardConstants.PROPERTY_HOST_UID, ExecutionEnvironmentFactory.toUniqueID(env));
  768. }
  769. fileSystem = FileSystemProvider.getFileSystem(env);
  770. ((EditableComboBox)binaryField).setStorage(BINARY_FILE_KEY, NbPreferences.forModule(SelectBinaryPanelVisual.class));
  771. String binary = (String)wizardDescriptor.getProperty(WizardConstants.PROPERTY_BUILD_RESULT);
  772. if (binary == null) {
  773. binary = ""; // NOI18N
  774. }
  775. ((EditableComboBox)binaryField).read(binary);
  776. }
  777. void store(WizardDescriptor wizardDescriptor) {
  778. cancelSearch();
  779. wizardDescriptor.putProperty(WizardConstants.PROPERTY_BUILD_RESULT, ((EditableComboBox)binaryField).getText().trim());
  780. wizardDescriptor.putProperty(WizardConstants.PROPERTY_PREFERED_PROJECT_NAME, new File(((EditableComboBox)binaryField).getText().trim()).getName());
  781. wizardDescriptor.putProperty(WizardConstants.PROPERTY_SOURCE_FOLDER_PATH, sourcesField.getText().trim());
  782. wizardDescriptor.putProperty(WizardConstants.PROPERTY_DEPENDENCY_KIND, ((ProjectKindItem)dependeciesComboBox.getSelectedItem()).kind);
  783. wizardDescriptor.putProperty(WizardConstants.PROPERTY_DEPENDENCIES, getDlls());
  784. wizardDescriptor.putProperty(WizardConstants.PROPERTY_TRUE_SOURCE_ROOT, ((ProjectView)viewComboBox.getSelectedItem()).isSourceRoot);
  785. ((EditableComboBox)binaryField).setStorage(BINARY_FILE_KEY, NbPreferences.forModule(SelectBinaryPanelVisual.class));
  786. ((EditableComboBox)binaryField).store();
  787. if (wizardDescriptor.getProperty(WizardConstants.PROPERTY_REMOTE_FILE_SYSTEM_ENV) != null) {
  788. // forbid tool collection selection
  789. // project creator detect real tool collection
  790. wizardDescriptor.putProperty(WizardConstants.PROPERTY_READ_ONLY_TOOLCHAIN, Boolean.TRUE);
  791. }
  792. // TODO should be inited
  793. wizardDescriptor.putProperty(WizardConstants.PROPERTY_USER_MAKEFILE_PATH, ""); // NOI18N
  794. }
  795. private ArrayList<String> getDlls(){
  796. ArrayList<String> dlls = new ArrayList<String>();
  797. if (((ProjectKindItem)dependeciesComboBox.getSelectedItem()).kind == IteratorExtension.ProjectKind.Minimal) {
  798. return dlls;
  799. }
  800. for(int i = 0; i < table.getModel().getRowCount(); i++) {
  801. if ((Boolean)table.getModel().getValueAt(i, 0)){
  802. dlls.add((String)table.getModel().getValueAt(i, 2));
  803. }
  804. }
  805. return dlls;
  806. }
  807. boolean valid() {
  808. return !searching.get() && checking.get()==0 && validBinary() && validSourceRoot() && validDlls();
  809. }
  810. private String getValidBinaryPath() {
  811. String path = ((EditableComboBox) binaryField).getText().trim();
  812. if (path.isEmpty()) {
  813. return null;
  814. }
  815. if (CndPathUtilitities.isPathAbsolute(path)) {
  816. return CndFileUtils.normalizeAbsolutePath(fileSystem, path);
  817. } else {
  818. return null;
  819. }
  820. }
  821. private boolean validBinary() {
  822. String validBinaryPath = getValidBinaryPath();
  823. if (validBinaryPath != null) {
  824. FileObject fo = fileSystem.findResource(validBinaryPath); // can be null
  825. if (fo != null && fo.isValid()) {
  826. return MIMENames.isBinary(fo.getMIMEType());
  827. }
  828. }
  829. return false;
  830. }
  831. private boolean validSourceRoot() {
  832. String path = sourcesField.getText().trim();
  833. if (path.isEmpty()) {
  834. return false;
  835. }
  836. if (CndPathUtilitities.isPathAbsolute(path)) {
  837. FileObject fo = fileSystem.findResource(CndFileUtils.normalizeAbsolutePath(path));
  838. if (fo == null || !fo.isValid()) {
  839. return false;
  840. }
  841. return fo.isFolder();
  842. } else {
  843. return false;
  844. }
  845. }
  846. private boolean validDlls() {
  847. for(String dll : getDlls()) {
  848. FileObject fo = fileSystem.findResource(dll);
  849. if(fo == null || !fo.isValid()) {
  850. return false;
  851. }
  852. }
  853. return true;
  854. }
  855. private void onClickAction(MouseEvent e) {
  856. int rowIndex = table.rowAtPoint(e.getPoint());
  857. if (rowIndex >= 0) {
  858. TableColumnModel columnModel = table.getColumnModel();
  859. int viewColumn = columnModel.getColumnIndexAtX(e.getX());
  860. int col = table.convertColumnIndexToModel(viewColumn);
  861. if (col == 2){
  862. Rectangle rect = table.getCellRect(rowIndex, viewColumn, false);
  863. Point point = new Point(e.getPoint().x - rect.x, e.getPoint().y - rect.y);
  864. //System.err.println("Action for row "+rowIndex+" rect "+rect+" point "+point);
  865. if (rect.width - BUTTON_WIDTH <= point.x && point.x <= rect.width ) {
  866. tableButtonActionPerformed(rowIndex);
  867. }
  868. }
  869. }
  870. }
  871. private String selectBinaryFile(String path) {
  872. FileFilter[] filters = FileFilterFactory.getBinaryFilters();
  873. JFileChooser fileChooser = NewProjectWizardUtils.createFileChooser(
  874. controller.getWizardDescriptor(),
  875. getString("SelectBinaryPanelVisual.Browse.Title"), // NOI18N
  876. getString("SelectBinaryPanelVisual.Browse.Select"), // NOI18N
  877. JFileChooser.FILES_ONLY,
  878. filters,
  879. path,
  880. false
  881. );
  882. int ret = fileChooser.showOpenDialog(this);
  883. if (ret == JFileChooser.CANCEL_OPTION) {
  884. return null;
  885. }
  886. return fileChooser.getSelectedFile().getPath();
  887. }
  888. private void tableButtonActionPerformed(int row) {
  889. String path = selectBinaryFile((String) table.getModel().getValueAt(row, 2));
  890. if (path == null) {
  891. return;
  892. }
  893. table.getModel().setValueAt(path, row, 2);
  894. }
  895. private static String getString(String key) {
  896. return NbBundle.getMessage(SelectBinaryPanelVisual.class, key);
  897. }
  898. private static String getString(String key, String arg) {
  899. return NbBundle.getMessage(SelectBinaryPanelVisual.class, key, arg);
  900. }
  901. // Variables declaration - do not modify//GEN-BEGIN:variables
  902. private javax.swing.JButton binaryButton;
  903. private javax.swing.JComboBox binaryField;
  904. private javax.swing.JLabel binaryLabel;
  905. private javax.swing.JButton cancelSearch;
  906. private javax.swing.JComboBox dependeciesComboBox;
  907. private javax.swing.JLabel dependenciesLabel;
  908. private javax.swing.JScrollPane jScrollPane1;
  909. private javax.swing.JSeparator jSeparator1;
  910. private javax.swing.JButton sourcesButton;
  911. private javax.swing.JTextField sourcesField;
  912. private javax.swing.JLabel sourcesLabel;
  913. private javax.swing.JTable table;
  914. private javax.swing.JComboBox viewComboBox;
  915. private javax.swing.JLabel viewLabel;
  916. // End of variables declaration//GEN-END:variables
  917. private static final class ProjectKindItem {
  918. private final IteratorExtension.ProjectKind kind;
  919. ProjectKindItem(IteratorExtension.ProjectKind kind) {
  920. this.kind = kind;
  921. }
  922. @Override
  923. public String toString() {
  924. return getString("ProjectItemKind_"+kind);
  925. }
  926. }
  927. private static final class ProjectView {
  928. private boolean isSourceRoot;
  929. ProjectView(boolean isSourceRoot) {
  930. this.isSourceRoot = isSourceRoot;
  931. }
  932. @Override
  933. public String toString() {
  934. if (isSourceRoot) {
  935. return getString("ProjectViewSource");
  936. } else {
  937. return getString("ProjectViewLogical");
  938. }
  939. }
  940. }
  941. private static final class CheckBoxCellRenderer extends JCheckBox implements TableCellRenderer {
  942. private static final Border noFocusBorder = new EmptyBorder(1, 1, 1, 1);
  943. private final JLabel emptyLabel = new JLabel();
  944. public CheckBoxCellRenderer() {
  945. super();
  946. setHorizontalAlignment(JLabel.CENTER);
  947. setBorderPainted(true);
  948. emptyLabel.setBorder(noFocusBorder);
  949. emptyLabel.setOpaque(true);
  950. }
  951. @Override
  952. public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
  953. JComponent result;
  954. if (value == null) {
  955. result = emptyLabel;
  956. } else {
  957. setSelected(((Boolean)value).booleanValue());
  958. setEnabled(table.getModel().isCellEditable(row, column));
  959. result = this;
  960. }
  961. result.setForeground(isSelected ? table.getSelectionForeground() : table.getForeground());
  962. result.setBackground(isSelected ? table.getSelectionBackground() : table.getBackground());
  963. result.setBorder(hasFocus ? UIManager.getBorder("Table.focusCellHighlightBorder") : noFocusBorder); // NOI18N
  964. return result;
  965. }
  966. }
  967. private static final int BUTTON_WIDTH = 20;
  968. private static final class PathCellRenderer extends JPanel implements TableCellRenderer {
  969. private static final Border noFocusBorder = new EmptyBorder(1, 1, 1, 1);
  970. private static final Border noFocusButtonBorder = new LineBorder(Color.GRAY, 1);
  971. private final JTextField field = new JTextField();
  972. private final JButton button = new JButton("..."); // NOI18N
  973. private final Color textFieldColor;
  974. private final Color redTextFieldColor;
  975. private final FileSystem fileSystem;
  976. public PathCellRenderer(FileSystem fileSystem) {
  977. super();
  978. setLayout(new BorderLayout());
  979. add(field, BorderLayout.CENTER);
  980. field.setBorder(noFocusBorder);
  981. textFieldColor = field.getForeground();
  982. redTextFieldColor = new Color(field.getBackground().getRed(), textFieldColor.getGreen(), textFieldColor.getBlue());
  983. add(button, BorderLayout.EAST);
  984. button.setPreferredSize(new Dimension(BUTTON_WIDTH,5));
  985. button.setMaximumSize(new Dimension(BUTTON_WIDTH,20));
  986. button.setBorder(noFocusButtonBorder);
  987. this.fileSystem = fileSystem;
  988. }
  989. @Override
  990. public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, final int row, final int column) {
  991. field.setText(value.toString());
  992. if (table.getModel().isCellEditable(row, column)) {
  993. field.setEnabled(true);
  994. button.setEnabled(true);
  995. } else {
  996. field.setEnabled(false);
  997. button.setEnabled(false);
  998. }
  999. FileObject dll = fileSystem.findResource(value.toString());
  1000. if (dll != null && dll.isValid()) {
  1001. field.setForeground(textFieldColor);
  1002. } else {
  1003. field.setForeground(redTextFieldColor);
  1004. }
  1005. setForeground(isSelected ? table.getSelectionForeground() : table.getForeground());
  1006. setBackground(isSelected ? table.getSelectionBackground() : table.getBackground());
  1007. setBorder(hasFocus ? UIManager.getBorder("Table.focusCellHighlightBorder") : noFocusBorder); // NOI18N
  1008. return this;
  1009. }
  1010. }
  1011. private static final class CheckBoxTableCellEditor extends DefaultCellEditor {
  1012. private CheckBoxTableCellEditor() {
  1013. super(new JCheckBox());
  1014. ((JCheckBox)getEditorComponent()).setHorizontalAlignment(JLabel.CENTER);
  1015. ((JCheckBox)getEditorComponent()).setBorderPainted(true);
  1016. }
  1017. public final JComponent getEditorComponent() {
  1018. return editorComponent;
  1019. }
  1020. @Override
  1021. public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
  1022. return super.getTableCellEditorComponent(table, value, isS