/** * Add item to the model. * * <p>If the item has no color, this will define its color based on the model's next available * color. * * <p>If the model is already 'running', the item will be 'start'ed. * * @param item {@link ModelItem} to add * @throws RuntimeException if item is already in model * @throws Exception on error trying to start a PV Item that's added to a running model */ public void addItem(final ModelItem item) throws Exception { // A new item with the same PV name are allowed to be added in the // model. This way Data Browser can show the trend of the same PV // in different axes or with different waveform indexes. For example, // one may want to show the first element of epics://aaa:bbb in axis 1 // while showing the third element of the same PV in axis 2 to compare // their trends in one chart. // // if (getItem(item.getName()) != null) // throw new RuntimeException("Item " + item.getName() + " already in Model"); // But, if exactly the same instance of the given ModelItem already exists in this // model, it will not be added. if (items.indexOf(item) != -1) throw new RuntimeException("Item " + item.getName() + " already in Model"); // Assign default color if (item.getColor() == null) item.setColor(getNextItemColor()); // Force item to be on an axis if (item.getAxis() == null) { if (axes.size() == 0) addAxis(item.getDisplayName()); item.setAxis(axes.get(0)); } // Check item axis if (!axes.contains(item.getAxis())) throw new Exception("Item " + item.getName() + " added with invalid axis " + item.getAxis()); // Add to model items.add(item); item.setModel(this); if (is_running && item instanceof PVItem) ((PVItem) item).start(scanner); // Notify listeners of new item for (ModelListener listener : listeners) listener.itemAdded(item); }
/** * Remove item from the model. * * <p>If the model and thus item are 'running', the item will be 'stopped'. * * @param item * @throws RuntimeException if item is already in model */ public void removeItem(final ModelItem item) { if (is_running && item instanceof PVItem) { final PVItem pv = (PVItem) item; pv.stop(); // Delete its samples: // For one, so save memory. // Also, in case item is later added back in, its old samples // will have gaps because the item was stopped pv.getSamples().clear(); } if (!items.remove(item)) throw new RuntimeException("Unknown item " + item.getName()); // Detach item from model item.setModel(null); // Notify listeners of removed item for (ModelListener listener : listeners) listener.itemRemoved(item); // Remove axis if unused AxisConfig axis = item.getAxis(); item.setAxis(null); if (countActiveItemsOnAxis(axis) == 0) { removeAxis(axis); fireAxisChangedEvent(null); } }
/** * Write XML formatted Model content. * * @param out OutputStream, will be closed when done. */ public void write(final OutputStream out) { final PrintWriter writer = new PrintWriter(out); XMLWriter.header(writer); XMLWriter.start(writer, 0, TAG_DATABROWSER); writer.println(); // L.PHILIPPE // Save config graph settings XYGraphSettingsXMLUtil XYGraphMemXML = new XYGraphSettingsXMLUtil(graphSettings); XYGraphMemXML.write(writer); // Time axis XMLWriter.XML(writer, 1, TAG_SCROLL, isScrollEnabled()); XMLWriter.XML(writer, 1, TAG_UPDATE_PERIOD, getUpdatePeriod()); if (isScrollEnabled()) { XMLWriter.XML(writer, 1, TAG_START, new RelativeTime(-getTimespan())); XMLWriter.XML(writer, 1, TAG_END, RelativeTime.NOW); } else { XMLWriter.XML(writer, 1, TAG_START, getStartTime()); XMLWriter.XML(writer, 1, TAG_END, getEndTime()); } // Time axis config if (timeAxis != null) { XMLWriter.start(writer, 1, TAG_TIME_AXIS); writer.println(); timeAxis.write(writer); XMLWriter.end(writer, 1, TAG_TIME_AXIS); writer.println(); } // Misc. writeColor(writer, 1, TAG_BACKGROUND, background); XMLWriter.XML(writer, 1, TAG_ARCHIVE_RESCALE, archive_rescale.name()); // Value axes XMLWriter.start(writer, 1, TAG_AXES); writer.println(); for (AxisConfig axis : axes) axis.write(writer); XMLWriter.end(writer, 1, TAG_AXES); writer.println(); // Annotations XMLWriter.start(writer, 1, TAG_ANNOTATIONS); writer.println(); for (AnnotationInfo annotation : annotations) annotation.write(writer); XMLWriter.end(writer, 1, TAG_ANNOTATIONS); writer.println(); // PVs (Formulas) XMLWriter.start(writer, 1, TAG_PVLIST); writer.println(); for (ModelItem item : items) item.write(writer); XMLWriter.end(writer, 1, TAG_PVLIST); writer.println(); XMLWriter.end(writer, 0, TAG_DATABROWSER); writer.close(); }
/** * @param axis Axis to remove * @throws Error when axis not in model, or axis in use by model item */ public void removeAxis(final AxisConfig axis) { if (!axes.contains(axis)) throw new Error("Unknown AxisConfig"); for (ModelItem item : items) if (item.getAxis() == axis) throw new Error("Cannot removed AxisConfig while in use"); axis.setModel(null); axes.remove(axis); fireAxisChangedEvent(null); }
private ModelItem getItem(Element ele) { int x = getIntValue(ele, "x"); int y = getIntValue(ele, "y"); ModelItem item = new ModelItem(); item.setPosition(new Point(x, y)); item.setId(getIntValue(ele, "id")); item.setType(getIntValue(ele, "type")); return item; }
/** * Test if any ModelItems received new samples, if formulas need to be re-computed, since the last * time this method was called. * * @return <code>true</code> if there were new samples */ public boolean updateItemsAndCheckForNewSamples() { boolean anything_new = false; // Update any formulas for (ModelItem item : items) { if (item instanceof FormulaItem && ((FormulaItem) item).reevaluate()) anything_new = true; } // Check and reset PV Items for (ModelItem item : items) { if (item instanceof PVItem && item.getSamples().testAndClearNewSamplesFlag()) anything_new = true; } return anything_new; }
private Object getPreselectedPackage( final ModelItem groupItem, final FileObject preselectedFolder) { if (preselectedFolder == null) return null; final ModelItem ch[] = groupItem.getChildren(); final FileObject root = groupItem.group.getRootFolder(); String relPath = FileUtil.getRelativePath(root, preselectedFolder); relPath = relPath == null ? "" : relPath.replace('/', '.'); // NOI18N for (int i = 0; i < ch.length; i++) if (ch[i].toString().equals(relPath)) return ch[i]; return relPath; }
public Component getListCellRendererComponent( final JList list, final Object value, @SuppressWarnings("unused") final int index, final boolean isSelected, @SuppressWarnings("unused") final boolean cellHasFocus) { if (value instanceof ModelItem) { final ModelItem item = (ModelItem) value; setText(item.getDisplayName()); setIcon(item.getIcon()); } else { setText(value.toString()); setIcon(null); } if (isSelected) { setBackground(list.getSelectionBackground()); setForeground(list.getSelectionForeground()); } else { setBackground(list.getBackground()); setForeground(list.getForeground()); } return this; }
protected void processModelBasicInformation() throws SetupException { List<String> filenames = this.getFilenames(); ManagementBeanFactory factory = null; try { factory = this.getManagementBeanFactory(); ModelBean modelBean = factory.createModelBean(); if (System.getProperty("otas.dm.home") == null) { log.error( "ModelTask: " + "Could not found 'otas.dm.home' from system properties, please set 'otas.dm.home'."); } DDFTreeBean ddfBean = factory.createDDFTreeBean(); // Import Model, DDF, TACs for (String filename : filenames) { // Process the file, and import data into database. File file = new File(filename); if (!file.isAbsolute()) { file = new File(this.getSetup().getWorkDir(), filename); } this.getSetup() .getConsole() .println(" Loading file [ " + file.getAbsolutePath() + " ]"); List<ManufacturerItem> items = this.loadManufacturerItems(file.getAbsolutePath()); for (ManufacturerItem manufacturerItem : items) { List<ModelItem> modelItems = manufacturerItem.getModels(); Manufacturer manufacturer = modelBean.getManufacturerByExternalID(manufacturerItem.getExternalID()); for (ModelItem modelItem : modelItems) { Model model = modelBean.getModelByManufacturerModelID(manufacturer, modelItem.getExternalID()); if (model == null) { log.info( "Create a new model: " + manufacturer.getExternalId() + " " + modelItem.getExternalID()); model = modelBean.newModelInstance(); model.setManufacturer(manufacturer); } else { log.info( "Modify a model: " + manufacturer.getExternalId() + " " + modelItem.getExternalID()); } // Copy information from family this.copyFromFamily(modelItem); // Copy item into model entity this.copy(modelItem, model); this.getSetup() .getConsole() .println( " * Importing [" + manufacturer.getExternalId() + " " + model.getManufacturerModelId() + "] from [ " + modelItem.getDefinedByFilename() + " ]"); factory.beginTransaction(); modelBean.update(model); this.getSetup().getConsole().println(" * Basic information processed"); // ModelSpec: Icon, ... String iconFilename = modelItem.getIconFile(); if (StringUtils.isEmpty(iconFilename)) { iconFilename = this.getSetup().getPropertyValue("model.default.icon.file"); } File iconFile = new File(iconFilename); if (!iconFile.isAbsolute()) { iconFile = new File(this.getSetup().getWorkDir(), iconFilename); } if (iconFile.exists()) { model.setIconBinary(new FileInputStream(iconFile)); } else { this.getSetup() .getConsole() .println(" Could not found icon file: " + iconFile.getAbsolutePath()); } modelBean.update(model); Map<String, String> specMap = modelItem.getSpecifications(); for (String specName : specMap.keySet()) { String category = null; String name = specName; int index = specName.indexOf("."); if (index >= 0) { category = specName.substring(0, index); name = specName.substring(index + 1, specName.length()); } String value = specMap.get(specName); List<ModelCharacter> characters = modelBean.findModelCharacters(model, category, name); ModelCharacter character = null; if (characters != null && characters.size() > 0) { // Update exists character character = characters.get(0); } else { // Create a new character character = modelBean.newModelCharacterInstance(model, category, name); } character.setValue(value); modelBean.update(character); } this.getSetup().getConsole().println(" * Specifications processed"); // TACs for (String tac : modelItem.getTacs()) { if (StringUtils.isNotEmpty(tac)) { modelBean.addTACInfo(model, tac); this.getSetup().getConsole().println(" * TAC information processed"); } } // DDF Files for (String ddfFilename : modelItem.getDdfFiles()) { File ddfFile = new File(ddfFilename); if (!ddfFile.isAbsolute()) { ddfFile = new File(this.getSetup().getWorkDir(), ddfFilename); } DDFTree ddfTree = null; try { ddfTree = ddfBean.parseDDFTree(new FileInputStream(ddfFile)); } catch (Exception e) { throw new DMException("Error to parse DDF File: " + ddfFile.getAbsolutePath(), e); } ddfBean.addDDFTree(ddfTree); modelBean.attachDDFTree(model, ddfTree.getID()); this.getSetup() .getConsole() .println(" * DDF information [ " + ddfFile + " ] processed"); } factory.commit(); } } } } catch (Exception ex) { if (factory != null) { factory.rollback(); } throw new SetupException("Error in import models.", ex); } finally { if (factory != null) { factory.release(); } } }
@Override public void fireChange() { super.fireChange(); }
protected void processFirmwares() throws SetupException { List<String> filenames = this.getFilenames(); ManagementBeanFactory factory = null; try { factory = this.getManagementBeanFactory(); ModelBean modelBean = factory.createModelBean(); // Import Profile Mappings for (String filename : filenames) { // Process the file, and import data into database. File file = new File(filename); if (!file.isAbsolute()) { file = new File(this.getSetup().getWorkDir(), filename); } this.getSetup() .getConsole() .println(" Loading file [ " + file.getAbsolutePath() + " ]"); List<ManufacturerItem> items = this.loadManufacturerItems(file.getAbsolutePath()); for (ManufacturerItem manufacturerItem : items) { List<ModelItem> modelItems = manufacturerItem.getModels(); Manufacturer manufacturer = modelBean.getManufacturerByExternalID(manufacturerItem.getExternalID()); for (ModelItem modelItem : modelItems) { // Copy information from family this.copyFromFamily(modelItem); Model model = modelBean.getModelByManufacturerModelID(manufacturer, modelItem.getExternalID()); if (!modelItem.getFirmwares().isEmpty()) { this.getSetup() .getConsole() .println( " * Importing Firmwares for [ " + manufacturer.getExternalId() + " " + model.getManufacturerModelId() + " ]"); } for (FirmwareItem firmwareItem : modelItem.getFirmwares()) { File firmwareFile = new File(firmwareItem.getFilename()); if (!firmwareFile.isAbsolute()) { firmwareFile = new File(this.getSetup().getWorkDir(), firmwareItem.getFilename()); } if (!firmwareFile.exists()) { this.getSetup() .getConsole() .println("Could not load firmware from: " + firmwareFile.getAbsolutePath()); continue; } String fromVersion = firmwareItem.getFromVersion(); String toVersion = firmwareItem.getToVersion(); this.importFirmware( manufacturer.getExternalId(), model.getManufacturerModelId(), fromVersion, toVersion, firmwareFile.getAbsolutePath()); } } } } } catch (Exception ex) { throw new SetupException("Error in import models.", ex); } finally { if (factory != null) { factory.release(); } } }
protected void processCPTemplates() throws SetupException { List<String> filenames = this.getFilenames(); ManagementBeanFactory factory = null; try { factory = this.getManagementBeanFactory(); ModelBean modelBean = factory.createModelBean(); ClientProvTemplateBean cpBean = factory.createClientProvTemplateBean(); // Import Profile Mappings for (String filename : filenames) { // Process the file, and import data into database. File file = new File(filename); if (!file.isAbsolute()) { file = new File(this.getSetup().getWorkDir(), filename); } this.getSetup() .getConsole() .println(" Loading file [ " + file.getAbsolutePath() + " ]"); List<ManufacturerItem> items = this.loadManufacturerItems(file.getAbsolutePath()); for (ManufacturerItem manufacturerItem : items) { List<ModelItem> modelItems = manufacturerItem.getModels(); Manufacturer manufacturer = modelBean.getManufacturerByExternalID(manufacturerItem.getExternalID()); for (ModelItem modelItem : modelItems) { // Copy information from family this.copyFromFamily(modelItem); Model model = modelBean.getModelByManufacturerModelID(manufacturer, modelItem.getExternalID()); if (!modelItem.getCpTemplatesFiles().isEmpty()) { this.getSetup() .getConsole() .println( " * Importing CP Templates for [ " + manufacturer.getExternalId() + " " + model.getManufacturerModelId() + " ]"); } for (String templateFilename : modelItem.getCpTemplatesFiles()) { File templateFile = new File(templateFilename); if (!templateFile.isAbsolute()) { templateFile = new File(this.getSetup().getWorkDir(), templateFilename); } InputStream in = new FileInputStream(templateFile); List<ClientProvTemplate> templates = cpBean.importClientProvTemplates(in, this.getSetup().getWorkDir()); factory.beginTransaction(); for (ClientProvTemplate template : templates) { cpBean.attach(model, template); } factory.commit(); this.getSetup().getConsole().println(" [ " + templateFile + " ] imported!"); } } } } } catch (Exception ex) { if (factory != null) { factory.rollback(); } throw new SetupException("Error in import models.", ex); } finally { if (factory != null) { factory.release(); } } }
/** * @param item * @param model * @throws InvocationTargetException * @throws IllegalAccessException * @throws NoSuchMethodException */ private void copy(ModelItem item, Model model) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException { // Copy ModelItem into Model model.setManufacturerModelId(item.getExternalID()); model.setName(item.getName()); model.setDescription(item.getDescription()); model.setFamilyExternalID(item.getFamilyID()); model.setIsOmaDmEnabled(item.getIsOmaDmEnabled()); model.setOmaDmVersion(item.getOmaDmVersion()); model.setIsOmaCpEnabled(item.isOmaCpEnabled()); model.setOmaCpVersion(item.getOmaCpVersion()); model.setIsNokiaOtaEnabled(item.isNokiaOtaEnabled()); model.setNokiaOtaVersion(item.getNokiaOtaVersion()); model.setSupportedDownloadMethods(item.getSupportedDownloadMethods()); model.setFirmwareVersionNode(item.getFirmwareVersionNode()); model.setFirmwareDownloadNode(item.getFirmwareDownloadNode()); model.setFirmwareUpdateNode(item.getFirmwareUpdateNode()); model.setFirmwareDownloadAndUpdateNode(item.getFirmwareDownloadAndUpdateNode()); model.setFirmwareStatusNode(item.getFirmwareStatusNode()); }
/** * Locate item by name. If different items with the same exist in this model, the first occurrence * will be returned. If no item is found with the given name, <code>null</code> will be returned. * Now that this model may have different items with the same name, this method is not recommended * to locate an item. This method just returns an item which just happens to have the given name. * Use {@link #indexOf(ModelItem)} or {@link #getItem(int)} to locate an item in this model. * * @param name * @return ModelItem by that name or <code>null</code> */ public ModelItem getItem(final String name) { for (ModelItem item : items) if (item.getName().equals(name)) return item; return null; }
/** * @param axis Axis to test * @return ModelItem linked to this axis count */ public int countActiveItemsOnAxis(final AxisConfig axis) { int count = 0; for (ModelItem item : items) if (item.getAxis() == axis && item.isVisible()) count++; return count; }
/** * @param axis Axis to test * @return First ModelItem that uses the axis, <code>null</code> if axis is empty */ public ModelItem getFirstItemOnAxis(final AxisConfig axis) { for (ModelItem item : items) if (item.getAxis() == axis) return item; return null; }
@Override public ModelItem copy() { SaveItem copy = new SaveItem(); super.copy(copy); return (copy); }
@Override void setModel(Model model) { super.setModel(model); this.automaticRefresh = model.isAutomaticHistoryRefresh(); }
public void initValues( final Project project, final FileObject template, final FileObject preselectedFolder) { this.project = project; this.helper = project.getLookup().lookup(AntProjectHelper.class); final Object obj = template.getAttribute(IS_MIDLET_TEMPLATE_ATTRIBUTE); isMIDlet = false; if (obj instanceof Boolean) isMIDlet = ((Boolean) obj).booleanValue(); projectTextField.setText(ProjectUtils.getInformation(project).getDisplayName()); final Sources sources = ProjectUtils.getSources(project); final SourceGroup[] groups = sources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA); final SourceGroup preselectedGroup = getPreselectedGroup(groups, preselectedFolder); if (preselectedGroup != null) { final ModelItem groupItem = new ModelItem(preselectedGroup); final ModelItem[] nodes = groupItem.getChildren(); packageComboBox.setModel(new DefaultComboBoxModel(nodes)); final Object folderItem = getPreselectedPackage(groupItem, preselectedFolder); if (folderItem != null) packageComboBox.setSelectedItem(folderItem); } else { packageComboBox.setModel(new DefaultComboBoxModel()); } // Determine the extension final String ext = template == null ? "" : template.getExt(); // NOI18N expectedExtension = ext.length() == 0 ? "" : "." + ext; // NOI18N lName.setVisible(isMIDlet); tName.setVisible(isMIDlet); lIcon.setVisible(isMIDlet); cIcon.setVisible(isMIDlet); lNote.setVisible(isMIDlet); org.openide.awt.Mnemonics.setLocalizedText( lClassName, NbBundle.getMessage( MIDPTargetChooserPanelGUI.class, isMIDlet ? "LBL_File_MIDletClassName" : "LBL_File_MIDPClassName")); // NOI18N // Show name of the project if (isMIDlet) { tName.getDocument().removeDocumentListener(this); tName.setText(template.getName()); updateClassNameAndIcon(); if (testIfFileNameExists(preselectedGroup) && updateClassName) { String name = tName.getText(); int i = 1; for (; ; ) { tName.setText(name + "_" + i); // NOI18N updateClassNameAndIcon(); if (!testIfFileNameExists(preselectedGroup) || !updateClassName) break; i++; } } tName.getDocument().addDocumentListener(this); } else { tClassName.setText(template.getName()); if (testIfFileNameExists(preselectedGroup)) { String name = tClassName.getText(); int i = 1; for (; ; ) { tClassName.setText(name + "_" + i); // NOI18N if (!testIfFileNameExists(preselectedGroup)) break; i++; } } tClassName.getDocument().addDocumentListener(this); } updateText(); // Find all icons if (loadIcons) { loadIcons = false; final DefaultComboBoxModel icons = new DefaultComboBoxModel(); cIcon.setModel(icons); cIcon.setSelectedItem(""); // NOI18N RequestProcessor.getDefault() .post( new Runnable() { public void run() { final ArrayList<FileObject> roots = new ArrayList<FileObject>(); roots.add( helper.resolveFileObject( helper.getStandardPropertyEvaluator().getProperty("src.dir"))); // NOI18N final String libs = J2MEProjectUtils.evaluateProperty( helper, DefaultPropertiesDescriptor.LIBS_CLASSPATH); if (libs != null) { final String elements[] = PropertyUtils.tokenizePath(helper.resolvePath(libs)); for (int i = 0; i < elements.length; i++) try { final FileObject root = FileUtil.toFileObject(FileUtil.normalizeFile(new File(elements[i]))); if (root != null) roots.add( FileUtil.isArchiveFile(root) ? FileUtil.getArchiveRoot(root) : root); } catch (Exception e) { } } for (FileObject root : roots) { if (root != null) { final int rootLength = root.getPath().length(); final Enumeration en = root.getChildren(true); while (en.hasMoreElements()) { final FileObject fo = (FileObject) en.nextElement(); if (fo.isData()) { final String ext = fo.getExt().toLowerCase(); if ("png".equals(ext)) { // NOI18N String name = fo.getPath().substring(rootLength); if (!name.startsWith("/")) name = "/" + name; // NOI18N if (icons.getIndexOf(name) < 0) icons.addElement(name); } } } } } } }); } }