Search in sources :

Example 71 with ModifyEvent

use of org.eclipse.swt.events.ModifyEvent in project LAMSADE-tools by LAntoine.

the class Tester method main.

public static void main(String[] args) throws SQLException {
    System.setProperty("SWT_GTK3", "0");
    Display display = new Display();
    Shell shell = new Shell(display);
    // shell.setSize(300, 300);
    shell.setText("Conference List");
    GridLayout gridLayout = new GridLayout();
    shell.setLayout(gridLayout);
    shell.setLocation(400, 200);
    shell.layout(true, true);
    final Point newSize = shell.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
    shell.setSize(new Point(888, 661));
    /*
		 * Initialize Group conferencesInfos which will include : -The Grid data
		 * which will display conferences
		 *
		 * -The fields that will allow the user to add a new conference in the
		 * database
		 */
    Group grpUserDetails = new Group(shell, SWT.NONE);
    GridData gd_grpUserDetails = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
    gd_grpUserDetails.widthHint = 848;
    gd_grpUserDetails.heightHint = 155;
    grpUserDetails.setLayoutData(gd_grpUserDetails);
    grpUserDetails.setText("User Details");
    Label lblFirstname = new Label(grpUserDetails, SWT.NONE);
    lblFirstname.setBounds(10, 26, 70, 15);
    lblFirstname.setText("First Name");
    Label lblNewLabel_1 = new Label(grpUserDetails, SWT.NONE);
    lblNewLabel_1.setBounds(10, 53, 55, 15);
    lblNewLabel_1.setText("Last Name");
    txt_firstname = new Text(grpUserDetails, SWT.BORDER);
    txt_firstname.setBounds(86, 23, 98, 21);
    txt_lastname = new Text(grpUserDetails, SWT.BORDER);
    txt_lastname.setBounds(86, 50, 98, 21);
    /*
		 * Handle the User Info's Search Throws exception if firstname or
		 * lastname is wrong
		 */
    Button btn_searchInfo = new Button(grpUserDetails, SWT.NONE);
    btn_searchInfo.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent arg0) {
            try {
                UserDetails user = GetInfosFromYearbook.getUserDetails(txt_lastname.getText(), txt_firstname.getText());
                txt_function.setText(user.getFunction());
                txt_number.setText(user.getNumber());
                txt_email.setText(user.getEmail());
                txt_group.setText(user.getGroup());
                txt_fax.setText(user.getFax());
                txt_office.setText(user.getOffice());
                txt_city_ud.setText(user.getCity());
                txt_country_ud.setText(user.getCountry());
            } catch (@SuppressWarnings("unused") Exception e) {
                MessageBox mb = new MessageBox(shell, SWT.ICON_ERROR | SWT.OK);
                mb.setText("Error");
                mb.setMessage("Please verify firstname and lastname");
                mb.open();
            }
        }
    });
    btn_searchInfo.setBounds(10, 87, 114, 25);
    btn_searchInfo.setText("Search My Infos");
    Label lbl_function = new Label(grpUserDetails, SWT.NONE);
    lbl_function.setBounds(224, 26, 55, 15);
    lbl_function.setText("Function");
    Label lbl_number = new Label(grpUserDetails, SWT.NONE);
    lbl_number.setBounds(224, 56, 55, 15);
    lbl_number.setText("Phone");
    Label lbl_email = new Label(grpUserDetails, SWT.NONE);
    lbl_email.setBounds(224, 92, 55, 15);
    lbl_email.setText("E-mail");
    Label lbl_group = new Label(grpUserDetails, SWT.NONE);
    lbl_group.setBounds(224, 124, 55, 15);
    lbl_group.setText("Group");
    txt_function = new Text(grpUserDetails, SWT.BORDER);
    txt_function.setBounds(285, 20, 219, 21);
    txt_number = new Text(grpUserDetails, SWT.BORDER);
    txt_number.setBounds(285, 53, 219, 21);
    txt_email = new Text(grpUserDetails, SWT.BORDER);
    txt_email.setBounds(285, 87, 219, 21);
    txt_group = new Text(grpUserDetails, SWT.BORDER);
    txt_group.setBounds(285, 121, 219, 21);
    Label lbl_fax = new Label(grpUserDetails, SWT.NONE);
    lbl_fax.setText("Fax");
    lbl_fax.setBounds(535, 26, 55, 15);
    Label lbl_office = new Label(grpUserDetails, SWT.NONE);
    lbl_office.setText("Office");
    lbl_office.setBounds(535, 59, 55, 15);
    Label lbl_city = new Label(grpUserDetails, SWT.NONE);
    lbl_city.setText("City");
    lbl_city.setBounds(535, 92, 55, 15);
    Label lbl_country = new Label(grpUserDetails, SWT.NONE);
    lbl_country.setText("Country");
    lbl_country.setBounds(535, 124, 55, 15);
    txt_fax = new Text(grpUserDetails, SWT.BORDER);
    txt_fax.setBounds(596, 23, 219, 21);
    txt_office = new Text(grpUserDetails, SWT.BORDER);
    txt_office.setBounds(596, 56, 219, 21);
    txt_city_ud = new Text(grpUserDetails, SWT.BORDER);
    txt_city_ud.setBounds(596, 89, 219, 21);
    txt_country_ud = new Text(grpUserDetails, SWT.BORDER);
    txt_country_ud.setBounds(596, 121, 219, 21);
    Group grp_conferencesInfos = new Group(shell, SWT.NONE);
    GridData gd_conferencesInfos = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
    gd_conferencesInfos.heightHint = 237;
    gd_conferencesInfos.widthHint = 854;
    grp_conferencesInfos.setLayoutData(gd_conferencesInfos);
    grp_conferencesInfos.setText("Conferences");
    Table table = new Table(grp_conferencesInfos, SWT.V_SCROLL);
    table.setBounds(165, 16, 502, 134);
    table.setHeaderVisible(true);
    fillConferenceTable(table);
    Button btn_addNewConf = new Button(grp_conferencesInfos, SWT.NONE);
    btn_addNewConf.setBounds(165, 156, 149, 25);
    btn_addNewConf.setText("Create conference");
    Label lblTitle = new Label(grp_conferencesInfos, SWT.NONE);
    lblTitle.setAlignment(SWT.RIGHT);
    lblTitle.setBounds(25, 16, 50, 15);
    lblTitle.setText("Title");
    Text txt_title = new Text(grp_conferencesInfos, SWT.BORDER);
    txt_title.setBounds(81, 15, 78, 21);
    Label lblUrl = new Label(grp_conferencesInfos, SWT.NONE);
    lblUrl.setAlignment(SWT.RIGHT);
    lblUrl.setText("URL");
    lblUrl.setBounds(25, 45, 50, 15);
    Text txt_url = new Text(grp_conferencesInfos, SWT.BORDER);
    txt_url.setBounds(81, 42, 78, 21);
    Label lblStartDate = new Label(grp_conferencesInfos, SWT.NONE);
    lblStartDate.setAlignment(SWT.RIGHT);
    lblStartDate.setText("Start Date");
    lblStartDate.setBounds(10, 72, 65, 15);
    Text txt_startDate = new Text(grp_conferencesInfos, SWT.BORDER);
    txt_startDate.setBounds(81, 69, 78, 21);
    Label lblEndDate = new Label(grp_conferencesInfos, SWT.NONE);
    lblEndDate.setAlignment(SWT.RIGHT);
    lblEndDate.setText("End Date");
    lblEndDate.setBounds(10, 99, 65, 15);
    Text txt_endDate = new Text(grp_conferencesInfos, SWT.BORDER);
    txt_endDate.setBounds(81, 96, 78, 21);
    Label lblFee = new Label(grp_conferencesInfos, SWT.NONE);
    lblFee.setText("Fee");
    lblFee.setBounds(42, 126, 33, 15);
    Text txt_fee = new Text(grp_conferencesInfos, SWT.BORDER);
    txt_fee.setBounds(81, 123, 78, 21);
    // add news fields
    /*
		 * Label lblCity= new Label(grp_conferencesInfos, SWT.NONE);
		 * lblCity.setAlignment(SWT.RIGHT); lblCity.setBounds(25, 38, 50, 15);
		 * lblCity.setText("City"); Text txt_city = new
		 * Text(grp_conferencesInfos, SWT.BORDER); txt_city.setBounds(81, 35,
		 * 78, 21);
		 */
    Label lblCity = new Label(grp_conferencesInfos, SWT.NONE);
    lblCity.setAlignment(SWT.RIGHT);
    lblCity.setBounds(25, 153, 50, 15);
    lblCity.setText("City");
    Text txt_city = new Text(grp_conferencesInfos, SWT.BORDER);
    txt_city.setBounds(81, 150, 78, 21);
    Label lbladdress = new Label(grp_conferencesInfos, SWT.NONE);
    lbladdress.setAlignment(SWT.RIGHT);
    lbladdress.setBounds(25, 180, 50, 15);
    lbladdress.setText("Address");
    Text txt_address = new Text(grp_conferencesInfos, SWT.BORDER);
    txt_address.setBounds(81, 177, 78, 21);
    // Create new Conference object, assign it values from
    // selection, then pass it function to export to desktop
    // public Conference(int id, String title, String url, LocalDate
    // start_date, LocalDate end_date, double entry_fee)
    Button btnExportEvent = new Button(grp_conferencesInfos, SWT.NONE);
    btnExportEvent.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/M/yyyy");
            TableItem[] ti = table.getSelection();
            if (ti.length == 0) {
            // Put somewhere that an event should be selected
            } else {
                Conference conf = new Conference(ti[0].getText(0), ti[0].getText(1), LocalDate.parse(ti[0].getText(2), formatter), LocalDate.parse(ti[0].getText(3), formatter), Double.parseDouble(ti[0].getText(4)), ti[0].getText(5), ti[0].getText(6));
                try {
                    FileDialog dialog = new FileDialog(shell, SWT.SAVE);
                    dialog.setFilterNames(new String[] { "Calendar Files", "All Files (*.*)" });
                    // Windows
                    dialog.setFilterExtensions(new String[] { "*.ics", "*.*" });
                    switch(Util.getOS()) {
                        case WINDOWS:
                            dialog.setFilterPath("c:\\");
                            break;
                        case LINUX:
                            dialog.setFilterPath("/");
                            break;
                        case MAC:
                            dialog.setFilterPath("/");
                            break;
                        case SOLARIS:
                            dialog.setFilterPath("/");
                            break;
                        default:
                            dialog.setFilterPath("/");
                    }
                    dialog.setFileName("conference.ics");
                    conf.generateCalendarFile(dialog.open());
                } catch (IOException | ValidationException | ParserException e2) {
                    e2.printStackTrace();
                }
            }
        }
    });
    btnExportEvent.setBounds(320, 154, 104, 28);
    btnExportEvent.setText("Export Event");
    /*
		 * Behavior of a click on the add new conference button
		 */
    btn_addNewConf.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent arg0) {
            System.out.println("Appui sur le bouton");
            if (!txt_title.getText().isEmpty() && !txt_url.getText().isEmpty() && !txt_startDate.getText().isEmpty() && !txt_startDate.getText().isEmpty() && !txt_endDate.getText().isEmpty() && !txt_fee.getText().isEmpty()) {
                try {
                    DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/MM/yyyy");
                    LocalDate startDate = LocalDate.parse(txt_startDate.getText(), formatter);
                    LocalDate endDate = LocalDate.parse(txt_endDate.getText(), formatter);
                    Conference conf = new Conference(txt_title.getText(), txt_url.getText(), startDate, endDate, Double.parseDouble(txt_fee.getText()), txt_city.getText(), txt_address.getText());
                    ConferenceDatabase.insertInDatabase(conf);
                    /*
						 * Reload the conference table
						 */
                    table.removeAll();
                    fillConferenceTable(table);
                } catch (DateTimeParseException e1) {
                    MessageBox mb = new MessageBox(shell, SWT.ICON_ERROR | SWT.OK);
                    mb.setText("Date format error");
                    mb.setMessage("Please fill the dates in the following format : dd/MM/YYYY");
                    mb.open();
                } catch (SQLException e2) {
                    throw new IllegalStateException(e2);
                }
            } else {
                MessageBox mb = new MessageBox(shell, SWT.ICON_ERROR | SWT.OK);
                mb.setText("Information missing");
                mb.setMessage("Please fill in the information regarding the conference");
                mb.open();
            }
        }
    });
    /*
		 * This group will help the user to see his itinerary into the browser
		 */
    Group grp_map = new Group(shell, SWT.NONE);
    grp_map.setText("Visualize your travel");
    GridData gd_map = new GridData(SWT.LEFT, SWT.CENTER, false, true, 1, 1);
    gd_map.heightHint = 85;
    gd_map.widthHint = 860;
    grp_map.setLayoutData(gd_map);
    Text departure = new Text(grp_map, SWT.BORDER);
    departure.setLocation(101, 22);
    departure.setSize(196, 21);
    Text arrival = new Text(grp_map, SWT.BORDER);
    arrival.setLocation(101, 51);
    arrival.setSize(196, 21);
    Button btnItinerary = new Button(grp_map, SWT.NONE);
    btnItinerary.setText("Validate");
    btnItinerary.setBounds(303, 49, 68, 25);
    Label lblDeparture = new Label(grp_map, SWT.NONE);
    lblDeparture.setAlignment(SWT.RIGHT);
    lblDeparture.setBounds(10, 25, 73, 15);
    lblDeparture.setText("Departure");
    Label lblArrival = new Label(grp_map, SWT.NONE);
    lblArrival.setAlignment(SWT.RIGHT);
    lblArrival.setBounds(10, 54, 73, 15);
    lblArrival.setText("Arrival");
    /*
		 * Behavior of the btnItinerary : Takes the addresses entered in
		 * departure and arrival Texts and call the ItineraryMap class to open
		 * the itinerary into the browser
		 */
    btnItinerary.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent arg0) {
            System.out.println("Appui sur le bouton");
            if (!departure.getText().isEmpty() && !arrival.getText().isEmpty()) {
                try {
                    AddressInfos dep = new AddressInfos(departure.getText());
                    AddressInfos arr = new AddressInfos(arrival.getText());
                    // ItineraryMap itinerary = new
                    // ItineraryMap(dep.getLongitude(),
                    // dep.getLatitude(),arr.getLongitude(),
                    // arr.getLatitude());
                    GoogleItineraryMap itinerary = new GoogleItineraryMap(departure.getText(), arrival.getText());
                    String url = itinerary.setMapUrl();
                    System.out.println(url);
                    itinerary.openMapUrl(url);
                } catch (IllegalArgumentException e) {
                    LOGGER.error("Error : ", e);
                }
            } else {
                MessageBox mb = new MessageBox(shell, SWT.ICON_ERROR | SWT.OK);
                mb.setText("Infromation missing");
                mb.setMessage("Please fill in the departure and arrival fields");
                mb.open();
            }
        }
    });
    arrival.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            System.out.println("nouvelle valeur = " + ((Text) e.widget).getText());
        }
    });
    departure.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            System.out.println("nouvelle valeur = " + ((Text) e.widget).getText());
        }
    });
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
    display.dispose();
}
Also used : Group(org.eclipse.swt.widgets.Group) AddressInfos(com.github.lantoine.lamsadetools.map.AddressInfos) ModifyListener(org.eclipse.swt.events.ModifyListener) SQLException(java.sql.SQLException) Label(org.eclipse.swt.widgets.Label) Conference(com.github.lantoine.lamsadetools.conferences.Conference) LocalDate(java.time.LocalDate) Shell(org.eclipse.swt.widgets.Shell) GridLayout(org.eclipse.swt.layout.GridLayout) GoogleItineraryMap(com.github.lantoine.lamsadetools.map.GoogleItineraryMap) ModifyEvent(org.eclipse.swt.events.ModifyEvent) UserDetails(com.github.lantoine.lamsadetools.setCoordinates.UserDetails) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Table(org.eclipse.swt.widgets.Table) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Text(org.eclipse.swt.widgets.Text) Point(org.eclipse.swt.graphics.Point) ValidationException(net.fortuna.ical4j.model.ValidationException) SQLException(java.sql.SQLException) ParserException(net.fortuna.ical4j.data.ParserException) IOException(java.io.IOException) DateTimeParseException(java.time.format.DateTimeParseException) MessageBox(org.eclipse.swt.widgets.MessageBox) DateTimeParseException(java.time.format.DateTimeParseException) GridData(org.eclipse.swt.layout.GridData) DateTimeFormatter(java.time.format.DateTimeFormatter) FileDialog(org.eclipse.swt.widgets.FileDialog) Display(org.eclipse.swt.widgets.Display)

