private void doSaveTemplateAs(String msg) throws Exception { InputDialog dialog = new InputDialog( J2sTemplateComposite.this.getShell(), "Save As", msg, templateCombo.getText(), null); if (dialog.open() == Dialog.OK) { String tname = dialog.getValue(); if (contributor.getBuiltInTemplates().contains(tname)) { MessageDialog.openError( J2sTemplateComposite.this.getShell(), "Error", "Error: a predefined template named \"" + tname + "\" already exists. \n " + "Predefined templates cannot be overwritten, please choose another name"); return; } else if (J2SLaunchingUtil.arrayContains(manager.listTemplateNames(), tname)) { MessageDialog overwriteDialog = new MessageDialog( J2sTemplateComposite.this.getShell(), "Overwrite existing template", null, "A template named \"" + tname + "\" already exists\n" + "Are you sure you want to overwrite it?", MessageDialog.QUESTION, new String[] {"Ok", "Cancel"}, 0); if (overwriteDialog.open() != 0) { return; } } // do it manager.putTemplate( new TemplateInfo(tname, templateCodeText.getText(), outputFileText.getText())); currentTemplateList = manager.listTemplateNames(); templateCombo.setItems(currentTemplateList); selectTemplateByName(tname); } }
private void initGUI() { try { GridLayout thisLayout = new GridLayout(); thisLayout.makeColumnsEqualWidth = true; this.setLayout(thisLayout); { applyTemplateCheck = new Button(this, SWT.CHECK | SWT.LEFT); applyTemplateCheck.setText("Apply template"); GridData button1LData = new GridData(); applyTemplateCheck.setLayoutData(button1LData); applyTemplateCheck.addSelectionListener( new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { optionsTab.updateLaunchConfigurationDialog(); updateTemaplteCheck(); } }); } { label1 = new Label(this, SWT.NONE); label1.setText("Template:"); GridData label1LData = new GridData(); label1.setLayoutData(label1LData); } { composite1 = new Composite(this, SWT.NONE); RowLayout composite1Layout = new RowLayout(org.eclipse.swt.SWT.HORIZONTAL); composite1Layout.marginLeft = 0; composite1.setLayout(composite1Layout); GridData composite1LData = new GridData(); composite1.setLayoutData(composite1LData); { templateCombo = new Combo(composite1, SWT.NONE); // templateCombo.setText("temlate1"); currentTemplateList = manager.listTemplateNames(); templateCombo.setItems(currentTemplateList); RowData templateComboLData = new RowData(); templateCombo.setLayoutData(templateComboLData); templateCombo.addSelectionListener( new SelectionAdapter() { // @Override public void widgetSelected(SelectionEvent e) { try { optionsTab.updateLaunchConfigurationDialog(); String tname = currentTemplateList[templateCombo.getSelectionIndex()]; TemplateInfo template = manager.getTemplate(tname); outputFileText.setText(template.getFileOutputName()); templateCodeText.setText(template.getTemplateCode()); } catch (Exception ex) { ex.printStackTrace(); } } }); } { saveBtn = new Button(composite1, SWT.PUSH | SWT.CENTER); saveBtn.setText("save as"); RowData saveBtnLData = new RowData(); saveBtn.setLayoutData(saveBtnLData); saveBtn.addSelectionListener( new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { try { doSaveTemplateAs("Please enter name for new template:"); } catch (Exception ex) { MessageDialog.openError( J2sTemplateComposite.this.getShell(), "Error", "Unespected error: " + ex.getMessage()); } } }); } { resetBtn = new Button(composite1, SWT.PUSH | SWT.CENTER); resetBtn.setText("reset"); resetBtn.addSelectionListener( new SelectionAdapter() { // @Override public void widgetSelected(SelectionEvent e) { try { MessageDialog overwriteDialog = new MessageDialog( J2sTemplateComposite.this.getShell(), "Reset J2S templates", null, "You are about to reset all user defined J2s templates. \n" + "All templates but predefined J2S' will be deleted. \nAre you sure?", MessageDialog.QUESTION, new String[] {"Ok", "Cancel"}, 0); if (overwriteDialog.open() == 0) { String[] names = manager.listTemplateNames(); for (int i = 0; i < names.length; i++) manager.removeTemplate(names[i]); templateCombo.setItems(manager.listTemplateNames()); } } catch (Exception ex) { MessageDialog.openError( J2sTemplateComposite.this.getShell(), "Error", "Unespected error: " + ex.getMessage()); ex.printStackTrace(); } } }); } } { label3 = new Label(this, SWT.NONE); label3.setText("Output File Name:"); GridData label3LData = new GridData(); label3.setLayoutData(label3LData); } { outputFileText = new Text(this, SWT.NONE); GridData outputFileTextLData = new GridData(); outputFileTextLData.horizontalAlignment = GridData.FILL; outputFileTextLData.grabExcessHorizontalSpace = true; outputFileText.setLayoutData(outputFileTextLData); outputFileText.addModifyListener( new ModifyListener() { // @Override public void modifyText(ModifyEvent e) { optionsTab.updateLaunchConfigurationDialog(); } }); } { label2 = new Label(this, SWT.NONE); label2.setText("Velocity Code: "); GridData label2LData = new GridData(); label2.setLayoutData(label2LData); } { templateCodeText = new Text(this, SWT.MULTI | SWT.WRAP | SWT.V_SCROLL | SWT.H_SCROLL); templateCodeText.setText("text1"); GridData text1LData = new GridData(); text1LData.verticalAlignment = GridData.FILL; text1LData.horizontalAlignment = GridData.FILL; text1LData.grabExcessHorizontalSpace = true; text1LData.grabExcessVerticalSpace = true; templateCodeText.setLayoutData(text1LData); templateCodeText.addModifyListener( new ModifyListener() { // @Override public void modifyText(ModifyEvent e) { optionsTab.updateLaunchConfigurationDialog(); // templateCodeDirty=true; } }); } this.layout(); pack(); } catch (Exception e) { e.printStackTrace(); } }