@Override public Object doExecute(ExecutionEvent event) throws ExecutionException { ProjectContent projectContent = this.getProjectContent(event); RttProject project = projectContent.getProject(); Configuration config = project.createEmptyConfiguration(); ConfigurationDialog configDialog = new ConfigurationDialog(getParentShell(event), project, config); configDialog.setTitle("New Configuration ..."); configDialog.setMessage("Create a new Configuration."); if (configDialog.open() == Dialog.OK) { try { String configName = configDialog.getConfigName(); String parserClass = configDialog.getInitNodeName(); List<String> cpEntries = configDialog.getClasspathEntries(); project.setConfiguration(configName, parserClass, cpEntries, configDialog.isDefault()); projectContent.reload(new ReloadInfo(Content.CONFIGURATION)); } catch (Exception e) { throw new ExecutionException("Could not add configuration.", e); } } configDialog.close(); return null; }
/** * Create contents of the dialog. * * @param parent */ @Override protected Control createDialogArea(Composite parent) { super.setMessage(message, IMessageProvider.INFORMATION); super.setTitle(title); Composite area = (Composite) super.createDialogArea(parent); Composite container = new Composite(area, SWT.NONE); container.setLayout(new GridLayout(3, false)); container.setLayoutData(new GridData(GridData.FILL_BOTH)); Label nameLabel = new Label(container, SWT.NONE); nameLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1)); nameLabel.setText("Name:"); nameText = new Text(container, SWT.BORDER); nameText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1)); nameText.setText(configName); nameText.addModifyListener(getModifyListener()); nameText.setEnabled(nameEditable); defaultButton = new Button(container, SWT.CHECK); defaultButton.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1)); defaultButton.setAlignment(SWT.CENTER); defaultButton.setText("Default"); defaultButton.setSelection(isDefault); defaultButton.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { setOkButtonEnabled(true); } }); Label initNodeLabel = new Label(container, SWT.NONE); initNodeLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1)); initNodeLabel.setText("Initial Node:"); initNodeText = new Text(container, SWT.BORDER); initNodeText.setText(initNodeName); initNodeText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); initNodeText.addModifyListener(getModifyListener()); Button initNodeButton = new Button(container, SWT.NONE); initNodeButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 0, 1)); initNodeButton.setText("Find ..."); initNodeButton.addSelectionListener( new ClassSelectionAdapter(getParentShell(), initNodeText, project.getSearchScope())); Label classpathLabel = new Label(container, SWT.NONE); classpathLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1)); classpathLabel.setText("Classpath:"); listViewer = new ListViewer(container, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL); listViewer.getList().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); listViewer.setContentProvider(new ArrayContentProvider()); listViewer.setLabelProvider(new LabelProvider()); listViewer.setInput(cpEntries); Composite classpathComposite = new Composite(container, SWT.NONE); classpathComposite.setLayout(new GridLayout(1, true)); Button btnAddFile = new Button(classpathComposite, SWT.NONE); btnAddFile.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1)); btnAddFile.setText("Add Files ..."); btnAddFile.addSelectionListener(new ResourceSelectionAdapter(DialogType.RESOURCE, this)); Button btnAddFolder = new Button(classpathComposite, SWT.NONE); btnAddFolder.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1)); btnAddFolder.setText("Add Binary Folder ..."); btnAddFolder.addSelectionListener(new ResourceSelectionAdapter(DialogType.CONTAINER, this)); Button btnAddAbsolute = new Button(classpathComposite, SWT.NONE); btnAddAbsolute.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1)); btnAddAbsolute.setText("Add Entry ..."); btnAddAbsolute.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { InputDialog dialog = new InputDialog(getParentShell(), "Add Entry...", "", "", null); dialog.setBlockOnOpen(true); if (dialog.open() == Dialog.OK) { cpEntries.add(dialog.getValue()); setOkButtonEnabled(true); listViewer.refresh(); } } }); Composite composite = new Composite(classpathComposite, SWT.NONE); composite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1)); final Button btnRemove = new Button(classpathComposite, SWT.NONE); btnRemove.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1)); btnRemove.setText("Remove"); btnRemove.setEnabled(false); btnRemove.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { String selectedString = ViewerUtils.getSelection(listViewer.getSelection(), String.class); if (selectedString != null && !selectedString.equals("")) { int oldIndex = cpEntries.indexOf(selectedString); cpEntries.remove(selectedString); listViewer.refresh(); int size = cpEntries.size(); if (size == 0) { btnRemove.setEnabled(false); } else { int select = Math.min(oldIndex, size - 1); listViewer.setSelection(new StructuredSelection(cpEntries.get(select))); } setOkButtonEnabled(true); } } }); new Label(container, SWT.NONE); Label lblNoteToAdd = new Label(container, SWT.NONE); lblNoteToAdd.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1)); lblNoteToAdd.setText("Note: To add Java archives (*.jar) use 'Add Files ...' "); new Label(container, SWT.NONE); Composite spacer = new Composite(container, SWT.NONE); GridData gd_spacer = new GridData(SWT.FILL, SWT.CENTER, false, false, 3, 1); gd_spacer.heightHint = 30; spacer.setLayoutData(gd_spacer); listViewer.addSelectionChangedListener( new ISelectionChangedListener() { @Override public void selectionChanged(SelectionChangedEvent event) { boolean enable = false; String selectedString = ViewerUtils.getSelection(event.getSelection(), String.class); if (selectedString != null && !selectedString.equals("")) { enable = true; } btnRemove.setEnabled(enable); } }); return area; }