Example 72 with ModifyEvent

use of org.eclipse.swt.events.ModifyEvent in project azure-tools-for-java by Microsoft.

the class AzureNewDockerLoginPage method initUIMainContainer.

private void initUIMainContainer(Composite mainContainer) {
    dockerHostImportKeyvaultCredsRadioButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            dockerHostImportKeyvaultComboBox.setEnabled(true);
            dockerHostUsernameTextField.setEnabled(false);
            dockerHostFirstPwdField.setEnabled(false);
            dockerHostSecondPwdField.setEnabled(false);
            dockerHostNoSshRadioButton.setEnabled(false);
            dockerHostAutoSshRadioButton.setEnabled(false);
            dockerHostImportSshRadioButton.setEnabled(false);
            dockerHostImportSSHTextField.setEnabled(false);
            dockerHostImportSSHBrowseButton.setEnabled(false);
            dockerHostNoTlsRadioButton.setEnabled(false);
            dockerHostAutoTlsRadioButton.setEnabled(false);
            dockerHostImportTlsRadioButton.setEnabled(false);
            dockerHostImportTLSTextField.setEnabled(false);
            dockerHostImportTLSBrowseButton.setEnabled(false);
            setErrorMessage(null);
            setPageComplete(doValidate());
        }
    });
    dockerHostImportKeyvaultComboBox.setEnabled(false);
    for (AzureDockerCertVault certVault : dockerManager.getDockerKeyVaults()) {
        dockerHostImportKeyvaultComboBox.add(certVault.name);
        dockerHostImportKeyvaultComboBox.setData(certVault.name, certVault);
    }
    if (dockerManager.getDockerKeyVaults().size() > 0) {
        dockerHostImportKeyvaultComboBox.select(0);
    }
    dockerHostImportKeyvaultComboBox.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            setPageComplete(doValidate());
        }
    });
    dockerHostNewCredsRadioButton.setSelection(true);
    dockerHostNewCredsRadioButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            dockerHostImportKeyvaultComboBox.setEnabled(false);
            dockerHostUsernameTextField.setEnabled(true);
            dockerHostFirstPwdField.setEnabled(true);
            dockerHostSecondPwdField.setEnabled(true);
            dockerHostNoSshRadioButton.setEnabled(true);
            dockerHostAutoSshRadioButton.setEnabled(true);
            dockerHostImportSshRadioButton.setEnabled(true);
            if (dockerHostImportSshRadioButton.getSelection()) {
                dockerHostImportSSHTextField.setEnabled(true);
                dockerHostImportSSHBrowseButton.setEnabled(true);
            }
            dockerDaemonPortTextField.setEnabled(true);
            dockerHostNoTlsRadioButton.setEnabled(true);
            dockerHostAutoTlsRadioButton.setEnabled(true);
            dockerHostImportTlsRadioButton.setEnabled(true);
            if (dockerHostImportTlsRadioButton.getSelection()) {
                dockerHostImportTLSTextField.setEnabled(true);
                dockerHostImportTLSBrowseButton.setEnabled(true);
            }
            setErrorMessage(null);
            setPageComplete(doValidate());
        }
    });
    dockerHostUsernameTextField.setText(newHost.certVault.vmUsername);
    dockerHostUsernameTextField.setToolTipText(AzureDockerValidationUtils.getDockerHostUserNameTip());
    dockerHostUsernameTextField.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent event) {
            if (AzureDockerValidationUtils.validateDockerHostUserName(((Text) event.getSource()).getText())) {
                errDispatcher.removeMessage("dockerHostUsernameTextField", dockerHostUsernameTextField);
                setErrorMessage(null);
                setPageComplete(doValidate());
            } else {
                errDispatcher.addMessage("dockerHostUsernameTextField", AzureDockerValidationUtils.getDockerHostUserNameTip(), null, IMessageProvider.ERROR, dockerHostUsernameTextField);
                setErrorMessage("Invalid user name");
                setPageComplete(false);
            }
        }
    });
    dockerHostFirstPwdField.setToolTipText(AzureDockerValidationUtils.getDockerHostPasswordTip());
    dockerHostFirstPwdField.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent event) {
            String text = ((Text) event.getSource()).getText();
            if (text == null || text.isEmpty() || AzureDockerValidationUtils.validateDockerHostPassword(text)) {
                errDispatcher.removeMessage("dockerHostFirstPwdField", dockerHostFirstPwdField);
                setErrorMessage(null);
                setPageComplete(doValidate());
            } else {
                errDispatcher.addMessage("dockerHostFirstPwdField", AzureDockerValidationUtils.getDockerHostPasswordTip(), null, IMessageProvider.ERROR, dockerHostFirstPwdField);
                setErrorMessage("Invalid password");
                setPageComplete(false);
            }
        }
    });
    dockerHostSecondPwdField.setToolTipText(AzureDockerValidationUtils.getDockerHostPasswordTip());
    dockerHostSecondPwdField.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent event) {
            String pwd1 = dockerHostFirstPwdField.getText();
            String pwd2 = ((Text) event.getSource()).getText();
            if ((pwd1 == null && pwd2 == null) || pwd2.equals(pwd1)) {
                errDispatcher.removeMessage("dockerHostFirstPwdField", dockerHostFirstPwdField);
                errDispatcher.removeMessage("dockerHostSecondPwdField", dockerHostSecondPwdField);
                setErrorMessage(null);
                setPageComplete(doValidate());
            } else {
                errDispatcher.addMessage("dockerHostSecondPwdField", AzureDockerValidationUtils.getDockerHostPasswordTip(), null, IMessageProvider.ERROR, dockerHostSecondPwdField);
                setErrorMessage("Invalid confirmation password");
                setPageComplete(false);
            }
        }
    });
    dockerHostNoSshRadioButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            dockerHostPwdLabel.setText("(Required)");
            dockerHostImportSSHTextField.setEnabled(false);
            dockerHostImportSSHBrowseButton.setEnabled(false);
            errDispatcher.removeMessage("dockerHostImportSSHTextField", dockerHostImportSSHTextField);
            setErrorMessage(null);
            setPageComplete(doValidate());
        }
    });
    dockerHostAutoSshRadioButton.setSelection(true);
    dockerHostAutoSshRadioButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            dockerHostPwdLabel.setText("(Optional)");
            dockerHostImportSSHTextField.setEnabled(false);
            dockerHostImportSSHBrowseButton.setEnabled(false);
            errDispatcher.removeMessage("dockerHostImportSSHTextField", dockerHostImportSSHTextField);
            setErrorMessage(null);
            setPageComplete(doValidate());
        }
    });
    dockerHostImportSshRadioButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            dockerHostPwdLabel.setText("(Optional)");
            dockerHostImportSSHTextField.setEnabled(true);
            dockerHostImportSSHBrowseButton.setEnabled(true);
            setPageComplete(doValidate());
        }
    });
    dockerHostImportSSHTextField.setEnabled(false);
    dockerHostImportSSHTextField.setToolTipText(AzureDockerValidationUtils.getDockerHostSshDirectoryTip());
    dockerHostImportSSHTextField.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent event) {
            if (AzureDockerValidationUtils.validateDockerHostSshDirectory(((Text) event.getSource()).getText())) {
                errDispatcher.removeMessage("dockerHostImportSSHTextField", dockerHostImportSSHTextField);
                setErrorMessage(null);
                setPageComplete(doValidate());
            } else {
                errDispatcher.addMessage("dockerHostImportSSHTextField", AzureDockerValidationUtils.getDockerHostSshDirectoryTip(), null, IMessageProvider.ERROR, dockerHostImportSSHTextField);
                setErrorMessage("SSH key files not found in the specified directory");
                setPageComplete(false);
            }
        }
    });
    dockerHostImportSSHBrowseButton.setEnabled(false);
    dockerHostImportSSHBrowseButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            DirectoryDialog directoryDialog = new DirectoryDialog(dockerHostImportSSHBrowseButton.getShell());
            directoryDialog.setText("Select SSH Keys Directory");
            directoryDialog.setFilterPath(System.getProperty("user.home"));
            String path = directoryDialog.open();
            if (path == null) {
                return;
            }
            dockerHostImportSSHTextField.setText(path);
            setPageComplete(doValidate());
        }
    });
    dockerDaemonPortTextField.setText(newHost.port);
    dockerDaemonPortTextField.setToolTipText(AzureDockerValidationUtils.getDockerHostPortTip());
    dockerDaemonPortTextField.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent event) {
            if (AzureDockerValidationUtils.validateDockerHostPort(((Text) event.getSource()).getText())) {
                errDispatcher.removeMessage("dockerDaemonPortTextField", dockerDaemonPortTextField);
                setErrorMessage(null);
                setPageComplete(doValidate());
            } else {
                errDispatcher.addMessage("dockerDaemonPortTextField", AzureDockerValidationUtils.getDockerHostPortTip(), null, IMessageProvider.ERROR, dockerDaemonPortTextField);
                setErrorMessage("Invalid Docker daemon port setting");
                setPageComplete(false);
            }
        }
    });
    dockerHostNoTlsRadioButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            dockerHostImportTLSTextField.setEnabled(false);
            dockerHostImportTLSBrowseButton.setEnabled(false);
            errDispatcher.removeMessage("dockerHostImportTLSTextField", dockerHostImportTLSTextField);
            setErrorMessage(null);
            setPageComplete(doValidate());
        }
    });
    dockerHostAutoTlsRadioButton.setSelection(true);
    dockerHostAutoTlsRadioButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            dockerHostImportTLSTextField.setEnabled(false);
            dockerHostImportTLSBrowseButton.setEnabled(false);
            errDispatcher.removeMessage("dockerHostImportTLSTextField", dockerHostImportTLSTextField);
            setErrorMessage(null);
            setPageComplete(doValidate());
        }
    });
    dockerHostImportTlsRadioButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            dockerHostImportTLSTextField.setEnabled(true);
            dockerHostImportTLSBrowseButton.setEnabled(true);
            setPageComplete(doValidate());
        }
    });
    dockerHostImportTLSTextField.setEnabled(false);
    dockerHostImportTLSTextField.setToolTipText(AzureDockerValidationUtils.getDockerHostTlsDirectoryTip());
    dockerHostImportTLSTextField.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent event) {
            if (AzureDockerValidationUtils.validateDockerHostTlsDirectory(((Text) event.getSource()).getText())) {
                errDispatcher.removeMessage("dockerHostImportTLSTextField", dockerHostImportTLSTextField);
                setErrorMessage(null);
                setPageComplete(doValidate());
            } else {
                errDispatcher.addMessage("dockerHostImportTLSTextField", AzureDockerValidationUtils.getDockerHostTlsDirectoryTip(), null, IMessageProvider.ERROR, dockerHostImportTLSTextField);
                setErrorMessage("TLS certificate files not found in the specified directory");
                setPageComplete(false);
            }
        }
    });
    dockerHostImportTLSBrowseButton.setEnabled(false);
    dockerHostImportTLSBrowseButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            DirectoryDialog directoryDialog = new DirectoryDialog(dockerHostImportTLSBrowseButton.getShell());
            directoryDialog.setText("Select TLS Certificate Directory");
            directoryDialog.setFilterPath(System.getProperty("user.home"));
            String path = directoryDialog.open();
            if (path == null) {
                return;
            }
            dockerHostImportTLSTextField.setText(path);
            setPageComplete(doValidate());
        }
    });
    dockerHostSaveCredsCheckBox.setSelection(true);
    dockerHostSaveCredsCheckBox.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            dockerHostNewKeyvaultTextField.setEnabled(dockerHostSaveCredsCheckBox.getSelection());
            setPageComplete(doValidate());
        }
    });
    dockerHostNewKeyvaultTextField.setText(newHost.certVault.name);
    dockerHostNewKeyvaultTextField.setToolTipText(AzureDockerValidationUtils.getDockerHostKeyvaultNameTip());
    dockerHostNewKeyvaultTextField.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent event) {
            if (AzureDockerValidationUtils.validateDockerHostKeyvaultName(((Text) event.getSource()).getText(), dockerManager, false)) {
                errDispatcher.removeMessage("dockerHostNewKeyvaultTextField", dockerHostNewKeyvaultTextField);
                setErrorMessage(null);
                setPageComplete(doValidate());
            } else {
                errDispatcher.addMessage("dockerHostNewKeyvaultTextField", AzureDockerValidationUtils.getDockerHostPortTip(), null, IMessageProvider.ERROR, dockerHostNewKeyvaultTextField);
                setErrorMessage("Invalid key vault name");
                setPageComplete(false);
            }
        }
    });
}
Also used : ModifyEvent(org.eclipse.swt.events.ModifyEvent) ModifyListener(org.eclipse.swt.events.ModifyListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) SelectionEvent(org.eclipse.swt.events.SelectionEvent) AzureDockerCertVault(com.microsoft.azure.docker.model.AzureDockerCertVault) Text(org.eclipse.swt.widgets.Text) DirectoryDialog(org.eclipse.swt.widgets.DirectoryDialog)

