[jboss-cvs] jbosside/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/upgrades ...

Robert Stryker rawblem at gmail.com
Thu Sep 14 14:46:50 EDT 2006


  User: rawb    
  Date: 06/09/14 14:46:50

  Added:       as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/upgrades 
                        UpdatePage20.java
  Log:
  Implementation to make use of firstrun's extension point and convert old run configurations. 
  
  Revision  Changes    Path
  1.1      date: 2006/09/14 18:46:50;  author: rawb;  state: Exp;jbosside/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/upgrades/UpdatePage20.java
  
  Index: UpdatePage20.java
  ===================================================================
  package org.jboss.ide.eclipse.as.ui.upgrades;
  
  import java.util.ArrayList;
  import java.util.HashMap;
  import java.util.Iterator;
  import java.util.List;
  
  import org.eclipse.core.runtime.CoreException;
  import org.eclipse.core.runtime.IProgressMonitor;
  import org.eclipse.jdt.launching.IVMInstall;
  import org.eclipse.swt.SWT;
  import org.eclipse.swt.custom.ScrolledComposite;
  import org.eclipse.swt.events.ModifyEvent;
  import org.eclipse.swt.events.ModifyListener;
  import org.eclipse.swt.events.SelectionEvent;
  import org.eclipse.swt.events.SelectionListener;
  import org.eclipse.swt.layout.FormAttachment;
  import org.eclipse.swt.layout.FormData;
  import org.eclipse.swt.layout.FormLayout;
  import org.eclipse.swt.layout.GridData;
  import org.eclipse.swt.layout.GridLayout;
  import org.eclipse.swt.widgets.Button;
  import org.eclipse.swt.widgets.Composite;
  import org.eclipse.swt.widgets.Event;
  import org.eclipse.swt.widgets.Label;
  import org.eclipse.swt.widgets.Listener;
  import org.eclipse.swt.widgets.Text;
  import org.eclipse.wst.server.core.IRuntime;
  import org.eclipse.wst.server.core.IServer;
  import org.eclipse.wst.server.core.ServerCore;
  import org.jboss.ide.eclipse.as.core.util.ASLaunchConfigurationConverter;
  import org.jboss.ide.eclipse.as.core.util.ASLaunchConfigurationConverter.TempLaunchConfiguration;
  import org.jboss.ide.eclipse.firstrun.wizard.pages.AbstractFirstRunPage;
  
  public class UpdatePage20 extends AbstractFirstRunPage {
  
  	private ASLaunchConfigurationConverter converter;
  	private TempLaunchConfiguration[] configs;
  	
  	private ArrayList rows;
  	private boolean pageComplete;
  	private String errorMessage;
  	
  	private ConfigDataComposite configDataComposite;
  	
  	public UpdatePage20() {
  		super("", "Convert JBoss AS Launch Configurations", null);
  		setDescription("This is where I explain why we need to convert launch configs to servers");
  		rows = new ArrayList();
  	}
  
  	public void createControl(Composite parent) {
  		Composite main = new Composite(parent, SWT.NONE);
  		main.setLayout(new FormLayout());
  		
  		Composite main2 = new Composite(main, SWT.NONE);
  		FormData main2Data = new FormData();
  		main2Data.left = new FormAttachment(0,5);
  		main2Data.right = new FormAttachment(100,-5);
  		main2Data.top = new FormAttachment(0,5);
  		main2Data.bottom = new FormAttachment(100,-5);
  		main2.setLayoutData(main2Data);
  		
  		main2.setLayout(new FormLayout());
  		
  		
  		
  		ScrolledComposite sc = new ScrolledComposite(main2, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
  		FormData scData = new FormData();
  		scData.left = new FormAttachment(0,5);
  		scData.right = new FormAttachment(100,-5);
  		scData.top = new FormAttachment(0,5);
  		scData.bottom = new FormAttachment(50,-2);
  		sc.setLayoutData(scData);
  		
  		fillScrolledComposite(sc);
  		
  		
  		configDataComposite = new ConfigDataComposite(main2, SWT.NONE);
  		FormData cdcData = new FormData();
  		cdcData.left = new FormAttachment(0,5);
  		cdcData.right = new FormAttachment(100,-5);
  		cdcData.top = new FormAttachment(sc,5);
  		cdcData.bottom = new FormAttachment(100,-5);
  		configDataComposite.setLayoutData(cdcData);
  		
  		
  		setControl(main);
  		checkPageComplete();
  	}
  	
  	protected class ConfigDataComposite extends Composite {
  		private TempLaunchConfiguration currentConfig;
  		
  		private Label launchConfigName, homeDir, jbConfig, startArgs, stopArgs, jre;
  		
  		public ConfigDataComposite(Composite parent, int style) {
  			super(parent, style);
  			
  			setLayout(new FormLayout());
  			
  			
  			Label detailLabel = new Label(this, SWT.NONE);
  			FormData dld = new FormData();
  			dld.left = new FormAttachment(0,5);
  			dld.top = new FormAttachment(0,5);
  			detailLabel.setLayoutData(dld);
  			detailLabel.setText("Details: ");
  			
  			Composite detailComposite = new Composite(this, SWT.NONE);
  			detailComposite.setLayout(new GridLayout(2, false));
  			FormData detailCompositeData = new FormData();
  			detailCompositeData.left = new FormAttachment(0,20);
  			detailCompositeData.top = new FormAttachment(detailLabel, 5);
  			detailComposite.setLayoutData(detailCompositeData);
  			
  			
  			
  			new Label(detailComposite, SWT.NONE).setText("Launch Configuration Name: ");
  			launchConfigName = new Label(detailComposite, SWT.NONE);
  			
  			new Label(detailComposite, SWT.NONE).setText("Home Directory: ");
  			homeDir = new Label(detailComposite, SWT.NONE);
  			
  			new Label(detailComposite, SWT.NONE).setText("JBoss Configuration: ");
  			jbConfig = new Label(detailComposite, SWT.NONE);
  			
  			new Label(detailComposite, SWT.NONE).setText("Start Arguments: ");
  			startArgs = new Label(detailComposite, SWT.NONE);
  			
  			new Label(detailComposite, SWT.NONE).setText("Shutdown Arguments: ");
  			stopArgs = new Label(detailComposite, SWT.NONE);
  			
  			new Label(detailComposite, SWT.NONE).setText("JRE: ");
  			jre = new Label(detailComposite, SWT.NONE);
  		}
  		
  		public void setInput(TempLaunchConfiguration config) {
  			if( config != currentConfig) {
  				currentConfig = config;
  				try {
  					launchConfigName.setText(config.getName());
  					homeDir.setText(config.getAttribute("org.jboss.rocklet.HomeDir", ""));
  					jbConfig.setText(config.getAttribute("org.jboss.rocklet.ServerConfiguration", ""));
  					startArgs.setText(config.getAttribute("org.rocklet.launcher.userProgramArgs", ""));
  					stopArgs.setText(config.getAttribute("org.rocklet.launcher.userShutdownProgramArgs", ""));
  
  					IVMInstall vm = config.getJVMItem();
  					String vmName = vm == null ? "" : vm.getName();
  					jre.setText(vmName);
  					layout();
  				} catch( CoreException ce ) {
  					ce.printStackTrace();
  				}
  			}
  		}
  	}
  	
  	protected void fillScrolledComposite(ScrolledComposite sc) {
  	    
  		Composite main = new Composite(sc, SWT.NONE);
  		main.setLayout(new GridLayout(4, false));
  		sc.setContent(main);
  		
  		
  
  		// add headings
  		Label convertLabel = new Label(main, SWT.NONE);
  		convertLabel.setText("Convert?");
  		Label configName = new Label(main, SWT.NONE);
  		configName.setText("Configuration Name");
  		Label runtimeLabel = new Label(main, SWT.NONE);
  		runtimeLabel.setText("Runtime Name");
  		Label serverLabel = new Label(main, SWT.NONE);
  		serverLabel.setText("Server Name");
  		
  		for( int i = 0; i < configs.length; i++ ) {
  			// should add the 4 widgets itself
  			ConfigurationRow row = new ConfigurationRow(configs[i], main);
  			rows.add(row);
  		}
  
  		
  		// force a layout
  		main.pack();
  		
          int locY = main.getLocation().y;
          int locX = main.getLocation().x;
          int sY = main.getSize().y;
          int sX = main.getSize().x;
  
  		
  	    sc.setExpandHorizontal(true);
  	    sc.setExpandVertical(true);
  	    sc.setMinHeight(locY + sY);
  	    sc.setMinWidth(locX + sX);
  	    
  		sc.setSize(300,150);
  	}
  	
  
  	public void initialize() {
  		converter = new ASLaunchConfigurationConverter();
  		configs = converter.getConvertableConfigurations();
  	}
  
  	public void performFinishWithProgress(IProgressMonitor monitor) {
  		monitor.beginTask("Converting Launch Configurations", rows.size() * 100);
  		monitor.setTaskName("Converting Launch Configurations");
  		Iterator i = rows.iterator();
  		while(i.hasNext()) {
  			ConfigurationRow r = (ConfigurationRow)i.next();
  			if( r.getSelected() ) {
  				// now convert
  				monitor.subTask("Converting " + r.getLaunchConfig().getName());
  				try {
  					converter.convertConfiguration(r.getLaunchConfig(), 
  							r.getRuntimeName(), r.getServerName());
  				} catch( CoreException ce ) {
  					ce.printStackTrace();
  				}
  			}
  		}
  		monitor.done();
  	}
  	
      public boolean isPageComplete() {
      	return pageComplete;
      }
  
      protected void checkPageComplete() {
      	pageComplete = true; // start it off true. If it remains true, great
      	HashMap map = new HashMap();
      	
      	
      	
      	String server_prefix = "__SP__";
      	String rt_prefix = "__RT__";
      	
      	IRuntime[] rts = ServerCore.getRuntimes();
      	IServer[] servers = ServerCore.getServers();
      	
      	for( int i = 0; i < rts.length; i++ ) {
      		map.put(rt_prefix + rts[i].getName(), "");
      	}
      	for( int i = 0; i < servers.length; i++ ) {
      		map.put(server_prefix + servers[i].getName(), "");
      	}
      	
      	ArrayList runtimeCollisions = new ArrayList();
      	ArrayList serverCollisions = new ArrayList();
      	
      	Iterator i = rows.iterator();
      	while(i.hasNext()) {
      		ConfigurationRow r = (ConfigurationRow)i.next();
      		if( r.getSelected()) {
      			if( !map.containsKey(rt_prefix + r.getRuntimeName())
      					&& !map.containsKey(server_prefix + r.getServerName())) {
      				map.put(rt_prefix + r.getRuntimeName(), "");
      				map.put(server_prefix + r.getServerName(), "");
  	    		} else {
  	    			if( map.containsKey(rt_prefix + r.getRuntimeName()))
  	    				runtimeCollisions.add(r.getRuntimeName());
  	    			if( map.containsKey(server_prefix + r.getServerName()))
  	    				serverCollisions.add(r.getServerName());
  	    				
  	    			pageComplete = false;
  	    		}
      		}
      	}
      	
      	if( runtimeCollisions.size() == 0 && serverCollisions.size() == 0 ) {
      		errorMessage = null;
      	} else {
      		errorMessage = "";
      		String[] sc = (String[]) serverCollisions.toArray(new String[serverCollisions.size()]);
      		String[] rtc = (String[]) runtimeCollisions.toArray(new String[runtimeCollisions.size()]);
      		if( rtc.length > 0 ) 
      			errorMessage += "The following runtime names are already in use: " + implode(rtc, ", ") + "\n";
      		if( sc.length > 0 ) 
      			errorMessage += "The following server names are already in use: " + implode(sc, ", ");
      	}
      	setErrorMessage(errorMessage);
      }
      
      protected String implode(String[] array, String separator) {
      	if( array.length == 0 ) return "";
      	String ret = "";
      	for( int i = 0; i < array.length; i++ ) {
      		ret += array[i] + separator;
      	}
      	return ret.substring(0, ret.length() - separator.length());
      }
      
  	protected class ConfigurationRow {
  		private TempLaunchConfiguration config;
  		
  		private Button shouldConvert;
  		private Label nameLabel;
  		private Text runtimeText;
  		private Text serverText;
  		
  		public ConfigurationRow(TempLaunchConfiguration config, Composite parent) {
  			this.config = config;
  
  			shouldConvert = new Button(parent, SWT.CHECK);
  			shouldConvert.setSelection(true);
  			GridData shouldConvertData = new GridData(GridData.HORIZONTAL_ALIGN_CENTER);
  			shouldConvert.setLayoutData(shouldConvertData);
  			
  			nameLabel = new Label(parent, SWT.NONE);
  			nameLabel.setText(config.getName());
  			
  			runtimeText = new Text(parent, SWT.BORDER);
  			runtimeText.setText(config.getName() + " Runtime");
  			
  			GridData rtgd = new GridData(GridData.FILL_HORIZONTAL);
  			runtimeText.setLayoutData(rtgd);
  			
  			serverText = new Text(parent, SWT.BORDER);
  			serverText.setText(config.getName());
  			GridData stgd = new GridData(GridData.FILL_HORIZONTAL);
  			serverText.setLayoutData(stgd);
  			
  			
  			
  			// listeners
  			SelectionListener listener = new SelectionListener() { 
  				public void widgetDefaultSelected(SelectionEvent e) {
  				}
  
  				public void widgetSelected(SelectionEvent e) {
  					checkPageComplete();
  					getContainer().updateButtons();
  				} 
  			};
  			ModifyListener modListener = new ModifyListener() {
  				public void modifyText(ModifyEvent e) {
  					checkPageComplete();
  					getContainer().updateButtons();
  				} 
  			};
  			shouldConvert.addSelectionListener(listener);
  			runtimeText.addModifyListener(modListener);
  			serverText.addModifyListener(modListener);
  			
  			final TempLaunchConfiguration config2 = config;
  			Listener mmListener = new Listener() {
  				public void handleEvent(Event event) {
  					if( event.type == SWT.MouseMove) {
  						configDataComposite.setInput(config2);
  					}
  				}
  			};
  			shouldConvert.addListener(SWT.MouseMove, mmListener);
  			runtimeText.addListener(SWT.MouseMove, mmListener);
  			serverText.addListener(SWT.MouseMove, mmListener);
  			nameLabel.addListener(SWT.MouseMove, mmListener);
  		}
  		
  		public boolean getSelected() {
  			return shouldConvert.getSelection();
  		}
  		public String getName() {
  			return nameLabel.getText();
  		}
  		public String getRuntimeName() {
  			return runtimeText.getText();
  		}
  		public String getServerName() {
  			return serverText.getText();
  		}
  		public TempLaunchConfiguration getLaunchConfig() {
  			return config;
  		}
  	}
  }
  
  
  



More information about the jboss-cvs-commits mailing list