예제 #1
0
 /** Returns possible choices for drop down lists. */
 @Override
 protected Object[] getParamPossibleChoices(final String param) {
   if (DiskData.SOURCE_FILE.equals(param)) {
     final Set<String> sourceFileDirs = new TreeSet<String>();
     sourceFileDirs.add(LIBVIRT_IMAGE_LOCATION);
     for (final Host h : getVMSVirtualDomainInfo().getDefinedOnHosts()) {
       final VMSXML vmsxml = getBrowser().getVMSXML(h);
       if (vmsxml != null) {
         sourceFileDirs.addAll(vmsxml.getsourceFileDirs());
       }
     }
     return sourceFileDirs.toArray(new String[sourceFileDirs.size()]);
   } else if (DiskData.SOURCE_DEVICE.equals(param)) {
     for (final Host h : getVMSVirtualDomainInfo().getDefinedOnHosts()) {
       final VMSXML vmsxml = getBrowser().getVMSXML(h);
       final List<String> bds = new ArrayList<String>();
       bds.add(null);
       if (vmsxml != null) {
         for (final BlockDevInfo bdi : h.getBrowser().getBlockDevInfos()) {
           if (bdi.getBlockDevice().isDrbd()) {
             bds.add(bdi.getDrbdVolumeInfo().getDeviceByRes());
           } else {
             bds.add(bdi.getName());
           }
         }
         return bds.toArray(new String[bds.size()]);
       }
     }
   }
   return POSSIBLE_VALUES.get(param);
 }
예제 #2
0
 /** Returns the regexp of the parameter. */
 @Override
 protected String getParamRegexp(final String param) {
   if (FILE_TYPE.equals(getComboBoxValue(DiskData.TYPE)) && DiskData.SOURCE_FILE.equals(param)) {
     return ".*[^/]$";
   }
   return super.getParamRegexp(param);
 }
예제 #3
0
 /** Returns device parameters. */
 @Override
 protected Map<String, String> getHWParameters(final boolean allParams) {
   Tools.invokeAndWait(
       new Runnable() {
         @Override
         public void run() {
           getInfoPanel();
         }
       });
   final String[] params = getRealParametersFromXML();
   final Map<String, String> parameters = new LinkedHashMap<String, String>();
   for (final String param : params) {
     final String value = getComboBoxValue(param);
     if (DiskData.TYPE.equals(param)) {
       parameters.put(param, value);
     } else if (DiskData.TARGET_BUS_TYPE.equals(param)) {
       if (value == null) {
         parameters.put(DiskData.TARGET_BUS, null);
         parameters.put(DiskData.TARGET_TYPE, null);
       } else {
         final String[] values = value.split("/");
         if (values.length == 2) {
           parameters.put(DiskData.TARGET_BUS, values[0]);
           parameters.put(DiskData.TARGET_TYPE, values[1]);
         } else {
           LOG.appWarning("getHWParameters: cannot parse: " + param + " = " + value);
         }
       }
     } else if (allParams) {
       if (Tools.areEqual(getParamDefault(param), value)) {
         parameters.put(param, null);
       } else {
         parameters.put(param, value);
       }
     } else if (!Tools.areEqual(getParamSaved(param), value)
         || DiskData.SOURCE_FILE.equals(param)
         || DiskData.SOURCE_DEVICE.equals(param)
         || DiskData.SOURCE_PROTOCOL.equals(param)
         || DiskData.SOURCE_NAME.equals(param)
         || DiskData.SOURCE_HOST_NAME.equals(param)
         || DiskData.SOURCE_HOST_PORT.equals(param)
         || DiskData.AUTH_USERNAME.equals(param)
         || DiskData.AUTH_SECRET_TYPE.equals(param)
         || DiskData.AUTH_SECRET_UUID.equals(param)) {
       if (Tools.areEqual(getParamDefault(param), value)) {
         parameters.put(param, null);
       } else {
         parameters.put(param, value);
       }
     }
   }
   parameters.put(DiskData.SAVED_TARGET_DEVICE, getName());
   setName(getParamSaved(DiskData.TARGET_DEVICE));
   return parameters;
 }