Example 73 with ModifyEvent

use of org.eclipse.swt.events.ModifyEvent in project azure-tools-for-java by Microsoft.

the class AzureConfigureDockerContainerStep method initUIMainContainer.

private void initUIMainContainer(Composite mainContainer) {
    dockerContainerNameTextField.setText(dockerImageDescription.dockerContainerName);
    dockerContainerNameTextField.setToolTipText(AzureDockerValidationUtils.getDockerContainerNameTip());
    dockerContainerNameTextField.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent event) {
            if (AzureDockerValidationUtils.validateDockerContainerName(((Text) event.getSource()).getText())) {
                errDispatcher.removeMessage("dockerContainerNameTextField", dockerContainerNameTextField);
                setErrorMessage(null);
                setPageComplete(doValidate());
            } else {
                errDispatcher.addMessage("dockerContainerNameTextField", AzureDockerValidationUtils.getDockerContainerNameTip(), null, IMessageProvider.ERROR, dockerContainerNameTextField);
                setErrorMessage("Invalid Docker container name");
                setPageComplete(false);
            }
        }
    });
    predefinedDockerfileRadioButton.setSelection(true);
    predefinedDockerfileRadioButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            dockerfileComboBox.setEnabled(true);
            customDockerfileTextField.setEnabled(false);
            customDockerfileBrowseButton.setEnabled(false);
            errDispatcher.removeMessage("customDockerfileTextField", customDockerfileTextField);
            setErrorMessage(null);
            setPageComplete(doValidate());
        }
    });
    int idx = 0;
    boolean selected = false;
    for (KnownDockerImages predefinedImage : dockerManager.getDefaultDockerImages()) {
        // Add predefined images that can run .WAR as default
        if (!predefinedImage.isCanRunJarFile()) {
            dockerfileComboBox.add(predefinedImage.getName());
            dockerfileComboBox.setData(predefinedImage.getName(), predefinedImage);
            if (dockerImageDescription.predefinedDockerfile != null && dockerImageDescription.predefinedDockerfile.equals(predefinedImage)) {
                dockerfileComboBox.select(idx);
                selected = true;
            }
            idx++;
        }
    }
    if (!selected) {
        dockerfileComboBox.select(0);
    }
    dockerfileComboBox.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            dockerContainerPortSettings.setText(getDefaultPortMapping((KnownDockerImages) dockerfileComboBox.getData(dockerfileComboBox.getText())));
            setPageComplete(doValidate());
        }
    });
    customDockerfileRadioButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            dockerfileComboBox.setEnabled(false);
            customDockerfileTextField.setEnabled(true);
            customDockerfileBrowseButton.setEnabled(true);
            setPageComplete(doValidate());
        }
    });
    customDockerfileTextField.setToolTipText(AzureDockerValidationUtils.getDockerfilePathTip());
    customDockerfileTextField.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent event) {
            if (AzureDockerValidationUtils.validateDockerfilePath(((Text) event.getSource()).getText())) {
                errDispatcher.removeMessage("customDockerfileTextField", customDockerfileTextField);
                setErrorMessage(null);
                setPageComplete(doValidate());
            } else {
                errDispatcher.addMessage("customDockerfileTextField", AzureDockerValidationUtils.getDockerfilePathTip(), null, IMessageProvider.ERROR, customDockerfileTextField);
                setErrorMessage("Invalid Dockerfile location");
                setPageComplete(false);
            }
        }
    });
    customDockerfileBrowseButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            FileDialog fileDialog = new FileDialog(customDockerfileBrowseButton.getShell(), SWT.OPEN);
            fileDialog.setText("Select Custom Dockerfile");
            fileDialog.setFilterPath(System.getProperty("user.home"));
            fileDialog.setFilterExtensions(new String[] { "Dockerfile", "*.*" });
            String path = fileDialog.open();
            if (path == null) {
                return;
            }
            customDockerfileTextField.setText(path);
            setPageComplete(doValidate());
        }
    });
    dockerContainerPortSettings.setText(getDefaultPortMapping((KnownDockerImages) dockerfileComboBox.getData(dockerfileComboBox.getText())));
    dockerContainerPortSettings.setToolTipText(AzureDockerValidationUtils.getDockerPortSettingsTip());
    dockerContainerPortSettings.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent event) {
            if (AzureDockerValidationUtils.validateDockerPortSettings(((Text) event.getSource()).getText()) != null) {
                errDispatcher.removeMessage("dockerContainerPortSettings", dockerContainerPortSettings);
                setErrorMessage(null);
                setPageComplete(doValidate());
            } else {
                errDispatcher.addMessage("dockerContainerPortSettings", AzureDockerValidationUtils.getDockerPortSettingsTip(), null, IMessageProvider.ERROR, dockerContainerPortSettings);
                setErrorMessage("Invalid Docker container port settings");
                setPageComplete(false);
            }
        }
    });
}
Also used : ModifyEvent(org.eclipse.swt.events.ModifyEvent) ModifyListener(org.eclipse.swt.events.ModifyListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Text(org.eclipse.swt.widgets.Text) KnownDockerImages(com.microsoft.azure.docker.model.KnownDockerImages) FileDialog(org.eclipse.swt.widgets.FileDialog)

Example 74 with ModifyEvent

use of org.eclipse.swt.events.ModifyEvent in project azure-tools-for-java by Microsoft.

the class AzureSelectDockerHostPage method initUIMainContainer.

private void initUIMainContainer(Composite mainContainer) {
    dockerImageNameTextField.setText(dockerImageDescription.dockerImageName);
    dockerImageNameTextField.setToolTipText(AzureDockerValidationUtils.getDockerImageNameTip());
    dockerImageNameTextField.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent event) {
            if (AzureDockerValidationUtils.validateDockerImageName(((Text) event.getSource()).getText())) {
                errDispatcher.removeMessage("dockerImageNameTextField", dockerImageNameTextField);
                setErrorMessage(null);
                setPageComplete(doValidate());
            } else {
                errDispatcher.addMessage("dockerImageNameTextField", AzureDockerValidationUtils.getDockerImageNameTip(), null, IMessageProvider.ERROR, dockerImageNameTextField);
                setErrorMessage("Invalid Docker image name");
                setPageComplete(false);
            }
        }
    });
    String artifactPath;
    if (project != null) {
        try {
            String projectName = project.getName();
            artifactPath = project.getLocation() + "/" + projectName + ".war";
        } catch (Exception ignored) {
            artifactPath = "";
        }
    } else {
        artifactPath = "";
    }
    if (artifactPath == null || artifactPath.isEmpty() || !Files.isRegularFile(Paths.get(artifactPath))) {
        errDispatcher.addMessage("dockerArtifactPathTextField", AzureDockerValidationUtils.getDockerArtifactPathTip(), null, IMessageProvider.ERROR, dockerArtifactPathTextField);
        setErrorMessage("Invalid artifact path");
    } else {
        dockerArtifactPathTextField.setText(artifactPath);
    }
    dockerArtifactPathTextField.setToolTipText(AzureDockerValidationUtils.getDockerArtifactPathTip());
    dockerArtifactPathTextField.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent event) {
            if (AzureDockerValidationUtils.validateDockerArtifactPath(((Text) event.getSource()).getText())) {
                errDispatcher.removeMessage("dockerArtifactPathTextField", dockerArtifactPathTextField);
                String artifactFileName = new File(((Text) event.getSource()).getText()).getName();
                wizard.setPredefinedDockerfileOptions(artifactFileName);
                setErrorMessage(null);
                setPageComplete(doValidate());
            } else {
                errDispatcher.addMessage("dockerArtifactPathTextField", AzureDockerValidationUtils.getDockerArtifactPathTip(), null, IMessageProvider.ERROR, dockerArtifactPathTextField);
                setErrorMessage("Invalid artifact path");
                setPageComplete(false);
            }
        }
    });
    dockerArtifactPathBrowseButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            FileDialog fileDialog = new FileDialog(dockerArtifactPathBrowseButton.getShell(), SWT.OPEN);
            fileDialog.setText("Select Artifact .WAR or .JAR");
            fileDialog.setFilterPath(System.getProperty("user.home"));
            fileDialog.setFilterExtensions(new String[] { "*.war;*.jar", "*.jar", "*.*" });
            String path = fileDialog.open();
            if (path == null || (!path.toLowerCase().contains(".war") && !path.toLowerCase().contains(".jar"))) {
                return;
            }
            dockerArtifactPathTextField.setText(path);
            String artifactFileName = new File(path).getName();
            wizard.setPredefinedDockerfileOptions(artifactFileName);
            setPageComplete(doValidate());
        }
    });
    TableViewerColumn colHostName = createTableViewerColumn(dockerHostsTableViewer, "Name", 150, 1);
    colHostName.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            return ((DockerHost) element).name;
        }
    });
    TableViewerColumn colHostState = createTableViewerColumn(dockerHostsTableViewer, "State", 80, 2);
    colHostState.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            DockerHost dockerHost = (DockerHost) element;
            return dockerHost.hostVM.state != null ? dockerHost.hostVM.state.toString() : "TO_BE_CREATED";
        }
    });
    TableViewerColumn colHostOS = createTableViewerColumn(dockerHostsTableViewer, "OS", 200, 3);
    colHostOS.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            return ((DockerHost) element).hostOSType.toString();
        }
    });
    TableViewerColumn colHostApiUrl = createTableViewerColumn(dockerHostsTableViewer, "API URL", 250, 4);
    colHostApiUrl.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            return ((DockerHost) element).apiUrl.toString();
        }
    });
    dockerHostsTableViewer.setContentProvider(new ArrayContentProvider());
    dockerHostsList = new ArrayList<>();
    dockerHostsTableViewer.setInput(dockerHostsList);
    refreshDockerHostsTable(mainContainer);
    if (!dockerHostsList.isEmpty()) {
        if (dockerHostsTableSelection == null) {
            dockerHostsTable.select(0);
            dockerHostsTable.getItem(0).setChecked(true);
            dockerHostsTableSelection = new DockerHostsTableSelection();
            dockerHostsTableSelection.row = 0;
            dockerHostsTableSelection.host = (DockerHost) dockerHostsTable.getItem(0).getData();
        } else {
            dockerHostsTable.select(dockerHostsTableSelection.row);
            dockerHostsTable.getItem(dockerHostsTableSelection.row).setChecked(true);
        }
    } else {
        dockerHostsTableSelection = null;
        setPageComplete(false);
    }
    dockerHostsTable.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            if (e.detail == SWT.CHECK) {
                DockerHost dockerHost = (DockerHost) ((TableItem) e.item).getData();
                if (dockerHostsTableSelection == null || dockerHostsTableSelection.host != dockerHost) {
                    dockerHostsTableSelection = new DockerHostsTableSelection();
                    dockerHostsTableSelection.row = dockerHostsTable.indexOf((TableItem) e.item);
                    dockerHostsTableSelection.host = dockerHost;
                    for (TableItem tableItem : dockerHostsTable.getItems()) {
                        if (tableItem != ((TableItem) e.item) && tableItem.getChecked()) {
                            tableItem.setChecked(false);
                        }
                    }
                    dockerHostsTable.redraw();
                } else {
                    dockerHostsTableSelection = null;
                }
                setPageComplete(doValidate());
            }
        }
    });
    dockerHostsRefreshButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            AzureDockerUIResources.updateAzureResourcesWithProgressDialog(mainContainer.getShell(), project);
            refreshDockerHostsTable(mainContainer);
            setPageComplete(doValidate());
            sendButtonClickedTelemetry(REFRESH);
        }
    });
    dockerHostsViewButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            int idx = dockerHostsTable.getSelectionIndex();
            if (idx >= 0 && dockerHostsTable.getItem(idx) != null) {
                DockerHost dockerHost = (DockerHost) dockerHostsTable.getItem(dockerHostsTable.getSelectionIndex()).getData();
                if (dockerHost != null) {
                    AzureViewDockerDialog viewDockerDialog = new AzureViewDockerDialog(mainContainer.getShell(), project, dockerHost, dockerManager);
                    viewDockerDialog.open();
                    if (viewDockerDialog.getInternalExitCode() == AzureViewDockerDialog.UPDATE_EXIT_CODE) {
                        if (dockerHost != null && !dockerHost.isUpdating) {
                            AzureDockerUIResources.updateDockerHost(PluginUtil.getParentShell(), project, new EditableDockerHost(dockerHost), dockerManager, true);
                        } else {
                            PluginUtil.displayErrorDialog(mainContainer.getShell(), "Error: Invalid Edit Selection", "The selected Docker host can not be edited at this time!");
                        }
                    }
                    setPageComplete(doValidate());
                }
            }
            sendButtonClickedTelemetry(VIEW);
        }
    });
    dockerHostsAddButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            AzureNewDockerWizard newDockerWizard = new AzureNewDockerWizard(project, dockerManager);
            WizardDialog createNewDockerHostDialog = new AzureWizardDialog(mainContainer.getShell(), newDockerWizard);
            if (createNewDockerHostDialog.open() == Window.OK) {
                DockerHost host = newDockerWizard.getDockerHost();
                dockerImageDescription.host = host;
                dockerImageDescription.hasNewDockerHost = true;
                dockerImageDescription.sid = host.sid;
                AzureDockerPreferredSettings dockerPrefferedSettings = dockerManager.getDockerPreferredSettings();
                if (dockerPrefferedSettings == null) {
                    dockerPrefferedSettings = new AzureDockerPreferredSettings();
                }
                dockerPrefferedSettings.region = host.hostVM.region;
                dockerPrefferedSettings.vmSize = host.hostVM.vmSize;
                dockerPrefferedSettings.vmOS = host.hostOSType.name();
                dockerManager.setDockerPreferredSettings(dockerPrefferedSettings);
                dockerHostsList.add(0, host);
                dockerHostsTable.setEnabled(false);
                dockerHostsRefreshButton.setEnabled(false);
                dockerHostsAddButton.setEnabled(false);
                dockerHostsDeleteButton.setEnabled(false);
                dockerHostsEditButton.setEnabled(false);
                dockerHostsTableViewer.refresh();
                dockerHostsTable.getItem(0).setChecked(true);
                dockerHostsTable.select(0);
            }
            setPageComplete(doValidate());
            sendButtonClickedTelemetry(ADD);
        }
    });
    dockerHostsDeleteButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            //dockerHostsList
            int idx = dockerHostsTable.getSelectionIndex();
            if (idx >= 0 && dockerHostsTable.getItem(idx) != null) {
                DockerHost deleteHost = (DockerHost) dockerHostsTable.getItem(idx).getData();
                if (deleteHost != null) {
                    Azure azureClient = dockerManager.getSubscriptionsMap().get(deleteHost.sid).azureClient;
                    int option = AzureDockerUIResources.deleteAzureDockerHostConfirmationDialog(mainContainer.getShell(), azureClient, deleteHost);
                    if (option != 1 && option != 2) {
                        if (AzureDockerUtils.DEBUG)
                            System.out.format("User canceled delete Docker host op: %d\n", option);
                        return;
                    }
                    dockerHostsList.remove(deleteHost);
                    if (dockerHostsTableSelection != null && dockerHostsTableSelection.row == idx) {
                        dockerHostsTableSelection = null;
                    }
                    dockerHostsTableViewer.refresh();
                    AzureDockerUIResources.deleteDockerHost(mainContainer.getShell(), project, azureClient, deleteHost, option, new Runnable() {

                        @Override
                        public void run() {
                            dockerManager.getDockerHostsList().remove(deleteHost);
                            dockerManager.refreshDockerHostDetails();
                            DefaultLoader.getIdeHelper().invokeLater(new Runnable() {

                                @Override
                                public void run() {
                                    refreshDockerHostsTable(mainContainer);
                                }
                            });
                        }
                    });
                }
                setPageComplete(doValidate());
            }
            sendButtonClickedTelemetry(DELETE);
        }
    });
    dockerHostsEditButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            int idx = dockerHostsTable.getSelectionIndex();
            if (idx >= 0 && dockerHostsTable.getItem(idx) != null) {
                DockerHost updateHost = (DockerHost) dockerHostsTable.getItem(idx).getData();
                if (updateHost != null && !updateHost.isUpdating) {
                    AzureDockerUIResources.updateDockerHost(PluginUtil.getParentShell(), project, new EditableDockerHost(updateHost), dockerManager, true);
                } else {
                    PluginUtil.displayErrorDialog(mainContainer.getShell(), "Error: Invalid Edit Selection", "The selected Docker host can not be edited at this time!");
                }
            }
            setPageComplete(doValidate());
            sendButtonClickedTelemetry(EDIT);
        }
    });
}
Also used : ModifyListener(org.eclipse.swt.events.ModifyListener) EditableDockerHost(com.microsoft.azure.docker.model.EditableDockerHost) TableItem(org.eclipse.swt.widgets.TableItem) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) ModifyEvent(org.eclipse.swt.events.ModifyEvent) AzureWizardDialog(com.microsoft.azuretools.core.components.AzureWizardDialog) SelectionEvent(org.eclipse.swt.events.SelectionEvent) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn) Azure(com.microsoft.azure.management.Azure) AzureNewDockerWizard(com.microsoft.azuretools.docker.ui.wizards.createhost.AzureNewDockerWizard) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Text(org.eclipse.swt.widgets.Text) AzureDockerPreferredSettings(com.microsoft.azure.docker.model.AzureDockerPreferredSettings) AzureViewDockerDialog(com.microsoft.azuretools.docker.ui.dialogs.AzureViewDockerDialog) EditableDockerHost(com.microsoft.azure.docker.model.EditableDockerHost) DockerHost(com.microsoft.azure.docker.model.DockerHost) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) File(java.io.File) FileDialog(org.eclipse.swt.widgets.FileDialog) WizardDialog(org.eclipse.jface.wizard.WizardDialog) AzureWizardDialog(com.microsoft.azuretools.core.components.AzureWizardDialog)

