Opens an xml or data file specified by name. @param fileName the file name
(File file)
| 686 | * @param fileName the file name |
| 687 | */ |
| 688 | public void open(File file) { |
| 689 | // @return the file name, if successfully opened (datasets loaded) |
| 690 | // BH 2020.02.13 return was string; |
| 691 | OSPLog.fine("opening " + file); //$NON-NLS-1$ |
| 692 | Resource res = new Resource(file); |
| 693 | Reader in = res.openReader(); |
| 694 | String firstLine = readFirstLine(in); |
| 695 | // if xml, read the file into an XML control and add tab |
| 696 | if (firstLine.startsWith("<?xml")) { //$NON-NLS-1$ |
| 697 | XMLControlElement control = new XMLControlElement(file); |
| 698 | addTabs(control, new Consumer<ArrayList<DataToolTab>>() { |
| 699 | |
| 700 | @Override |
| 701 | public void accept(ArrayList<DataToolTab> tabs) { |
| 702 | if (tabs.isEmpty()) { |
| 703 | OSPLog.finest("no data found"); //$NON-NLS-1$ |
| 704 | } else { |
| 705 | for (DataToolTab tab : tabs) { |
| 706 | refreshDataBuilder(); |
| 707 | if (tabs.size() == 1) { |
| 708 | tab.fileName = file.toString(); |
| 709 | } |
| 710 | tab.tabChanged(false); |
| 711 | } |
| 712 | try { |
| 713 | in.close(); |
| 714 | } catch (IOException e) { |
| 715 | // e.printStackTrace(); |
| 716 | } |
| 717 | } |
| 718 | } |
| 719 | |
| 720 | }); |
| 721 | return; |
| 722 | } |
| 723 | if (res.getString() != null) { |
| 724 | // if not xml, attempt to import data and add tab(s) |
| 725 | setMultipleTabPolicy(res.getString()); |
| 726 | Data[] data = parseData(res.getString(), file.toString()); |
| 727 | if (data != null) { |
| 728 | DataToolTab first = null; |
| 729 | for (int i = 0; i < data.length; i++) { |
| 730 | DataToolTab tab = createTab(data[i]); |
| 731 | first = first == null? tab: first; |
| 732 | addTab(tab); |
| 733 | if (data.length == 1) |
| 734 | tab.fileName = file.getAbsolutePath(); |
| 735 | tab.tabChanged(false); |
| 736 | } |
| 737 | setSelectedTab(first); |
| 738 | refreshDataBuilder(); |
| 739 | return; |
| 740 | } |
| 741 | } |
| 742 | OSPLog.finest("no data found"); //$NON-NLS-1$ |
| 743 | } |
| 744 | |
| 745 | /** |
no test coverage detected