예제 #4
0
 /** Returns true if the specified parameter is required. */
 @Override
 protected boolean isRequired(final String param) {
   final String type = getComboBoxValue(DiskData.TYPE);
   if ((DiskData.SOURCE_FILE.equals(param) && FILE_TYPE.equals(type))
       || (DiskData.SOURCE_DEVICE.equals(param) && BLOCK_TYPE.equals(type))) {
     if ("ide/cdrom".equals(getComboBoxValue(DiskData.TARGET_BUS_TYPE))
         || "fdc/floppy".equals(getComboBoxValue(DiskData.TARGET_BUS_TYPE))) {
       return false;
     } else {
       return true;
     }
   }
   return IS_REQUIRED.contains(param);
 }
예제 #5
0
 /** Returns combo box for parameter. */
 @Override
 protected Widget createWidget(final String param, final String prefix, final int width) {
   String prefixS;
   if (prefix == null) {
     prefixS = "";
   } else {
     prefixS = prefix;
   }
   if (DiskData.SOURCE_FILE.equals(param)) {
     final String sourceFile = getParamSaved(DiskData.SOURCE_FILE);
     final String regexp = ".*[^/]$";
     final MyButton fileChooserBtn = new MyButton("Browse...");
     fileChooserBtn.miniButton();
     final Widget paramWi =
         WidgetFactory.createInstance(
             getFieldType(param),
             sourceFile,
             getParamPossibleChoices(param),
             regexp,
             width,
             Widget.NO_ABBRV,
             new AccessMode(getAccessType(param), false), /* only adv. mode */
             fileChooserBtn);
     paramWi.setAlwaysEditable(true);
     sourceFileWi.put(prefixS, paramWi);
     if (Tools.isWindows()) {
       /* does not work on windows and I tried, ultimately because
          FilePane.usesShellFolder(fc) in BasicFileChooserUI returns
          true and it is not possible to descent into a directory.
          TODO: It may work in the future.
       */
       paramWi.setTFButtonEnabled(false);
     }
     fileChooserBtn.addActionListener(
         new ActionListener() {
           @Override
           public void actionPerformed(final ActionEvent e) {
             final Thread t =
                 new Thread(
                     new Runnable() {
                       @Override
                       public void run() {
                         String file;
                         final String oldFile = paramWi.getStringValue();
                         if (oldFile == null || "".equals(oldFile)) {
                           file = LIBVIRT_IMAGE_LOCATION;
                         } else {
                           file = oldFile;
                         }
                         startFileChooser(paramWi, file, FILECHOOSER_FILE_ONLY);
                       }
                     });
             t.start();
           }
         });
     widgetAdd(param, prefix, paramWi);
     return paramWi;
   } else {
     final Widget paramWi = super.createWidget(param, prefix, width);
     if (DiskData.TYPE.equals(param) || DiskData.TARGET_BUS_TYPE.equals(param)) {
       paramWi.setAlwaysEditable(false);
     } else if (DiskData.SOURCE_DEVICE.equals(param)) {
       paramWi.setAlwaysEditable(true);
       sourceDeviceWi.put(prefixS, paramWi);
     } else if (DiskData.SOURCE_NAME.equals(param)) {
       sourceNameWi.put(prefixS, paramWi);
     } else if (DiskData.SOURCE_PROTOCOL.equals(param)) {
       sourceProtocolWi.put(prefixS, paramWi);
     } else if (DiskData.SOURCE_HOST_NAME.equals(param)) {
       sourceHostNameWi.put(prefixS, paramWi);
     } else if (DiskData.SOURCE_HOST_PORT.equals(param)) {
       sourceHostPortWi.put(prefixS, paramWi);
     } else if (DiskData.AUTH_USERNAME.equals(param)) {
       authUsernameWi.put(prefixS, paramWi);
     } else if (DiskData.AUTH_SECRET_TYPE.equals(param)) {
       authSecretTypeWi.put(prefixS, paramWi);
     } else if (DiskData.AUTH_SECRET_UUID.equals(param)) {
       authSecretUuidWi.put(prefixS, paramWi);
     } else if (DiskData.TARGET_DEVICE.equals(param)) {
       paramWi.setAlwaysEditable(true);
       targetDeviceWi.put(prefixS, paramWi);
     } else if (DiskData.DRIVER_NAME.equals(param)) {
       driverNameWi.put(prefixS, paramWi);
     } else if (DiskData.DRIVER_TYPE.equals(param)) {
       driverTypeWi.put(prefixS, paramWi);
     } else if (DiskData.DRIVER_CACHE.equals(param)) {
       driverCacheWi.put(prefixS, paramWi);
     } else if (DiskData.READONLY.equals(param)) {
       readonlyWi.put(prefixS, paramWi);
     }
     return paramWi;
   }
 }