Example 75 with ModifyEvent

use of org.eclipse.swt.events.ModifyEvent in project azure-tools-for-java by Microsoft.

the class AzureExportDockerTlsKeysDialog method createDialogArea.

/**
	 * Create contents of the dialog.
	 * @param parent
	 */
@Override
protected Control createDialogArea(Composite parent) {
    setTitle("Export TLS Certificates");
    setMessage(pathToolTip);
    Composite area = (Composite) super.createDialogArea(parent);
    Composite mainContainer = new Composite(area, SWT.NONE);
    mainContainer.setLayout(new GridLayout(2, false));
    GridData gd_mainContainer = new GridData(GridData.FILL_BOTH);
    gd_mainContainer.widthHint = 524;
    mainContainer.setLayoutData(gd_mainContainer);
    exportTlsPathTextField = new Text(mainContainer, SWT.BORDER);
    exportTlsPathTextField.setToolTipText(pathToolTip);
    exportTlsPathTextField.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent event) {
            path = (((Text) event.getSource()).getText());
            if (path != null && Files.isDirectory(Paths.get(path))) {
                errDispatcher.removeMessage("exportTlsPathTextField", exportTlsPathTextField);
                setErrorMessage(null);
            } else {
                errDispatcher.addMessage("exportTlsPathTextField", pathToolTip, null, IMessageProvider.ERROR, exportTlsPathTextField);
                setErrorMessage("Invalid directory path");
            }
        }
    });
    GridData gd_exportTlsPathTextField = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);
    gd_exportTlsPathTextField.widthHint = 380;
    gd_exportTlsPathTextField.verticalIndent = 5;
    gd_exportTlsPathTextField.horizontalIndent = 5;
    exportTlsPathTextField.setLayoutData(gd_exportTlsPathTextField);
    Button exportTlsPathBrowseButton = new Button(mainContainer, SWT.NONE);
    exportTlsPathBrowseButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            DirectoryDialog directoryDialog = new DirectoryDialog(exportTlsPathTextField.getShell());
            directoryDialog.setText("Select TLS Certificates Directory");
            directoryDialog.setFilterPath(System.getProperty("user.home"));
            String pathSelected = directoryDialog.open();
            if (pathSelected == null) {
                return;
            }
            path = pathSelected;
            exportTlsPathTextField.setText(path);
        }
    });
    GridData gd_exportTlsPathBrowseButton = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
    gd_exportTlsPathBrowseButton.verticalIndent = 5;
    exportTlsPathBrowseButton.setLayoutData(gd_exportTlsPathBrowseButton);
    exportTlsPathBrowseButton.setText("Browse...");
    Label lblNote = new Label(mainContainer, SWT.NONE);
    GridData gd_lblNote = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
    gd_lblNote.verticalIndent = 5;
    gd_lblNote.horizontalIndent = 5;
    lblNote.setLayoutData(gd_lblNote);
    lblNote.setText("Note:");
    new Label(mainContainer, SWT.NONE);
    Label lblAnyExisting = new Label(mainContainer, SWT.NONE);
    GridData gd_lblAnyExisting = new GridData(SWT.LEFT, SWT.CENTER, false, false, 2, 1);
    gd_lblAnyExisting.horizontalIndent = 20;
    lblAnyExisting.setLayoutData(gd_lblAnyExisting);
    lblAnyExisting.setText("Any existing \"ca.pem\", \"ca-key.pem\", \"cert.pem\",\"key.pem\", \"server.pem\" and \"server-key.pem\"");
    Label lblWillBeOverwritten = new Label(mainContainer, SWT.NONE);
    GridData gd_lblWillBeOverwritten = new GridData(SWT.LEFT, SWT.CENTER, false, false, 2, 1);
    gd_lblWillBeOverwritten.horizontalIndent = 20;
    lblWillBeOverwritten.setLayoutData(gd_lblWillBeOverwritten);
    lblWillBeOverwritten.setText("certificate files in the selected directory will be overwritten!");
    FormToolkit toolkit = new FormToolkit(mainContainer.getDisplay());
    toolkit.getHyperlinkGroup().setHyperlinkUnderlineMode(HyperlinkSettings.UNDERLINE_HOVER);
    managedForm = new ManagedForm(mainContainer);
    errMsgForm = managedForm.getForm();
    errMsgForm.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 2, 1));
    errMsgForm.setBackground(mainContainer.getBackground());
    errDispatcher = managedForm.getMessageManager();
    return area;
}
Also used : Composite(org.eclipse.swt.widgets.Composite) ModifyListener(org.eclipse.swt.events.ModifyListener) FormToolkit(org.eclipse.ui.forms.widgets.FormToolkit) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) Text(org.eclipse.swt.widgets.Text) GridLayout(org.eclipse.swt.layout.GridLayout) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Button(org.eclipse.swt.widgets.Button) ManagedForm(org.eclipse.ui.forms.ManagedForm) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) DirectoryDialog(org.eclipse.swt.widgets.DirectoryDialog)

Aggregations

ModifyEvent (org.eclipse.swt.events.ModifyEvent)1196 ModifyListener (org.eclipse.swt.events.ModifyListener)1191 Text (org.eclipse.swt.widgets.Text)814 Label (org.eclipse.swt.widgets.Label)784 SelectionEvent (org.eclipse.swt.events.SelectionEvent)701 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)627 GridData (org.eclipse.swt.layout.GridData)595 Button (org.eclipse.swt.widgets.Button)572 Composite (org.eclipse.swt.widgets.Composite)563 GridLayout (org.eclipse.swt.layout.GridLayout)481 FormAttachment (org.eclipse.swt.layout.FormAttachment)347 FormData (org.eclipse.swt.layout.FormData)347 FormLayout (org.eclipse.swt.layout.FormLayout)340 Event (org.eclipse.swt.widgets.Event)324 Listener (org.eclipse.swt.widgets.Listener)316 Shell (org.eclipse.swt.widgets.Shell)307 Display (org.eclipse.swt.widgets.Display)294 ShellEvent (org.eclipse.swt.events.ShellEvent)285 ShellAdapter (org.eclipse.swt.events.ShellAdapter)283 Group (org.eclipse.swt.widgets.Group)245