diff options
Diffstat (limited to 'src/com/ibm')
-rw-r--r-- | src/com/ibm/ServerWizard2/Launcher.java | 4 | ||||
-rw-r--r-- | src/com/ibm/ServerWizard2/ServerWizard2.java | 71 | ||||
-rw-r--r-- | src/com/ibm/ServerWizard2/controller/TargetWizardController.java | 33 | ||||
-rw-r--r-- | src/com/ibm/ServerWizard2/model/SystemModel.java | 132 | ||||
-rw-r--r-- | src/com/ibm/ServerWizard2/utility/GitProgressMonitor.java | 37 | ||||
-rw-r--r-- | src/com/ibm/ServerWizard2/utility/Github.java | 43 | ||||
-rw-r--r-- | src/com/ibm/ServerWizard2/utility/GithubFile.java | 3 | ||||
-rw-r--r-- | src/com/ibm/ServerWizard2/utility/GithubRepository.java | 250 | ||||
-rw-r--r-- | src/com/ibm/ServerWizard2/view/GitDialog.java | 457 | ||||
-rw-r--r-- | src/com/ibm/ServerWizard2/view/MainDialog.java | 181 | ||||
-rw-r--r-- | src/com/ibm/ServerWizard2/view/PasswordPrompt.java | 98 |
11 files changed, 1197 insertions, 112 deletions
diff --git a/src/com/ibm/ServerWizard2/Launcher.java b/src/com/ibm/ServerWizard2/Launcher.java index 4f15e99..0f9ba31 100644 --- a/src/com/ibm/ServerWizard2/Launcher.java +++ b/src/com/ibm/ServerWizard2/Launcher.java @@ -77,7 +77,6 @@ public class Launcher { LOGGER.info("JarName = "+jarName); GithubFile jar = new GithubFile(REPOSITORY,version,jarName,"jars",true,LOGGER); - GithubFile zip = new GithubFile(REPOSITORY,version,ZIP_NAME,"jars",true,LOGGER); String versionCurrent="NONE"; @@ -116,9 +115,6 @@ public class Launcher { } if (doUpdate) { jar.download(); - zip.update(); - zip.download(); - unzip(zip.getLocalPath(),getWorkingDir()); updated=true; GithubFile.updateSuccess(LOGGER, version); } diff --git a/src/com/ibm/ServerWizard2/ServerWizard2.java b/src/com/ibm/ServerWizard2/ServerWizard2.java index ff4ee02..e469616 100644 --- a/src/com/ibm/ServerWizard2/ServerWizard2.java +++ b/src/com/ibm/ServerWizard2/ServerWizard2.java @@ -1,8 +1,17 @@ package com.ibm.ServerWizard2; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.util.Properties; import java.util.logging.ConsoleHandler; import java.util.logging.Level; import java.util.logging.Logger; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.DirectoryDialog; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Shell; + import com.ibm.ServerWizard2.controller.TargetWizardController; import com.ibm.ServerWizard2.model.SystemModel; import com.ibm.ServerWizard2.utility.MyLogFormatter; @@ -14,7 +23,12 @@ public class ServerWizard2 { */ public final static Logger LOGGER = Logger.getLogger(ServerWizard2.class.getName()); public final static int VERSION_MAJOR = 2; - public final static int VERSION_MINOR = 1; + public final static int VERSION_MINOR = 2; + + public final static String PROPERTIES_FILE = "serverwiz.preferences"; + public static String GIT_LOCATION = ""; + public final static String DEFAULT_REMOTE_URL = "https://github.com/open-power/common-mrw-xml.git"; + public static String getVersionString() { return VERSION_MAJOR+"."+VERSION_MINOR; @@ -61,16 +75,71 @@ public class ServerWizard2 { LOGGER.config("======================================================================"); LOGGER.config("ServerWiz2 Version "+getVersionString()+" Starting..."); + + getPreferences(); + TargetWizardController tc = new TargetWizardController(); SystemModel systemModel = new SystemModel(); MainDialog view = new MainDialog(null); tc.setView(view); tc.setModel(systemModel); view.setController(tc); + tc.init(); systemModel.cleanupMode = cleanupMode; if (!inputFilename.isEmpty()) { view.mrwFilename=inputFilename; } view.open(); } + + // Load preferences file. + // Contains git repository location and repositories to manage. + private static void getPreferences() { + Display display = new Display(); + Shell shell = new Shell(display); + try { + Properties p = new Properties(); + File f = new File(ServerWizard2.PROPERTIES_FILE); + if (!f.exists()) { + //File doesn't exist, so create; prompt user for git location + ServerWizard2.LOGGER.info("Preferences file doesn't exist, creating..."); + DirectoryDialog fdlg = new DirectoryDialog(shell, SWT.OPEN); + fdlg.setMessage("Select location of GIT repositories:"); + fdlg.setFilterPath(ServerWizard2.getWorkingDir()); + String libPath = fdlg.open(); + if (libPath == null || libPath.isEmpty()) { + ServerWizard2.LOGGER.warning("No directory selected; exiting..."); + System.exit(0); + } + p.setProperty("git_location", libPath); + p.setProperty("repositories", ServerWizard2.DEFAULT_REMOTE_URL); + p.setProperty("needs_password", "false"); + + FileOutputStream out = new FileOutputStream(ServerWizard2.PROPERTIES_FILE); + p.store(out, ""); + out.close(); + } + FileInputStream propFile = new FileInputStream(ServerWizard2.PROPERTIES_FILE); + p.load(propFile); + propFile.close(); + String loc = p.getProperty("git_location"); + if (loc !=null && !loc.isEmpty()) { + ServerWizard2.GIT_LOCATION = loc; + } else { + ServerWizard2.LOGGER.severe(ServerWizard2.PROPERTIES_FILE+" does not contain a repository location.\nPlease correct or delete."); + System.exit(0); + } + + + } catch (Exception e) { + e.printStackTrace(); + ServerWizard2.LOGGER.severe(e.getMessage()); + System.exit(0); + } + } + public static String getWorkingDir() { + File f = new File("").getAbsoluteFile(); + String workingDir = f.getAbsolutePath() + System.getProperty("file.separator"); + return workingDir; + } } diff --git a/src/com/ibm/ServerWizard2/controller/TargetWizardController.java b/src/com/ibm/ServerWizard2/controller/TargetWizardController.java index 2302412..1f21c57 100644 --- a/src/com/ibm/ServerWizard2/controller/TargetWizardController.java +++ b/src/com/ibm/ServerWizard2/controller/TargetWizardController.java @@ -8,6 +8,8 @@ import java.nio.file.Files; import java.nio.file.StandardCopyOption; import java.util.Vector; +import org.apache.logging.log4j.Level; +import org.apache.logging.log4j.status.StatusLogger; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.swt.widgets.TreeItem; @@ -16,6 +18,7 @@ import com.ibm.ServerWizard2.model.Connection; import com.ibm.ServerWizard2.model.Field; import com.ibm.ServerWizard2.model.SystemModel; import com.ibm.ServerWizard2.model.Target; +import com.ibm.ServerWizard2.utility.GithubRepository; import com.ibm.ServerWizard2.view.LogViewerDialog; import com.ibm.ServerWizard2.view.MainDialog; @@ -24,9 +27,11 @@ public class TargetWizardController { private MainDialog view; private Boolean modelCreationMode = false; - private String PROCESSING_SCRIPT = "scripts/gen_html.pl"; - + private String PROCESSING_SCRIPT = "scripts"+File.separator+"gen_html.pl"; + private final String LIBRARY_NAME = "common-mrw-xml"; + public TargetWizardController() { + } public void setModelCreationMode() { @@ -38,9 +43,15 @@ public class TargetWizardController { public void init() { try { - //xmlLib.init(); - //xmlLib.loadModel(model); - model.loadLibrary("xml"); + String libraryLocation = ServerWizard2.GIT_LOCATION + File.separator + this.LIBRARY_NAME; + File chk = new File(libraryLocation); + if (!chk.exists()) { + ServerWizard2.LOGGER.info("XML library does not exist so cloning: "+libraryLocation); + StatusLogger.getLogger().setLevel(Level.FATAL); + GithubRepository git = new GithubRepository(ServerWizard2.DEFAULT_REMOTE_URL, ServerWizard2.GIT_LOCATION, false); + git.cloneRepository(); + } + model.loadLibrary(libraryLocation); this.initModel(); } catch (Exception e) { ServerWizard2.LOGGER.severe(e.toString()); @@ -70,7 +81,10 @@ public class TargetWizardController { public void deleteTarget(Target target) { model.deleteTarget(target); } - + public Vector<Field> getAttributesAndGlobals(Target targetInstance, String path) { + return model.getAttributesAndGlobals(targetInstance, path, !this.modelCreationMode); + } + public void addTargetInstance(Target targetModel, Target parentTarget, TreeItem parentItem, String nameOverride) { @@ -206,11 +220,6 @@ public class TargetWizardController { public Vector<Target> getBusTypes() { return model.getBusTypes(); } - public String getWorkingDir() { - File f = new File("").getAbsoluteFile(); - String workingDir = f.getAbsolutePath() + System.getProperty("file.separator"); - return workingDir; - } public void loadLibrary(String path) { try { model.loadLibrary(path); @@ -220,7 +229,7 @@ public class TargetWizardController { } public void runChecks(String xmlFile, String htmlFile) { - String workingDir = this.getWorkingDir(); + String workingDir = ServerWizard2.getWorkingDir(); String commandLine[] = { "perl", "-I", workingDir + "/scripts", workingDir + PROCESSING_SCRIPT, "-x", xmlFile, "-f", "-o", htmlFile }; diff --git a/src/com/ibm/ServerWizard2/model/SystemModel.java b/src/com/ibm/ServerWizard2/model/SystemModel.java index 64c349a..183f8bf 100644 --- a/src/com/ibm/ServerWizard2/model/SystemModel.java +++ b/src/com/ibm/ServerWizard2/model/SystemModel.java @@ -1,7 +1,9 @@ package com.ibm.ServerWizard2.model; +import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; +import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.io.Writer; @@ -29,7 +31,6 @@ import com.ibm.ServerWizard2.ServerWizard2; import com.ibm.ServerWizard2.view.ErrataViewer; public class SystemModel { - // public Target rootTarget; public Vector<Target> rootTargets = new Vector<Target>(); private DocumentBuilder builder; @@ -58,11 +59,12 @@ public class SystemModel { private TreeMap<String, TreeMap<String, Field>> globalSettings = new TreeMap<String, TreeMap<String, Field>>(); + private HashMap<String,Boolean> loadedLibraries = new HashMap<String,Boolean>(); + public Boolean partsMode = false; public Boolean cleanupMode = false; public Boolean errataUpdated = false; - public Vector<Target> getBusTypes() { return busTypes; } @@ -200,6 +202,11 @@ public class SystemModel { return null; } public void loadLibrary(String path) throws Exception { + if (this.loadedLibraries.containsKey(path)) { + ServerWizard2.LOGGER.info("Library already loaded: "+path); + return; + } + this.loadedLibraries.put(path, true); File xmlDir = new File(path); //Loads files in alphabetical order String[] filesStr = xmlDir.list(); @@ -252,12 +259,22 @@ public class SystemModel { NodeList part = isXMLValid(document,"partInstance"); if (system == null && part == null) { String msg = "ServerWiz cannot read this version of XML: "+filename; - ServerWizard2.LOGGER.severe(msg); - MessageDialog.openError(null, "XML Load Error", msg); + ServerWizard2.LOGGER.warning(msg); + //MessageDialog.openError(null, "XML Load Error", msg); + ServerWizard2.LOGGER.warning("Attempting to convert..."); + String newName = this.xmlUpdate(filename); + if (newName.isEmpty()) { + ServerWizard2.LOGGER.info("Error converting file"); + MessageDialog.openError(null, "XML Load Error", "Old XML format found. Error converting file to new format"); + } else { + ServerWizard2.LOGGER.info("Converted file: "+newName); + MessageDialog.openInformation(null, "XML Converted", "Old XML format found. Converted file to:\n"+newName+"\nPlease open new file."); + } + return; } partsMode = false; String targetTag = "targetInstance"; - if (part != null) { + if (part != null) { partsMode = true; targetTag = "targetPart"; ServerWizard2.LOGGER.info("Setting Parts mode"); @@ -344,6 +361,9 @@ public class SystemModel { checkErrata(); } + /* + * Compare attributes in errata*.xml against currently loaded XML + */ public void checkErrata() { Vector<Errata> errataNew = new Vector<Errata>(); @@ -396,8 +416,9 @@ public class SystemModel { } } - /////////////////////////////////////////////// - // global settings + /* + * Global settings get/sets + */ public Field setGlobalSetting(String path, String attribute, String value) { TreeMap<String, Field> s = globalSettings.get(path); @@ -471,6 +492,9 @@ public class SystemModel { this.setGlobalSetting(targetId, property, value); } } + /* + * Read errata file + */ private void readErrata(Element setting) { String errata_id = SystemModel.getElement(setting, "id"); if (this.errata.containsKey(errata_id)) { @@ -479,8 +503,40 @@ public class SystemModel { } } - ///////////////////////////////////////////////// - // Writes MRW to file + /* + * Returns a vector of attributes located in the target and global settings + * associated with a particular target instance + */ + public Vector<Field> getAttributesAndGlobals(Target targetInstance, String path, Boolean showGlobalSettings) { + Vector<Field> attributes = new Vector<Field>(); + for (Map.Entry<String, Attribute> entry : targetInstance.getAttributes().entrySet()) { + Attribute attribute = entry.getValue(); + if (!attribute.isHidden()) { + if (attribute.isGlobal() && showGlobalSettings) { + if (!path.isEmpty()) { + Field field = getGlobalSetting(path, attribute.name); + if (field==null) { + setGlobalSetting(path, attribute.name, ""); + field = getGlobalSetting(path, attribute.name); + } + field.type = attribute.getValue().getType(); + if (field.type.equals("enumeration")) { + field.enumerator = attribute.getValue().getFields().get(0).enumerator; + } + attributes.add(field); + } + } else { + for (Field field : attribute.getValue().getFields()) + attributes.add(field); + } + } + } + return attributes; + } + + /* + * Write XML to a file + */ public void writeXML(String filename, Boolean partsMode) throws Exception { Writer out = new BufferedWriter(new FileWriter(filename)); String topTag = "systemInstance"; @@ -508,6 +564,9 @@ public class SystemModel { out.close(); } + /* + * Add a target instance to the model + */ public void addTarget(Target parentTarget, Target newTarget,Boolean pathMode) throws Exception { if (parentTarget == null) { this.rootTargets.add(newTarget); @@ -794,6 +853,61 @@ public class SystemModel { } } + private String xmlUpdate(String filename) { + + BufferedReader br; + BufferedWriter wr; + boolean found_settings = false; + boolean found_targets = false; + boolean found_start = false; + String newFilename = filename+".new.xml"; + + try { + br = new BufferedReader(new FileReader(filename)); + wr = new BufferedWriter(new FileWriter(newFilename)); + String line; + try { + wr.write("<systemInstance>\n"); + wr.write("<version>2.1</version>\n"); + wr.write("<enumerationTypes>\n"); + + while ((line = br.readLine()) != null) { + if (line.equals("<enumerationType>") && !found_start) { + found_start = true; + } + if (line.equals("<globalSetting>") && !found_settings) { + wr.write("</enumerationTypes>"); + wr.write("<globalSettings>\n"); + found_settings = true; + } + if (line.equals("<targetInstance>") && !found_targets) { + wr.write("</globalSettings>\n"); + wr.write("<targetInstances>\n"); + found_targets = true; + } + if (line.equals("</targetInstances>")) { + found_start = false; + } + if (found_start) { + wr.write(line+"\n"); + } + } + wr.write("</targetInstances>\n"); + wr.write("</systemInstance>\n"); + } catch (IOException e) { + e.printStackTrace(); + newFilename = ""; + } finally { + br.close(); + wr.close(); + } + } catch (Exception e) { + e.printStackTrace(); + newFilename = ""; + } + return newFilename; + } + private void xmlCleanup() { String path = "/"+this.getRootTarget().getName(); HashMap<String,Target> targets = new HashMap<String,Target>(); diff --git a/src/com/ibm/ServerWizard2/utility/GitProgressMonitor.java b/src/com/ibm/ServerWizard2/utility/GitProgressMonitor.java new file mode 100644 index 0000000..232424d --- /dev/null +++ b/src/com/ibm/ServerWizard2/utility/GitProgressMonitor.java @@ -0,0 +1,37 @@ +package com.ibm.ServerWizard2.utility;
+
+public class GitProgressMonitor implements org.eclipse.jgit.lib.ProgressMonitor {
+
+ javax.swing.ProgressMonitor pim;
+ private int progress = 0;
+ public GitProgressMonitor(javax.swing.ProgressMonitor pim) {
+ this.pim = pim;
+ }
+
+ public void beginTask(String arg0, int arg1) {
+ progress = 0;
+ pim.setNote(arg0);
+ pim.setMaximum(arg1);
+ }
+
+ @Override
+ public void endTask() {
+ pim.close();
+ }
+
+ @Override
+ public boolean isCancelled() {
+ return pim.isCanceled();
+ }
+
+ @Override
+ public void start(int arg0) {
+ progress = 0;
+ }
+
+ @Override
+ public void update(int arg0) {
+ progress = progress+arg0;
+ pim.setProgress(progress);
+ }
+}
diff --git a/src/com/ibm/ServerWizard2/utility/Github.java b/src/com/ibm/ServerWizard2/utility/Github.java new file mode 100644 index 0000000..6eef91b --- /dev/null +++ b/src/com/ibm/ServerWizard2/utility/Github.java @@ -0,0 +1,43 @@ +package com.ibm.ServerWizard2.utility;
+
+import java.io.File;
+import java.util.Vector;
+
+public class Github {
+ private Vector<GithubRepository> repositories = new Vector<GithubRepository>();
+ private String localPath;
+
+ public Github(String path) {
+ this.localPath = path;
+ File f = new File(path);
+ if (!f.exists()) {
+ f.mkdirs();
+ }
+ }
+ public String getLocation() {
+ return this.localPath;
+ }
+ public boolean isRepository(GithubRepository repo) {
+ return repositories.contains(repo);
+ }
+
+ public Vector<GithubRepository> getRepositories() {
+ return repositories;
+ }
+
+ public String getRepositoriesStr() {
+ String repos[] = new String[this.repositories.size()];
+ for (int i = 0; i < this.repositories.size(); i++) {
+ repos[i] = this.repositories.get(i).getRemoteUrl();
+ }
+ return String.join(",", repos);
+ }
+
+ public String getPasswordStr() {
+ String repos[] = new String[this.repositories.size()];
+ for (int i = 0; i < this.repositories.size(); i++) {
+ repos[i] = this.repositories.get(i).needsPasswordStr();
+ }
+ return String.join(",", repos);
+ }
+}
diff --git a/src/com/ibm/ServerWizard2/utility/GithubFile.java b/src/com/ibm/ServerWizard2/utility/GithubFile.java index 6d14e50..22829df 100644 --- a/src/com/ibm/ServerWizard2/utility/GithubFile.java +++ b/src/com/ibm/ServerWizard2/utility/GithubFile.java @@ -206,9 +206,6 @@ public class GithubFile { } catch (Exception e) { } } - //logger.info("Current Time: " + String.valueOf(currentTime)); - //logger.info("Update Time: " + String.valueOf(updateTime)); - if ((currentTime - updateTime) < MILLISECONDS_PER_DAY*3) { logger.info("Not checking for updates"); version=""; diff --git a/src/com/ibm/ServerWizard2/utility/GithubRepository.java b/src/com/ibm/ServerWizard2/utility/GithubRepository.java new file mode 100644 index 0000000..52c7871 --- /dev/null +++ b/src/com/ibm/ServerWizard2/utility/GithubRepository.java @@ -0,0 +1,250 @@ +package com.ibm.ServerWizard2.utility;
+
+import java.io.File;
+import java.io.PrintWriter;
+import java.util.Collection;
+import java.util.HashMap;
+
+import org.eclipse.jgit.api.Git;
+import org.eclipse.jgit.api.RebaseResult;
+import org.eclipse.jgit.api.ResetCommand.ResetType;
+import org.eclipse.jgit.lib.Ref;
+import org.eclipse.jgit.lib.RepositoryCache;
+import org.eclipse.jgit.lib.TextProgressMonitor;
+import org.eclipse.jgit.transport.FetchResult;
+import org.eclipse.jgit.transport.RefSpec;
+import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider;
+import org.eclipse.jgit.util.FS;
+import org.eclipse.swt.widgets.Shell;
+
+import com.ibm.ServerWizard2.ServerWizard2;
+import com.ibm.ServerWizard2.view.PasswordPrompt;
+
+public class GithubRepository implements Comparable<GithubRepository> {
+ private String remoteUrl;
+ private File rootDirectory;
+ private File gitDirectory;
+ private boolean needsPassword;
+ private boolean passwordValidated = false;
+ private Shell shell = null;
+ private UsernamePasswordCredentialsProvider credentials;
+
+ private boolean cloned;
+ private final RefSpec refSpec = new RefSpec("+refs/heads/*:refs/remotes/origin/*");
+
+ public GithubRepository(String remoteUrl, String localDir, boolean needsPassword) {
+ this.remoteUrl = remoteUrl;
+ this.needsPassword = needsPassword;
+ File f = new File(remoteUrl);
+ String localPath = localDir + File.separator + f.getName().replace(".git", "");
+ rootDirectory = new File(localPath);
+ gitDirectory = new File(localPath + File.separator + ".git");
+ cloned = false;
+ if (RepositoryCache.FileKey.isGitRepository(this.getGitDirectory(), FS.DETECTED)) {
+ cloned = true;
+ }
+ }
+
+ public void setShell(Shell shell) {
+ this.shell = shell;
+ }
+ public File getRootDirectory() {
+ return rootDirectory;
+ }
+
+ public File getGitDirectory() {
+ return gitDirectory;
+ }
+
+ public void getPassword() {
+ if (!this.needsPassword) {
+ credentials = new UsernamePasswordCredentialsProvider("", "");
+ return;
+ }
+ PasswordPrompt dlg = new PasswordPrompt(shell, this.remoteUrl);
+ dlg.open();
+ credentials = new UsernamePasswordCredentialsProvider("", dlg.passwd);
+ passwordValidated = false;
+ }
+
+ public String getRemoteUrl() {
+ return this.remoteUrl;
+ }
+ public boolean needsPassword() {
+ return this.needsPassword;
+ }
+ public String needsPasswordStr() {
+ if (this.needsPassword) {
+ return "true";
+ }
+ return "false";
+ }
+
+ public void checkRemote() throws Exception {
+ if (!passwordValidated) {
+ this.getPassword();
+ }
+
+ Collection<Ref> refs;
+ boolean found = false;
+
+ try {
+ refs = Git.lsRemoteRepository().setCredentialsProvider(credentials).setHeads(true).setTags(true)
+ .setRemote(this.remoteUrl).call();
+ if (!refs.isEmpty()) {
+ found = true;
+ passwordValidated = true;
+ for (Ref ref : refs) {
+ ServerWizard2.LOGGER.info("Ref: " + ref);
+ }
+ }
+ } catch (Exception e) {
+ ServerWizard2.LOGGER.severe(e.getMessage());
+ this.betterError(e);
+ }
+ if (!found) {
+ passwordValidated = false;
+ throw new Exception("Invalid Remote Repository or bad Password:\n" + this.getRemoteUrl());
+ }
+ }
+
+ public void cloneRepository() throws Exception {
+ if (!passwordValidated) {
+ this.getPassword();
+ }
+ if (isCloned()) {
+ return;
+ }
+ ServerWizard2.LOGGER.info("Cloning " + this.remoteUrl + " into " + this.getRootDirectory().getAbsolutePath());
+ cloned = false;
+ try {
+ //TODO: determine MacOS hang issue with the progress monitor
+ //ProgressMonitor pim = new ProgressMonitor(null, "Cloning...", "", 0, 1);
+ //GitProgressMonitor gpim = new GitProgressMonitor(pim);
+ Git result = Git.cloneRepository()
+ .setCredentialsProvider(credentials)
+ .setProgressMonitor(new TextProgressMonitor(new PrintWriter(System.out)))
+ .setURI(this.getRemoteUrl()).setDirectory(this.getRootDirectory()).call();
+
+ cloned = true;
+ result.close();
+ } catch (Exception e1) {
+ passwordValidated = false;
+ this.betterError(e1);
+ }
+ }
+
+ public String fetch(boolean reset) throws Exception {
+ if (!passwordValidated) {
+ this.getPassword();
+ }
+
+ ServerWizard2.LOGGER.info("Fetching " + this.rootDirectory.getAbsolutePath());
+ String rstr = "";
+ try {
+ Git result = Git.open(this.rootDirectory);
+ FetchResult fetch = result.fetch()
+ .setRemote(this.getRemoteUrl())
+ .setCredentialsProvider(credentials)
+ .setProgressMonitor(new TextProgressMonitor(new PrintWriter(System.out)))
+ .setRefSpecs(refSpec)
+ .call();
+
+ ServerWizard2.LOGGER.info(fetch.getMessages());
+ if (reset) {
+ ServerWizard2.LOGGER.info("Resetting to head: " + this.getRemoteUrl());
+ result.reset().setMode(ResetType.HARD).call();
+ rstr = "Reset Complete";
+ } else {
+ ServerWizard2.LOGGER.info("Rebase: " + this.getRemoteUrl());
+ RebaseResult r = result.rebase().setUpstream("refs/remotes/origin/master").call();
+ rstr = r.getStatus().toString();
+ ServerWizard2.LOGGER.info(rstr);
+ }
+ result.close();
+ } catch (Exception e1) {
+ passwordValidated = false;
+ this.betterError(e1);
+ }
+ return rstr;
+ }
+
+ public org.eclipse.jgit.api.Status status() {
+ org.eclipse.jgit.api.Status status = null;
+ try {
+ Git result = Git.open(this.getRootDirectory());
+ status = result.status()
+ .setProgressMonitor(new TextProgressMonitor(new PrintWriter(System.out)))
+ .call();
+
+ result.close();
+ } catch (Exception e1) {
+ ServerWizard2.LOGGER.severe(e1.getMessage());
+ status = null;
+ }
+ return status;
+ }
+
+ // The chained exceptions from jgit don't explain error
+ // Need to dive down to root cause and make better error message.
+ public void betterError(Exception e) throws Exception {
+ HashMap<String,String> errorLookup = new HashMap<String,String>();
+ errorLookup.put("java.net.UnknownHostException", "Unable to connect to location:");
+ errorLookup.put("org.eclipse.jgit.errors.NoRemoteRepositoryException", "Remote Repository not found:");
+ errorLookup.put("org.eclipse.jgit.errors.TransportException", "Invalid Remote Repository or Incorrect Password: ");
+ ServerWizard2.LOGGER.severe(e.getCause().toString());
+ Throwable t = getCause(e);
+ ServerWizard2.LOGGER.severe(t.toString());
+ String errorMsg = t.getMessage();
+ if (errorLookup.containsKey(t.getClass().getName())) {
+ errorMsg = errorLookup.get(t.getClass().getName()) + "\n" + t.getMessage();
+ }
+ throw new Exception(errorMsg);
+ }
+
+ public boolean isCloned() {
+ return cloned;
+ }
+
+ public void clear() {
+ // make sure stored password is destroyed
+ credentials.clear();
+ }
+
+ public String toString() {
+ return this.remoteUrl + "; " + this.getGitDirectory().getAbsolutePath() + "; " + this.needsPasswordStr();
+ }
+
+ @Override
+ public int compareTo(GithubRepository o) {
+ return this.getRemoteUrl().compareTo(o.getRemoteUrl());
+ }
+
+ public boolean equals(Object o) {
+ if (o == null)
+ return false;
+ if (o == this)
+ return true;
+
+ if (o instanceof String) {
+ String s = (String) o;
+ if (this.getRemoteUrl().equals(s)) {
+ return true;
+ }
+ return false;
+ } else if (o instanceof GithubRepository) {
+ GithubRepository p = (GithubRepository) o;
+ return this.compareTo(p) == 0 ? true : false;
+ }
+ return false;
+ }
+ Throwable getCause(Throwable e) {
+ Throwable cause = null;
+ Throwable result = e;
+
+ while(null != (cause = result.getCause()) && (result != cause) ) {
+ result = cause;
+ }
+ return result;
+ }
+}
diff --git a/src/com/ibm/ServerWizard2/view/GitDialog.java b/src/com/ibm/ServerWizard2/view/GitDialog.java new file mode 100644 index 0000000..5aaa4c6 --- /dev/null +++ b/src/com/ibm/ServerWizard2/view/GitDialog.java @@ -0,0 +1,457 @@ +package com.ibm.ServerWizard2.view;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.Properties;
+import java.util.Set;
+import java.util.Vector;
+
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.status.StatusLogger;
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.ListViewer;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.layout.RowData;
+import org.eclipse.swt.layout.RowLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.List;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+
+import com.ibm.ServerWizard2.ServerWizard2;
+import com.ibm.ServerWizard2.utility.Github;
+import com.ibm.ServerWizard2.utility.GithubRepository;
+import org.eclipse.wb.swt.SWTResourceManager;
+
+public class GitDialog extends Dialog {
+ private Text txtNewRepo;
+ Github git = new Github(ServerWizard2.GIT_LOCATION);
+
+ private ListViewer listViewer;
+ private Button btnCloned;
+ private Button btnAdded;
+ private Button btnRemoved;
+ private Button btnChanged;
+ private Button btnConflicting;
+ private Button btnUntracked;
+ private Button btnMissing;
+ private Button btnNeedsPassword;
+ private Button btnRefresh;
+ private Text txtLocation;
+
+ /**
+ * Create the dialog.
+ *
+ * @param parentShell
+ */
+ public GitDialog(Shell parentShell) {
+ super(parentShell);
+ StatusLogger.getLogger().setLevel(Level.FATAL);
+ }
+
+ private boolean isStatusSet(Set<String> status) {
+ if (status.size() > 0) {
+ for (String s : status) {
+ ServerWizard2.LOGGER.info(s);
+ }
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * Create contents of the dialog.
+ *
+ * @param parent
+ */
+ @Override
+ protected Control createDialogArea(Composite parent) {
+ Composite container = (Composite) super.createDialogArea(parent);
+
+ Label lblGitRepositoryUrl = new Label(container, SWT.NONE);
+ lblGitRepositoryUrl.setFont(SWTResourceManager.getFont("Arial", 9, SWT.NORMAL));
+ lblGitRepositoryUrl.setText("Git Repository URL:");
+ listViewer = new ListViewer(container, SWT.BORDER | SWT.V_SCROLL);
+
+ List repositoryList = listViewer.getList();
+ repositoryList.setFont(SWTResourceManager.getFont("Arial", 9, SWT.NORMAL));
+ repositoryList.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent arg0) {
+ if (listViewer.getList().getSelectionCount() == 0) {
+ return;
+ }
+ GithubRepository g = (GithubRepository) listViewer
+ .getElementAt(listViewer.getList().getSelectionIndex());
+ txtNewRepo.setText(g.getRemoteUrl());
+ btnNeedsPassword.setSelection(g.needsPassword());
+ if (g.isCloned()) {
+ btnCloned.setSelection(true);
+ txtLocation.setText(g.getRootDirectory().getAbsolutePath());
+ org.eclipse.jgit.api.Status status = g.status();
+ if (status != null) {
+ btnAdded.setSelection(isStatusSet(status.getAdded()));
+ btnRemoved.setSelection(isStatusSet(status.getRemoved()));
+ btnChanged.setSelection(isStatusSet(status.getChanged()) | isStatusSet(status.getModified()));
+ btnConflicting.setSelection(isStatusSet(status.getConflicting()));
+ btnUntracked.setSelection(isStatusSet(status.getUntracked()));
+ btnMissing.setSelection(isStatusSet(status.getMissing()));
+
+ } else {
+ MessageDialog.openError(null, "Git Error",
+ "The Git Repository has been modified. Please restart Serverwiz." + g.getRemoteUrl());
+ }
+ } else {
+ btnCloned.setSelection(false);
+ }
+ }
+ });
+ GridData gd_repositoryList = new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1);
+ gd_repositoryList.widthHint = 314;
+ gd_repositoryList.heightHint = 111;
+ repositoryList.setLayoutData(gd_repositoryList);
+
+ Composite composite = new Composite(container, SWT.NONE);
+ composite.setLayout(new GridLayout(5, false));
+ GridData gd_composite = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
+ gd_composite.widthHint = 367;
+ gd_composite.heightHint = 52;
+ composite.setLayoutData(gd_composite);
+ composite.setEnabled(false);
+
+ Label lblNewLabel = new Label(composite, SWT.NONE);
+ lblNewLabel.setFont(SWTResourceManager.getFont("Arial", 9, SWT.NORMAL));
+ GridData gd_lblNewLabel = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
+ gd_lblNewLabel.widthHint = 48;
+ lblNewLabel.setLayoutData(gd_lblNewLabel);
+ lblNewLabel.setText("Status:");
+
+ btnCloned = new Button(composite, SWT.CHECK);
+ btnCloned.setFont(SWTResourceManager.getFont("Arial", 9, SWT.NORMAL));
+ btnCloned.setText("Cloned");
+
+ btnAdded = new Button(composite, SWT.CHECK);
+ btnAdded.setFont(SWTResourceManager.getFont("Arial", 9, SWT.NORMAL));
+ btnAdded.setText("Added");
+
+ btnRemoved = new Button(composite, SWT.CHECK);
+ btnRemoved.setFont(SWTResourceManager.getFont("Arial", 9, SWT.NORMAL));
+ btnRemoved.setText("Removed");
+
+ btnChanged = new Button(composite, SWT.CHECK);
+ btnChanged.setFont(SWTResourceManager.getFont("Arial", 9, SWT.NORMAL));
+ btnChanged.setText("Changed");
+ new Label(composite, SWT.NONE);
+ new Label(composite, SWT.NONE);
+
+ btnConflicting = new Button(composite, SWT.CHECK);
+ btnConflicting.setFont(SWTResourceManager.getFont("Arial", 9, SWT.NORMAL));
+ btnConflicting.setText("Conflicting");
+
+ btnUntracked = new Button(composite, SWT.CHECK);
+ btnUntracked.setFont(SWTResourceManager.getFont("Arial", 9, SWT.NORMAL));
+ btnUntracked.setText("Untracked");
+
+ btnMissing = new Button(composite, SWT.CHECK);
+ btnMissing.setFont(SWTResourceManager.getFont("Arial", 9, SWT.NORMAL));
+ btnMissing.setText("Missing");
+
+ Composite composite_4 = new Composite(container, SWT.NONE);
+ composite_4.setLayout(new RowLayout(SWT.HORIZONTAL));
+ GridData gd_composite_4 = new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1);
+ gd_composite_4.widthHint = 351;
+ gd_composite_4.heightHint = 31;
+ composite_4.setLayoutData(gd_composite_4);
+
+ Label lblLocalLocation = new Label(composite_4, SWT.NONE);
+ lblLocalLocation.setFont(SWTResourceManager.getFont("Arial", 9, SWT.NORMAL));
+ lblLocalLocation.setLayoutData(new RowData(93, 24));
+ lblLocalLocation.setText("Local Location: ");
+
+ txtLocation = new Text(composite_4, SWT.BORDER);
+ txtLocation.setFont(SWTResourceManager.getFont("Arial", 9, SWT.NORMAL));
+ txtLocation.setEditable(false);
+ txtLocation.setLayoutData(new RowData(251, SWT.DEFAULT));
+
+ Composite composite_3 = new Composite(container, SWT.NONE);
+ composite_3.setLayout(new RowLayout(SWT.HORIZONTAL));
+ GridData gd_composite_3 = new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1);
+ gd_composite_3.widthHint = 194;
+ gd_composite_3.heightHint = 36;
+ composite_3.setLayoutData(gd_composite_3);
+
+ btnRefresh = new Button(composite_3, SWT.NONE);
+ btnRefresh.setFont(SWTResourceManager.getFont("Arial", 9, SWT.NORMAL));
+ btnRefresh.setLayoutData(new RowData(80, SWT.DEFAULT));
+ btnRefresh.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent arg0) {
+ if (listViewer.getList().getSelectionCount() == 0) {
+ return;
+ }
+ GithubRepository g = (GithubRepository) listViewer
+ .getElementAt(listViewer.getList().getSelectionIndex());
+ try {
+ if (!g.isCloned()) {
+ g.cloneRepository();
+ }
+ org.eclipse.jgit.api.Status status = g.status();
+
+ if (!status.isClean()) {
+ boolean reset = MessageDialog.openQuestion(null, "Repository is Modified",
+ "The local repository for:\n" + g.getRemoteUrl() + "\n"
+ + "has been modified. Would you like to ignore changes and reset?");
+ if (reset) {
+ String r = g.fetch(true);
+ MessageDialog.openInformation(null, "Refresh Complete", "Reset Successful");
+
+ }
+ } else {
+ String r = g.fetch(false);
+ MessageDialog.openInformation(null, "Refresh Complete", "Message: " + r);
+ }
+ } catch (Exception e) {
+ MessageDialog.openError(null, "Git Refresh: " + g.getRemoteUrl(), e.getMessage());
+ }
+ }
+ });
+
+ btnRefresh.setText("Refresh");
+
+ Button btnDummy = new Button(composite_3, SWT.NONE);
+ btnDummy.setLayoutData(new RowData(14, SWT.DEFAULT));
+ btnDummy.setVisible(false);
+ btnDummy.setText("New Button");
+
+ Button btnDelete = new Button(composite_3, SWT.NONE);
+ btnDelete.setFont(SWTResourceManager.getFont("Arial", 9, SWT.NORMAL));
+ btnDelete.setLayoutData(new RowData(80, SWT.DEFAULT));
+ btnDelete.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent arg0) {
+ if (listViewer.getList().getSelectionCount() == 0) {
+ return;
+ }
+ GithubRepository g = (GithubRepository) listViewer
+ .getElementAt(listViewer.getList().getSelectionIndex());
+
+ boolean delete = MessageDialog.openConfirm(null, "Delete Respository",
+ "Are you sure you want to delete the following repository?\n" + g.getRemoteUrl() + "\n"
+ + "Note: This will NOT delete repository from disk");
+
+ if (!delete) {
+ return;
+ }
+ if (g.getRemoteUrl().equals(ServerWizard2.DEFAULT_REMOTE_URL)) {
+ MessageDialog.openError(null, "Error", "Deleting of default repository is not allowed");
+ } else {
+ git.getRepositories().remove(g);
+ listViewer.refresh();
+ }
+ }
+ });
+ btnDelete.setText("Delete");
+
+ Label separator = new Label(container, SWT.SEPARATOR | SWT.HORIZONTAL);
+ GridData gd_separator = new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1);
+ gd_separator.heightHint = 7;
+ gd_separator.widthHint = 360;
+ separator.setLayoutData(gd_separator);
+
+ Composite composite_2 = new Composite(container, SWT.NONE);
+ composite_2.setLayout(new RowLayout(SWT.HORIZONTAL));
+ GridData gd_composite_2 = new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1);
+ gd_composite_2.widthHint = 354;
+ gd_composite_2.heightHint = 31;
+ composite_2.setLayoutData(gd_composite_2);
+
+ Label lblNewRepository = new Label(composite_2, SWT.NONE);
+ lblNewRepository.setLayoutData(new RowData(95, SWT.DEFAULT));
+ lblNewRepository.setFont(SWTResourceManager.getFont("Arial", 9, SWT.NORMAL));
+ lblNewRepository.setText("New Repository:");
+
+ txtNewRepo = new Text(composite_2, SWT.BORDER);
+ txtNewRepo.setFont(SWTResourceManager.getFont("Arial", 9, SWT.NORMAL));
+ txtNewRepo.setLayoutData(new RowData(249, SWT.DEFAULT));
+
+ Composite composite_1 = new Composite(container, SWT.NONE);
+ RowLayout rl_composite_1 = new RowLayout(SWT.HORIZONTAL);
+ rl_composite_1.center = true;
+ composite_1.setLayout(rl_composite_1);
+ GridData gd_composite_1 = new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1);
+ gd_composite_1.widthHint = 252;
+ gd_composite_1.heightHint = 30;
+ composite_1.setLayoutData(gd_composite_1);
+
+ btnNeedsPassword = new Button(composite_1, SWT.CHECK);
+ btnNeedsPassword.setFont(SWTResourceManager.getFont("Arial", 9, SWT.NORMAL));
+ btnNeedsPassword.setLayoutData(new RowData(148, SWT.DEFAULT));
+ btnNeedsPassword.setText("Needs Password?");
+
+ Button btnAddRemote = new Button(composite_1, SWT.NONE);
+ btnAddRemote.setLayoutData(new RowData(93, SWT.DEFAULT));
+ btnAddRemote.setFont(SWTResourceManager.getFont("Arial", 9, SWT.NORMAL));
+ btnAddRemote.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent arg0) {
+ String repo = txtNewRepo.getText();
+ if (repo.isEmpty()) {
+ MessageDialog.openError(null, "Error", "Repository URL is blank");
+ return;
+ }
+ GithubRepository g = new GithubRepository(repo, git.getLocation(), btnNeedsPassword.getSelection());
+ g.setShell(getShell());
+ if (git.isRepository(g)) {
+ MessageDialog.openError(null, "Error", "Repository already exists");
+ return;
+ }
+ try {
+ g.checkRemote();
+ g.cloneRepository();
+ git.getRepositories().add(g);
+ txtNewRepo.setText("");
+ listViewer.refresh();
+ } catch (Exception e) {
+ MessageDialog.openError(null, "Add Remote: " + g.getRemoteUrl(), e.getMessage());
+ }
+ }
+ });
+ btnAddRemote.setText("Add Remote");
+
+ Label label = new Label(container, SWT.SEPARATOR | SWT.HORIZONTAL);
+ label.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
+
+ listViewer.setLabelProvider(new LabelProvider() {
+ public Image getImage(Object element) {
+ return null;
+ }
+
+ public String getText(Object element) {
+ GithubRepository g = (GithubRepository) element;
+ return g.getRemoteUrl();
+ }
+ });
+ listViewer.setContentProvider(new IStructuredContentProvider() {
+ public Object[] getElements(Object inputElement) {
+ @SuppressWarnings("rawtypes")
+ Vector v = (Vector) inputElement;
+ return v.toArray();
+ }
+
+ @Override
+ public void dispose() {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void inputChanged(Viewer arg0, Object arg1, Object arg2) {
+ // TODO Auto-generated method stub
+
+ }
+ });
+ listViewer.setInput(git.getRepositories());
+ this.getRepositories();
+ listViewer.refresh();
+ return container;
+ }
+
+ /**
+ * Create contents of the button bar.
+ *
+ * @param parent
+ */
+ @Override
+ protected void createButtonsForButtonBar(Composite parent) {
+ Button button = createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false);
+ button.setFont(SWTResourceManager.getFont("Arial", 9, SWT.NORMAL));
+ button.setText("Exit");
+ }
+
+ /**
+ * Return the initial size of the dialog.
+ */
+ @Override
+ protected Point getInitialSize() {
+ return new Point(393, 480);
+ }
+
+ public void getRepositories() {
+ try {
+ boolean newFile = false;
+ File f = new File(ServerWizard2.PROPERTIES_FILE);
+ if (!f.exists()) {
+ ServerWizard2.LOGGER.info("Preferences file doesn't exist, creating...");
+ f.createNewFile();
+ newFile = true;
+ }
+ FileInputStream propFile = new FileInputStream(ServerWizard2.PROPERTIES_FILE);
+ Properties p = new Properties();
+ p.load(propFile);
+ propFile.close();
+
+ if (newFile) {
+ p.setProperty("repositories", ServerWizard2.DEFAULT_REMOTE_URL);
+ p.setProperty("needs_password", "false");
+ }
+ String repos = p.getProperty("repositories");
+ String pass = p.getProperty("needs_password");
+ String repo[] = repos.split(",");
+ String needsPass[] = pass.split(",");
+ git.getRepositories().removeAllElements();
+
+ for (int i = 0; i < repo.length; i++) {
+ boolean n = false;
+ if (needsPass[i].equals("true")) {
+ n = true;
+ }
+ GithubRepository g = new GithubRepository(repo[i], ServerWizard2.GIT_LOCATION, n);
+ g.setShell(getShell());
+ git.getRepositories().add(g);
+ }
+ } catch (Exception e) {
+ ServerWizard2.LOGGER.severe(e.getMessage());
+ }
+ }
+
+ public boolean close() {
+ Properties p = new Properties();
+ try {
+ FileInputStream propFile = new FileInputStream(ServerWizard2.PROPERTIES_FILE);
+ p.load(propFile);
+ propFile.close();
+
+ FileOutputStream out = new FileOutputStream(ServerWizard2.PROPERTIES_FILE);
+ String repo = git.getRepositoriesStr();
+ String pass = git.getPasswordStr();
+ p.setProperty("repositories", repo);
+ p.setProperty("needs_password", pass);
+ p.store(out, "");
+ out.close();
+ } catch (IOException e) {
+ ServerWizard2.LOGGER.severe("Unable to write preferences file");
+ }
+ return super.close();
+ }
+
+ protected void configureShell(Shell shell) {
+ super.configureShell(shell);
+ shell.setText("Manage Git Repositories");
+ }
+}
diff --git a/src/com/ibm/ServerWizard2/view/MainDialog.java b/src/com/ibm/ServerWizard2/view/MainDialog.java index bb472a6..cc455d2 100644 --- a/src/com/ibm/ServerWizard2/view/MainDialog.java +++ b/src/com/ibm/ServerWizard2/view/MainDialog.java @@ -1,6 +1,5 @@ package com.ibm.ServerWizard2.view; -import java.util.Map; import java.util.Vector; import org.eclipse.jface.dialogs.Dialog; @@ -48,13 +47,14 @@ import org.eclipse.wb.swt.SWTResourceManager; import com.ibm.ServerWizard2.ServerWizard2; import com.ibm.ServerWizard2.controller.TargetWizardController; -import com.ibm.ServerWizard2.model.Attribute; import com.ibm.ServerWizard2.model.Connection; import com.ibm.ServerWizard2.model.ConnectionEndpoint; import com.ibm.ServerWizard2.model.Field; import com.ibm.ServerWizard2.model.Target; import com.ibm.ServerWizard2.utility.GithubFile; + + public class MainDialog extends Dialog { private TableViewer viewer; private Tree tree; @@ -79,6 +79,7 @@ public class MainDialog extends Dialog { private Button btnDeleteTarget; private Button btnSave; private Button btnOpen; + private Button btnClone; private Button btnOpenLib; private Button btnDeleteConnection; private Button btnSaveAs; @@ -156,9 +157,9 @@ public class MainDialog extends Dialog { rl_composite.wrap = false; rl_composite.fill = true; composite.setLayout(rl_composite); - GridData gd_composite = new GridData(SWT.FILL, SWT.TOP, true, false, 1, 1); + GridData gd_composite = new GridData(SWT.FILL, SWT.FILL, false, false, 1, 1); gd_composite.widthHint = 918; - gd_composite.heightHint = 135; + gd_composite.heightHint = 154; composite.setLayoutData(gd_composite); sashForm_1 = new SashForm(container, SWT.BORDER | SWT.VERTICAL); @@ -169,12 +170,28 @@ public class MainDialog extends Dialog { buttonRow1 = new Composite(container, SWT.NONE); GridData gd_buttonRow1 = new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1); - gd_buttonRow1.widthHint = 789; + gd_buttonRow1.widthHint = 850; buttonRow1.setLayoutData(gd_buttonRow1); GridLayout rl_buttonRow1 = new GridLayout(18, false); buttonRow1.setLayout(rl_buttonRow1); this.createButtonsForButtonBar2(buttonRow1); + new Label(buttonRow1, SWT.NONE); + new Label(buttonRow1, SWT.NONE); + new Label(buttonRow1, SWT.NONE); + new Label(buttonRow1, SWT.NONE); + new Label(buttonRow1, SWT.NONE); + new Label(buttonRow1, SWT.NONE); + new Label(buttonRow1, SWT.NONE); + new Label(buttonRow1, SWT.NONE); + new Label(buttonRow1, SWT.NONE); + new Label(buttonRow1, SWT.NONE); + new Label(buttonRow1, SWT.NONE); + new Label(buttonRow1, SWT.NONE); + new Label(buttonRow1, SWT.NONE); + new Label(buttonRow1, SWT.NONE); + new Label(buttonRow1, SWT.NONE); + new Label(buttonRow1, SWT.NONE); sashForm = new SashForm(sashForm_1, SWT.NONE); @@ -200,6 +217,8 @@ public class MainDialog extends Dialog { // ////////////////////////////////////////////////////////// // Tab folders tabFolder = new TabFolder(composite, SWT.NONE); + tabFolder.setFont(SWTResourceManager.getFont("Arial", 9, SWT.NORMAL)); + tabFolder.setLayoutData(new RowData(SWT.DEFAULT, 119)); tbtmAddInstances = new TabItem(tabFolder, SWT.NONE); tbtmAddInstances.setText("Instances"); @@ -243,11 +262,12 @@ public class MainDialog extends Dialog { btnDeleteTarget.setFont(SWTResourceManager.getFont("Arial", 9, SWT.NORMAL)); btnDeleteTarget.setText("Delete Instance"); - btnShowHidden = new Button(compositeInstance, SWT.CHECK); - GridData gd_btnShowHidden = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1); - gd_btnShowHidden.heightHint = 20; - btnShowHidden.setLayoutData(gd_btnShowHidden); - btnShowHidden.setText(" Show Hidden"); + btnShowHidden = new Button(compositeInstance, SWT.CHECK); + btnShowHidden.setFont(SWTResourceManager.getFont("Arial", 9, SWT.NORMAL)); + GridData gd_btnShowHidden = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1); + gd_btnShowHidden.heightHint = 20; + btnShowHidden.setLayoutData(gd_btnShowHidden); + btnShowHidden.setText(" Show Hidden"); btnCopyInstance = new Button(compositeInstance, SWT.NONE); btnCopyInstance.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, false, 1, 1)); @@ -272,6 +292,7 @@ public class MainDialog extends Dialog { compositeBus.setLayout(new GridLayout(2, false)); lblChooseBus = new Label(compositeBus, SWT.NONE); + lblChooseBus.setFont(SWTResourceManager.getFont("Arial", 9, SWT.NORMAL)); lblChooseBus.setAlignment(SWT.RIGHT); GridData gd_lblChooseBus = new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1); gd_lblChooseBus.widthHint = 88; @@ -279,6 +300,7 @@ public class MainDialog extends Dialog { lblChooseBus.setText("Select Bus:"); cmbBusses = new Combo(compositeBus, SWT.READ_ONLY); + cmbBusses.setFont(SWTResourceManager.getFont("Arial", 9, SWT.NORMAL)); cmbBusses.setLayoutData(new GridData(SWT.FILL, SWT.BOTTOM, true, false, 1, 1)); cmbBusses.add("NONE"); @@ -286,6 +308,7 @@ public class MainDialog extends Dialog { cmbBusses.select(0); lblSelectedCard = new Label(compositeBus, SWT.NONE); + lblSelectedCard.setFont(SWTResourceManager.getFont("Arial", 9, SWT.NORMAL)); lblSelectedCard.setAlignment(SWT.RIGHT); GridData gd_lblSelectedCard = new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1); gd_lblSelectedCard.widthHint = 93; @@ -293,6 +316,7 @@ public class MainDialog extends Dialog { lblSelectedCard.setText("Select Card:"); cmbCards = new Combo(compositeBus, SWT.READ_ONLY); + cmbCards.setFont(SWTResourceManager.getFont("Arial", 9, SWT.NORMAL)); cmbCards.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); btnDeleteConnection = new Button(compositeBus, SWT.NONE); @@ -301,6 +325,7 @@ public class MainDialog extends Dialog { btnDeleteConnection.setFont(SWTResourceManager.getFont("Arial", 9, SWT.NORMAL)); btnHideBusses = new Button(compositeBus, SWT.CHECK); + btnHideBusses.setFont(SWTResourceManager.getFont("Arial", 9, SWT.NORMAL)); btnHideBusses.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1)); btnHideBusses.setText("Show only busses of selected type"); btnHideBusses.setSelection(true); @@ -330,12 +355,11 @@ public class MainDialog extends Dialog { + "5. Navigate to connection destination\r\n6. Right-click on destination and select \"Add Connection\""); listBusses = new List(sashForm, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL); + listBusses.setFont(SWTResourceManager.getFont("Arial", 9, SWT.NORMAL)); this.addEvents(); - - controller.init(); - this.setDirtyState(false); + // load file if passed on command line if (!mrwFilename.isEmpty()) { controller.readXML(mrwFilename); @@ -345,8 +369,8 @@ public class MainDialog extends Dialog { cmbBusses.add(t.getType()); cmbBusses.setData(t.getType(), t); } + attributes = new Vector<Field>(); this.initInstanceMode(); - // columnName.setWidth(200); sashForm.setWeights(new int[] { 1, 1 }); columnName.pack(); @@ -380,12 +404,8 @@ public class MainDialog extends Dialog { try { controller.initModel(); setFilename(""); - initAll(); + initInstanceMode(); setDirtyState(false); - refreshInstanceTree(); - refreshConnections(); - updateView(); - } catch (Exception e1) { e1.printStackTrace(); } @@ -417,7 +437,7 @@ public class MainDialog extends Dialog { } Boolean dirty = controller.readXML(filename); setFilename(filename); - initAll(); + initInstanceMode(); setDirtyState(dirty); } }); @@ -481,6 +501,22 @@ public class MainDialog extends Dialog { gd_sep.widthHint = 30; label.setLayoutData(gd_sep); + btnClone = createButton(row1, IDialogConstants.NO_ID, "Manage Library", false); + GridData gd_btnClone = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1); + gd_btnClone.widthHint = 100; + + btnClone.setLayoutData(gd_btnClone); + btnClone.setFont(SWTResourceManager.getFont("Arial", 9, SWT.NORMAL)); + btnClone.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + GitDialog dlg = new GitDialog(btnClone.getShell()); + dlg.open(); + } + }); + btnClone.setToolTipText("Retrieves Library from github"); + + btnOpenLib = createButton(row1, IDialogConstants.NO_ID, "Open Lib", false); GridData gd_btnOpenLib = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1); gd_btnOpenLib.widthHint = 90; @@ -492,7 +528,7 @@ public class MainDialog extends Dialog { public void widgetSelected(SelectionEvent e) { Button b = (Button) e.getSource(); DirectoryDialog fdlg = new DirectoryDialog(b.getShell(), SWT.OPEN); - fdlg.setFilterPath(controller.getWorkingDir()); + fdlg.setFilterPath(ServerWizard2.getWorkingDir()); String libPath = fdlg.open(); if (libPath == null) { return; @@ -569,11 +605,6 @@ public class MainDialog extends Dialog { return null; } - private void initAll() { - tabFolder.setSelection(0); - initInstanceMode(); - } - private void initBusMode() { busMode = true; this.lblBusDirections.setEnabled(true); @@ -590,24 +621,24 @@ public class MainDialog extends Dialog { } if (cmbCards.getItemCount() > 0) { cmbCards.select(-1); - //this.targetForConnections = (Target)cmbCards.getData(); } for (TreeItem item : tree.getItems()) { Target target = (Target) item.getData(); - // controller.getRootTarget().hideBusses(); controller.hideBusses(target); } - - this.source = null; this.dest = null; this.selectedEndpoint = null; refreshInstanceTree(); refreshConnections(); + attributes.clear(); + viewer.setInput(attributes); + viewer.refresh(); this.updateView(); } private void initInstanceMode() { + tabFolder.setSelection(0); busMode = false; this.lblInstanceDirections.setEnabled(true); this.lblInstanceDirections.setVisible(true); @@ -618,6 +649,10 @@ public class MainDialog extends Dialog { this.targetForConnections = null; this.refreshInstanceTree(); this.listBusses.removeAll(); + refreshConnections(); + attributes.clear(); + viewer.setInput(attributes); + viewer.refresh(); this.updateView(); } @@ -637,6 +672,10 @@ public class MainDialog extends Dialog { } } + /* + * Updates button enabled states based on if target is selected + * Also updates attribute table based on selected target + */ private void updateView() { Target targetInstance = getSelectedTarget(); if (targetInstance == null) { @@ -650,10 +689,13 @@ public class MainDialog extends Dialog { updatePopupMenu(targetInstance); updateChildCombo(targetInstance); + //A target is selected so show the associated attributes TreeItem item = tree.getSelection()[0]; ConnectionEndpoint ep = this.getEndpoint(item, null); - refreshAttributes(targetInstance,ep); - + attributes = controller.getAttributesAndGlobals(targetInstance, "/"+ep.getName()); + viewer.setInput(attributes); + viewer.refresh(); + if (targetInstance.isSystem()) { btnDeleteTarget.setEnabled(false); } else { @@ -667,7 +709,10 @@ public class MainDialog extends Dialog { btnDefaults.setEnabled(true); } - + /* + * Creates right-click popup menu for adding connections + * + */ private void updatePopupMenu(Target selectedTarget) { if (selectedTarget == null || tree.getSelectionCount()==0) { return; @@ -819,36 +864,6 @@ public class MainDialog extends Dialog { this.setFontStyle(item, SWT.BOLD | SWT.ITALIC, true); selectedEndpoint = item; } - - private void refreshAttributes(Target targetInstance,ConnectionEndpoint ep) { - attributes.clear(); - for (Map.Entry<String, Attribute> entry : targetInstance.getAttributes().entrySet()) { - - Attribute attribute = entry.getValue(); - if (!attribute.isHidden()) { - if (attribute.isGlobal() && !controller.getModelCreationMode()) { - if (ep !=null) { - String path="/"+ep.getName(); - Field field = controller.getGlobalSetting(path, attribute.name); - if (field==null) { - controller.setGlobalSetting(path, attribute.name, ""); - field = controller.getGlobalSetting(path, attribute.name); - } - field.type = attribute.getValue().getType(); - if (field.type.equals("enumeration")) { - field.enumerator = attribute.getValue().getFields().get(0).enumerator; - } - attributes.add(field); - } - } else { - for (Field field : attribute.getValue().getFields()) - attributes.add(field); - } - } - } - viewer.refresh(); - } - private void clearTreeAll() { if (tree.getItemCount() > 0) { clearTree(tree.getItem(0)); @@ -997,6 +1012,23 @@ public class MainDialog extends Dialog { } } + private void addConnection(Boolean cabled) { + Target busTarget = (Target) cmbBusses.getData(cmbBusses.getText()); + Connection conn = targetForConnections.addConnection(busTarget, source, dest, cabled); + this.addConnection(conn); + setDirtyState(true); + } + + private void deleteConnection() { + if (targetForConnections == null || listBusses.getSelectionCount() == 0) { + return; + } + Connection conn = (Connection) listBusses.getData(listBusses.getSelection()[0]); + controller.deleteConnection(targetForConnections, conn.busTarget, conn); + this.refreshConnections(); + setDirtyState(true); + } + private void setFontStyle(TreeItem item, int style, boolean selected) { if (item.isDisposed()) { return; @@ -1023,23 +1055,6 @@ public class MainDialog extends Dialog { return super.close(); } - private void addConnection(Boolean cabled) { - Target busTarget = (Target) cmbBusses.getData(cmbBusses.getText()); - Connection conn = targetForConnections.addConnection(busTarget, source, dest, cabled); - this.addConnection(conn); - setDirtyState(true); - } - - private void deleteConnection() { - if (targetForConnections == null || listBusses.getSelectionCount() == 0) { - return; - } - Connection conn = (Connection) listBusses.getData(listBusses.getSelection()[0]); - controller.deleteConnection(targetForConnections, conn.busTarget, conn); - this.refreshConnections(); - setDirtyState(true); - } - public void setDirtyState(Boolean dirty) { this.dirty = dirty; if (this.btnSave != null) { @@ -1196,7 +1211,9 @@ public class MainDialog extends Dialog { public void widgetSelected(SelectionEvent arg0) { if (listBusses.getSelectionCount() > 0) { Connection conn = (Connection) listBusses.getData(listBusses.getSelection()[0]); - refreshAttributes(conn.busTarget,null); + attributes = controller.getAttributesAndGlobals(conn.busTarget, ""); + viewer.setInput(attributes); + viewer.refresh(); } } }); @@ -1288,7 +1305,5 @@ public class MainDialog extends Dialog { }); viewer.setContentProvider(ArrayContentProvider.getInstance()); - attributes = new Vector<Field>(); - viewer.setInput(attributes); } } diff --git a/src/com/ibm/ServerWizard2/view/PasswordPrompt.java b/src/com/ibm/ServerWizard2/view/PasswordPrompt.java new file mode 100644 index 0000000..2197056 --- /dev/null +++ b/src/com/ibm/ServerWizard2/view/PasswordPrompt.java @@ -0,0 +1,98 @@ +package com.ibm.ServerWizard2.view;
+
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.wb.swt.SWTResourceManager;
+
+public class PasswordPrompt extends Dialog {
+ private Text text;
+ public char passwd[];
+ private String label = "REPO";
+ Button btnOk;
+
+ /**
+ * Create the dialog.
+ * @param parentShell
+ */
+ public PasswordPrompt(Shell parentShell,String label) {
+ super(parentShell);
+ setShellStyle(SWT.APPLICATION_MODAL);
+ this.label = label;
+ }
+
+ /**
+ * Create contents of the dialog.
+ * @param parent
+ */
+ @Override
+ protected Control createDialogArea(Composite parent) {
+ Composite container = (Composite) super.createDialogArea(parent);
+
+ Label lblEnterPasswordFor = new Label(container, SWT.NONE);
+ lblEnterPasswordFor.setFont(SWTResourceManager.getFont("Arial", 9, SWT.NORMAL));
+ GridData gd_lblEnterPasswordFor = new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1);
+ gd_lblEnterPasswordFor.widthHint = 352;
+ gd_lblEnterPasswordFor.heightHint = 21;
+ lblEnterPasswordFor.setLayoutData(gd_lblEnterPasswordFor);
+ lblEnterPasswordFor.setText("Enter Password For:");
+
+ Label lblRepository = new Label(container, SWT.NONE);
+ lblRepository.setFont(SWTResourceManager.getFont("Arial", 9, SWT.NORMAL));
+ GridData gd_lblRepository = new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1);
+ gd_lblRepository.widthHint = 419;
+ gd_lblRepository.heightHint = 20;
+ lblRepository.setLayoutData(gd_lblRepository);
+ lblRepository.setText(label);
+
+ Composite composite_1 = new Composite(container, SWT.NONE);
+ GridData gd_composite_1 = new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1);
+ gd_composite_1.widthHint = 418;
+ gd_composite_1.heightHint = 38;
+ composite_1.setLayoutData(gd_composite_1);
+
+ text = new Text(composite_1, SWT.BORDER | SWT.PASSWORD);
+ text.setFont(SWTResourceManager.getFont("Arial", 9, SWT.NORMAL));
+ text.setBounds(10, 10, 115, 21);
+
+ btnOk = new Button(composite_1, SWT.NONE);
+ btnOk.setFont(SWTResourceManager.getFont("Arial", 9, SWT.NORMAL));
+ btnOk.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent arg0) {
+ passwd = text.getTextChars();
+ close();
+ }
+ });
+ btnOk.setBounds(143, 6, 75, 25);
+ btnOk.setText("Ok");
+ this.getShell().setDefaultButton(btnOk);
+
+ return container;
+ }
+
+ /**
+ * Create contents of the button bar.
+ * @param parent
+ */
+ @Override
+ protected void createButtonsForButtonBar(Composite parent) {
+ }
+
+ /**
+ * Return the initial size of the dialog.
+ */
+ @Override
+ protected Point getInitialSize() {
+ return new Point(447, 174);
+ }
+}
|