@Override public void createPartControl(Composite parent) { // Creates toolkit and form toolkit = createFormBodySection(parent, "Senate Crawler"); Section section = toolkit.createSection(form.getBody(), Section.TITLE_BAR | Section.EXPANDED); GridDataFactory.fillDefaults().grab(true, false).span(3, 1).applyTo(section); section.setExpanded(true); // Create a composite to hold the other widgets ScrolledComposite sc = new ScrolledComposite(section, SWT.H_SCROLL | SWT.V_SCROLL); sc.setExpandHorizontal(true); sc.setExpandVertical(true); GridLayoutFactory.fillDefaults().numColumns(3).equalWidth(false).applyTo(sc); // Creates an empty to create a empty space TacitFormComposite.createEmptyRow(toolkit, sc); // Create a composite that can hold the other widgets Composite client = toolkit.createComposite(form.getBody()); GridLayoutFactory.fillDefaults() .equalWidth(true) .numColumns(1) .applyTo(client); // Align the composite section to one column GridDataFactory.fillDefaults().grab(true, false).span(1, 1).applyTo(client); GridLayout layout = new GridLayout(); // Layout creation layout.numColumns = 2; createSenateInputParameters(client); TacitFormComposite.createEmptyRow(toolkit, client); outputLayout = TacitFormComposite.createOutputSection(toolkit, client, form.getMessageManager()); // Add run and help button on the toolbar addButtonsToToolBar(); }
private IStatus handleException(IProgressMonitor monitor, Exception e, String message) { monitor.done(); System.out.println(message); e.printStackTrace(); TacitFormComposite.updateStatusMessage(getViewSite(), message, IStatus.ERROR, form); TacitFormComposite.writeConsoleHeaderBegining("<terminated> Senate Crawler"); return Status.CANCEL_STATUS; }
private IStatus handledCancelRequest(String message) { TacitFormComposite.updateStatusMessage(getViewSite(), message, IStatus.ERROR, form); TacitFormComposite.writeConsoleHeaderBegining("<terminated> Senate Crawler"); return Status.CANCEL_STATUS; }
private void createSenateInputParameters(Composite client) { Section inputParamsSection = toolkit.createSection(client, Section.TITLE_BAR | Section.EXPANDED | Section.DESCRIPTION); GridDataFactory.fillDefaults().grab(true, false).span(1, 1).applyTo(inputParamsSection); GridLayoutFactory.fillDefaults().numColumns(3).applyTo(inputParamsSection); inputParamsSection.setText("Input Parameters"); ScrolledComposite sc = new ScrolledComposite(inputParamsSection, SWT.H_SCROLL | SWT.V_SCROLL); sc.setExpandHorizontal(true); sc.setExpandVertical(true); GridLayoutFactory.fillDefaults().numColumns(3).equalWidth(false).applyTo(sc); Composite sectionClient = toolkit.createComposite(inputParamsSection); sc.setContent(sectionClient); GridDataFactory.fillDefaults().grab(true, true).applyTo(sc); GridLayoutFactory.fillDefaults().numColumns(3).equalWidth(false).applyTo(sectionClient); inputParamsSection.setClient(sectionClient); String[] loading = {"Loading..."}; Label congressLabel = toolkit.createLabel(sectionClient, "Congress:", SWT.NONE); GridDataFactory.fillDefaults().grab(false, false).span(1, 0).applyTo(congressLabel); cmbCongress = new Combo(sectionClient, SWT.FLAT | SWT.READ_ONLY); GridDataFactory.fillDefaults().grab(true, false).span(2, 0).applyTo(cmbCongress); toolkit.adapt(cmbCongress); cmbCongress.setItems(loading); cmbCongress.select(0); Label dummy1 = new Label(sectionClient, SWT.NONE); dummy1.setText("Senator:"); GridDataFactory.fillDefaults().grab(false, false).span(1, 0).applyTo(dummy1); senatorTable = new Table(sectionClient, SWT.BORDER | SWT.MULTI); GridDataFactory.fillDefaults().grab(true, true).span(1, 3).hint(90, 50).applyTo(senatorTable); Composite buttonComp = new Composite(sectionClient, SWT.NONE); GridLayout btnLayout = new GridLayout(); btnLayout.marginWidth = btnLayout.marginHeight = 0; btnLayout.makeColumnsEqualWidth = false; buttonComp.setLayout(btnLayout); buttonComp.setLayoutData(new GridData(GridData.FILL_VERTICAL)); addSenatorBtn = new Button(buttonComp, SWT.PUSH); // $NON-NLS-1$ addSenatorBtn.setText("Add..."); GridDataFactory.fillDefaults().grab(false, false).span(1, 1).applyTo(addSenatorBtn); addSenatorBtn.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { handleAdd(addSenatorBtn.getShell()); } }); addSenatorBtn.setEnabled(false); removeSenatorButton = new Button(buttonComp, SWT.PUSH); removeSenatorButton.setText("Remove..."); GridDataFactory.fillDefaults().grab(false, false).span(1, 1).applyTo(removeSenatorButton); removeSenatorButton.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { for (TableItem item : senatorTable.getSelection()) { selectedSenators.remove(item.getText()); item.dispose(); } if (selectedSenators.size() == 0) { removeSenatorButton.setEnabled(false); } } }); removeSenatorButton.setEnabled(false); TacitFormComposite.createEmptyRow(toolkit, sectionClient); Group limitGroup = new Group(client, SWT.SHADOW_IN); limitGroup.setText("Limit Records"); // limitGroup.setBackground(client.getBackground()); limitGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); GridLayout limitLayout = new GridLayout(); limitLayout.numColumns = 1; limitGroup.setLayout(limitLayout); final Composite limitRecordsClient = new Composite(limitGroup, SWT.None); GridDataFactory.fillDefaults().grab(true, false).span(1, 1).applyTo(limitRecordsClient); GridLayoutFactory.fillDefaults().numColumns(3).equalWidth(false).applyTo(limitRecordsClient); limitRecords = new Button(limitRecordsClient, SWT.CHECK); limitRecords.setText("Limit Records per Senator"); GridDataFactory.fillDefaults().grab(false, false).span(3, 0).applyTo(limitRecords); limitRecords.addSelectionListener( new SelectionListener() { @Override public void widgetSelected(SelectionEvent e) { if (!limitRecords.getSelection()) { form.getMessageManager().removeMessage("limitText"); } } @Override public void widgetDefaultSelected(SelectionEvent e) { // TODO Auto-generated method stub } }); final Label sortLabel = new Label(limitRecordsClient, SWT.NONE); sortLabel.setText("Sort Records by Date:"); GridDataFactory.fillDefaults().grab(false, false).span(1, 0).applyTo(sortLabel); sortLabel.setEnabled(false); sortByDateYes = new Button(limitRecordsClient, SWT.RADIO); sortByDateYes.setText("Yes"); sortByDateYes.setEnabled(false); sortByDateYes.setSelection(true); sortByDateNo = new Button(limitRecordsClient, SWT.RADIO); sortByDateNo.setText("No"); sortByDateNo.setEnabled(false); final Label limitLabel = new Label(limitRecordsClient, SWT.NONE); limitLabel.setText("No.of.Records per Senator:"); GridDataFactory.fillDefaults().grab(false, false).span(1, 0).applyTo(limitLabel); limitLabel.setEnabled(false); limitText = new Text(limitRecordsClient, SWT.BORDER); limitText.setText("1"); GridDataFactory.fillDefaults().grab(true, false).span(2, 0).applyTo(limitText); limitText.setEnabled(false); limitText.addKeyListener( new KeyListener() { @Override public void keyReleased(KeyEvent e) { if (!(e.character >= '0' && e.character <= '9')) { form.getMessageManager() .addMessage( "limitText", "Provide valid no.of.records per senator", null, IMessageProvider.ERROR); limitText.setText(""); } else { form.getMessageManager().removeMessage("limitText"); } } @Override public void keyPressed(KeyEvent e) { // TODO Auto-generated method stub } }); TacitFormComposite.createEmptyRow(toolkit, client); Group dateGroup = new Group(client, SWT.SHADOW_IN); dateGroup.setText("Date"); dateGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); GridLayout layout = new GridLayout(); layout.numColumns = 1; dateGroup.setLayout(layout); dateRange = new Button(dateGroup, SWT.CHECK); dateRange.setText("Specify Date Range"); // TacitFormComposite.createEmptyRow(toolkit, group); final Composite dateRangeClient = new Composite(dateGroup, SWT.None); GridDataFactory.fillDefaults().grab(true, false).span(1, 1).applyTo(dateRangeClient); GridLayoutFactory.fillDefaults().numColumns(4).equalWidth(false).applyTo(dateRangeClient); dateRangeClient.setEnabled(false); dateRangeClient.pack(); final Label fromLabel = new Label(dateRangeClient, SWT.NONE); fromLabel.setText("From:"); GridDataFactory.fillDefaults().grab(false, false).span(1, 0).applyTo(fromLabel); fromDate = new DateTime(dateRangeClient, SWT.DATE | SWT.DROP_DOWN | SWT.BORDER); GridDataFactory.fillDefaults().grab(false, false).span(1, 0).applyTo(fromDate); fromLabel.setEnabled(false); fromDate.setEnabled(false); fromDate.addListener( SWT.Selection, new Listener() { @Override public void handleEvent(Event event) { int day = fromDate.getDay(); int month = fromDate.getMonth() + 1; int year = fromDate.getYear(); Date newDate = null; try { newDate = format.parse(day + "/" + month + "/" + year); } catch (ParseException e) { e.printStackTrace(); } if (newDate.before(minDate) || newDate.after(maxDate)) { Calendar cal = Calendar.getInstance(); cal.setTime(minDate); fromDate.setMonth(cal.get(Calendar.MONTH)); fromDate.setDay(cal.get(Calendar.DAY_OF_MONTH)); fromDate.setYear(cal.get(Calendar.YEAR)); } } }); final Label toLabel = new Label(dateRangeClient, SWT.NONE); toLabel.setText("To:"); GridDataFactory.fillDefaults().grab(false, false).span(1, 0).applyTo(toLabel); toDate = new DateTime(dateRangeClient, SWT.DATE | SWT.DROP_DOWN | SWT.BORDER); GridDataFactory.fillDefaults().grab(false, false).span(1, 0).applyTo(toDate); toLabel.setEnabled(false); toDate.setEnabled(false); toDate.addListener( SWT.Selection, new Listener() { @Override public void handleEvent(Event event) { int day = toDate.getDay(); int month = toDate.getMonth() + 1; int year = toDate.getYear(); Date newDate = null; try { newDate = format.parse(day + "/" + month + "/" + year); } catch (ParseException e) { e.printStackTrace(); } if (newDate.after(maxDate) || newDate.before(minDate)) { Calendar cal = Calendar.getInstance(); cal.setTime(maxDate); toDate.setMonth(cal.get(Calendar.MONTH)); toDate.setDay(cal.get(Calendar.DAY_OF_MONTH)); toDate.setYear(cal.get(Calendar.YEAR)); } } }); Job loadFieldValuesJob = new Job("Loading form field values") { HashMap<String, String> congressDetails = null; final ArrayList<String> tempCongress = new ArrayList<String>(); final ArrayList<String> tempCongressYears = new ArrayList<String>(); @Override protected IStatus run(IProgressMonitor monitor) { try { congressDetails = AvailableRecords.getAllCongresses(); } catch (IOException e) { e.printStackTrace(); } Display.getDefault() .syncExec( new Runnable() { @Override public void run() { cmbCongress.removeAll(); for (String key : congressDetails.keySet()) { tempCongress.add(key); String value = congressDetails.get(key); tempCongressYears.add(value); cmbCongress.add(key + " (" + value + ")"); if (key.equalsIgnoreCase("All")) { String[] tempYears = value.split("-"); Calendar cal = Calendar.getInstance(); cal.set(Integer.parseInt(tempYears[0]), 0, 1); minDate = cal.getTime(); fromDate.setMonth(cal.get(Calendar.MONTH)); fromDate.setDay(cal.get(Calendar.DAY_OF_MONTH)); fromDate.setYear(cal.get(Calendar.YEAR)); cal.set(Integer.parseInt(tempYears[1]), 11, 31); toDate.setMonth(cal.get(Calendar.MONTH)); toDate.setDay(cal.get(Calendar.DAY_OF_MONTH)); toDate.setYear(cal.get(Calendar.YEAR)); maxDate = cal.getTime(); } } // cmbCongress.setItems(congresses); cmbCongress.select(0); } }); congresses = tempCongress.toArray(new String[0]); congressYears = tempCongressYears.toArray(new String[0]); try { allSenators = AvailableRecords.getAllSenators(congresses); totalSenators = allSenators.length + 5; Display.getDefault() .syncExec( new Runnable() { @Override public void run() { addSenatorBtn.setEnabled(true); } }); } catch (IOException e2) { e2.printStackTrace(); } return Status.OK_STATUS; } }; // loadFieldValuesJob.setUser(true); loadFieldValuesJob.schedule(); cmbCongress.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { // set dates String tempYears[] = congressYears[cmbCongress.getSelectionIndex()].split("-"); Calendar cal = Calendar.getInstance(); cal.set(Integer.parseInt(tempYears[0]), 0, 1); minDate = cal.getTime(); fromDate.setMonth(cal.get(Calendar.MONTH)); fromDate.setDay(cal.get(Calendar.DAY_OF_MONTH)); fromDate.setYear(cal.get(Calendar.YEAR)); cal.set(Integer.parseInt(tempYears[1]), 11, 31); toDate.setMonth(cal.get(Calendar.MONTH)); toDate.setDay(cal.get(Calendar.DAY_OF_MONTH)); toDate.setYear(cal.get(Calendar.YEAR)); maxDate = cal.getTime(); // cmbSenator.select(0); // Empty the senatorTable senatorTable.removeAll(); selectedSenators = new ArrayList<String>(); } }); dateRange.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { if (dateRange.getSelection()) { dateRangeClient.setEnabled(true); fromLabel.setEnabled(true); fromDate.setEnabled(true); toLabel.setEnabled(true); toDate.setEnabled(true); } else { dateRangeClient.setEnabled(false); fromLabel.setEnabled(false); fromDate.setEnabled(false); toLabel.setEnabled(false); toDate.setEnabled(false); } } }); limitRecords.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { if (limitRecords.getSelection()) { sortByDateYes.setEnabled(true); sortByDateNo.setEnabled(true); sortLabel.setEnabled(true); limitLabel.setEnabled(true); limitText.setEnabled(true); } else { sortByDateYes.setEnabled(false); sortByDateNo.setEnabled(false); sortLabel.setEnabled(false); limitLabel.setEnabled(false); limitText.setEnabled(false); } } }); }