Package at.kugel.tool.buildtray.action

Source Code of at.kugel.tool.buildtray.action.EditConfigurationCommand

package at.kugel.tool.buildtray.action;

import java.awt.Desktop;
import java.io.File;
import java.io.IOException;

import at.kugel.tool.buildtray.action.desktop.DesktopOperation;
import at.kugel.tool.buildtray.config.Config;
import at.kugel.tool.buildtray.status.SetStatusAble;

/**
* Open the configuration for editing.
*
* @author <a href="http://www.code-cop.org/">Peter Kofler</a>
*/
class EditConfigurationCommand extends ActionCommand {

   public EditConfigurationCommand(Config config, SetStatusAble statusDisplay) {
      super(config, statusDisplay);
   }

   @Override
   protected void workTemplate() throws IOException {
      openConfigFile();
   }

   private void openConfigFile() throws IOException {
      try {
         openConfigInEditor();
      } catch (IOException e) {
         // failes if *.properties is not registered, desperate, so try notepad ... DIRTY
         openConfigInNotepad();
      }
   }

   private void openConfigInEditor() throws IOException {
      new DesktopOperation(Desktop.Action.EDIT) {
         @Override
         public void runWithDesktop(Desktop deskTop) throws IOException {
            deskTop.edit(configurationFile());
         }
      }.run();
   }

   private File configurationFile() {
      return config.getConfigFileLocation();
   }

   private void openConfigInNotepad() throws IOException {
      new ProcessBuilder(editorCommand(), configurationFile().toString()).start();
   }

   private String editorCommand() {
      // TODO editor is Windows specific
      return "notepad.exe";
   }

}
TOP

Related Classes of at.kugel.tool.buildtray.action.EditConfigurationCommand

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.