Example usage for org.eclipse.jface.viewers ListViewer getList

List of usage examples for org.eclipse.jface.viewers ListViewer getList

Introduction

In this page you can find the example usage for org.eclipse.jface.viewers ListViewer getList.

Prototype

public org.eclipse.swt.widgets.List getList() 

Source Link

Document

Returns this list viewer's list control.

Usage

From source file:application.GUI.java

/**
 * Create contents of the window.//from  w ww.  j  a  v a  2 s  . c  o  m
 */
protected void createContents() {

    // Check license
    // System.out.println("Initiating...");

    //      licenseChecker = new LicenseChecker();
    //      if (!licenseChecker.checkLicense()) {
    //         shell = new Shell();
    //         shell.setSize(SHELL_WIDTH, SHELL_HEIGHT);
    //         shell.setText(PROGRAM_NAME);
    //
    //         lblLicense = new Label(shell, SWT.NONE);
    //         lblLicense
    //               .setText("License check failed, contact Uldrer for further information.");
    //         lblLicense.setBounds(200, 200, 700, 424);
    //         FontData[] fontData = lblLicense.getFont().getFontData();
    //         for (int i = 0; i < fontData.length; ++i) {
    //            fontData[i].setHeight(18);
    //         }
    //         final Font newFont = new Font(shell.getDisplay(), fontData);
    //         lblLicense.setFont(newFont);
    //
    //         // Since you created the font, you must dispose it
    //         lblLicense.addDisposeListener(new DisposeListener() {
    //            public void widgetDisposed(DisposeEvent e) {
    //               newFont.dispose();
    //            }
    //         });
    //
    //         return;
    //      }

    ConfigInfo config = new ConfigInfo();
    String configFile = "config.xml";
    ConfigLoader configLoader = new ConfigLoader();
    configLoader.readConfig(configFile, config);

    if (config.countryIds.isEmpty()) {
        System.out.println("No country ids specified in config.xml, exiting.");
        return;
    }

    dmgRetriever = new DamageRetriever(config.countryIds, config.muIds);
    battles = new ArrayList<BattleInfo>();

    shell = new Shell();
    shell.setSize(SHELL_WIDTH, SHELL_HEIGHT);
    shell.setText(PROGRAM_NAME);

    TextViewer textViewer = new TextViewer(shell, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
    resultText = textViewer.getTextWidget();
    resultText.setEditable(false);
    resultText.setBounds(370, 220, 600, 424);
    resultText.setText(WEIGHT_EXPLANATION + "Retrieving MU-Member information...");

    progressBar = new ProgressBar(shell, SWT.NONE);
    progressBar.setBounds(10, 422, 170, 17);

    Label lblMembers = new Label(shell, SWT.NONE);
    lblMembers.setText("Members");
    lblMembers.setBounds(MEMBER_START_Y, 52, 50, 15);

    lblMuMembers = new Label(shell, SWT.NONE);
    lblMuMembers.setText("");
    lblMuMembers.setBounds(MEMBER_START_Y + lblMembers.getBounds().width + TEXT_SEPARATION, 52, 250, 15);

    ListViewer listviewer_2 = new ListViewer(shell, SWT.BORDER | SWT.V_SCROLL);
    memberList = listviewer_2.getList();
    memberList.setBounds(MEMBER_START_Y, 93 + 2 * TEXT_HEIGHT_SEPARATION, MEMBER_LIST_WIDTH, 68);
    memberList.getVerticalBar().addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            int selection = memberList.getVerticalBar().getSelection();
            memberBattleDmgList.setTopIndex(selection);
            memberT2DmgList.setTopIndex(selection);
            memberEnemyDmgList.setTopIndex(selection);
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            int selection = memberList.getVerticalBar().getSelection();
            memberBattleDmgList.setTopIndex(selection);
            memberT2DmgList.setTopIndex(selection);
            memberEnemyDmgList.setTopIndex(selection);
        }

    });

    ListViewer listviewer_3 = new ListViewer(shell, SWT.BORDER);
    memberBattleDmgList = listviewer_3.getList();
    memberBattleDmgList.setBounds(MEMBER_START_Y + MEMBER_LIST_WIDTH, 93 + 2 * TEXT_HEIGHT_SEPARATION,
            DMG_LIST_WIDTH, 68);

    ListViewer listviewer_4 = new ListViewer(shell, SWT.BORDER);
    memberT2DmgList = listviewer_4.getList();
    memberT2DmgList.setBounds(MEMBER_START_Y + DMG_LIST_WIDTH + MEMBER_LIST_WIDTH,
            93 + 2 * TEXT_HEIGHT_SEPARATION, DMG_LIST_WIDTH, 68);

    ListViewer listviewer_5 = new ListViewer(shell, SWT.BORDER);
    memberEnemyDmgList = listviewer_5.getList();
    memberEnemyDmgList.setBounds(MEMBER_START_Y + 2 * DMG_LIST_WIDTH + MEMBER_LIST_WIDTH,
            93 + 2 * TEXT_HEIGHT_SEPARATION, DMG_LIST_WIDTH, 68);

    Label lblMemberNames = new Label(shell, SWT.NONE);
    lblMemberNames.setText("Name");
    lblMemberNames.setBounds(MEMBER_START_Y, 72 + TEXT_HEIGHT_SEPARATION, MEMBER_LIST_WIDTH, 15);

    Label lblMemberBattleDmg = new Label(shell, SWT.NONE);
    lblMemberBattleDmg.setText("Battle Damage");
    lblMemberBattleDmg.setBounds(MEMBER_START_Y + MEMBER_LIST_WIDTH, 72 + TEXT_HEIGHT_SEPARATION,
            DMG_LIST_WIDTH, 15);

    Label lblMemberT2Dmg = new Label(shell, SWT.NONE);
    lblMemberT2Dmg.setText("T2 Damage");
    lblMemberT2Dmg.setBounds(MEMBER_START_Y + DMG_LIST_WIDTH + MEMBER_LIST_WIDTH, 72 + TEXT_HEIGHT_SEPARATION,
            DMG_LIST_WIDTH, 15);

    Label lblMemberEnemyDmg = new Label(shell, SWT.NONE);
    lblMemberEnemyDmg.setText("Damage for enemy");
    lblMemberEnemyDmg.setBounds(MEMBER_START_Y + 2 * DMG_LIST_WIDTH + MEMBER_LIST_WIDTH,
            72 + TEXT_HEIGHT_SEPARATION, DMG_LIST_WIDTH + 20, 15);

    btnGetDamage = new Button(shell, SWT.NONE);
    btnGetDamage.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {

            if (!retrievingData) {
                retrievingData = true;
                progressBar.setSelection(0);
                dmgRetriever.SetBattles(battles);

                retrieveThread = new Thread(dmgRetriever);
                retrieveThread.start();
            } else {
                resultText.setText(WEIGHT_EXPLANATION + "Please wait. Retrieving API data.");
            }
        }
    });
    btnGetDamage.setBounds(10, 457, 100, 25);
    btnGetDamage.setText("Get damage");
    btnGetDamage.setEnabled(false);

    muListViewer = new StringListViewer(shell, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
    muList = muListViewer.getList();
    muList.setBounds(263, 93 + 2 * TEXT_HEIGHT_SEPARATION, 187, 68);
    muList.setItems(dmgRetriever.getMilitaryUnitInfo());
    muListViewer.addSelectionChangedListener(new ISelectionChangedListener() {
        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            String mu = muListViewer.getStringSelection();
            currentlySelectedMu = mu;
            lblMuMembers.setText(mu);
            MemberStorage mbStore = dmgRetriever.getMilitaryUnitMemberInfo(mu);
            memberList.setItems(mbStore.getNames());
            memberBattleDmgList.setItems(mbStore.getBattelDmg());
            memberT2DmgList.setItems(mbStore.getT2Dmg());
            memberEnemyDmgList.setItems(mbStore.getEnemyDmg());
        }
    });

    final Color myColor = new Color(Display.getCurrent(), 255, 0, 0);
    memberEnemyDmgList.setForeground(myColor);
    memberEnemyDmgList.addDisposeListener(new DisposeListener() {
        public void widgetDisposed(DisposeEvent e) {
            myColor.dispose();
        }
    });

    Label lblApplication = new Label(shell, SWT.NONE);
    lblApplication.setFont(SWTResourceManager.getFont("Segoe UI", 12, SWT.NORMAL));
    lblApplication.setBounds(SHELL_WIDTH / 2 - 100, 10, 330, 50);
    lblApplication.setText(PROGRAM_NAME);

    Label lblBattleIds = new Label(shell, SWT.NONE);
    lblBattleIds.setBounds(26, 72, 150, 15);
    lblBattleIds.setText("Battle ids selected");

    Label lblMus = new Label(shell, SWT.NONE);
    lblMus.setText("Military Units");
    lblMus.setBounds(263, 72, 100, 15);

    battleId = new Text(shell, SWT.BORDER);
    battleId.setBounds(26, 204 + 2 * TEXT_HEIGHT_SEPARATION, 92, 23);

    ListViewer listViewer = new ListViewer(shell, SWT.BORDER | SWT.V_SCROLL);
    battleIdList = listViewer.getList();
    battleIdList.setBounds(27, 93 + 2 * TEXT_HEIGHT_SEPARATION, 187, 68);

    defendingChecked = false;
    Button btnCheckDefender = new Button(shell, SWT.CHECK);
    btnCheckDefender.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            defendingChecked = !defendingChecked;
        }
    });
    btnCheckDefender.setBounds(26, 230 + 2 * TEXT_HEIGHT_SEPARATION, 91, 25);
    btnCheckDefender.setText("Defenders");

    Button btnAddBattleId = new Button(shell, SWT.NONE);
    btnAddBattleId.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {

            String bIdText = battleId.getText();
            int bId = 0;
            boolean defender = defendingChecked;

            if (bIdText.equals("")) {
                return;
            }

            try {
                bId = Integer.parseInt(bIdText);
            } catch (NumberFormatException exception) {
                battleId.setText("");
                return;
            }

            System.out.println("Battle id: " + bId + " added.");
            battleId.setText("");

            battles.add(new BattleInfo(bId, defender));
            String[] info = new String[battles.size()];
            int j = 0;
            for (BattleInfo battle : battles) {
                info[j] = battle.getId().toString() + "     ";
                if (battle.isDefender()) {
                    info[j] += "defending side";
                } else {
                    info[j] += "attacking side";
                }
                j++;
            }

            battleIdList.setItems(info);
        }
    });
    btnAddBattleId.setBounds(140, 202 + 2 * TEXT_HEIGHT_SEPARATION, 91, 25);
    btnAddBattleId.setText("Add");

    Label lblBattleId = new Label(shell, SWT.NONE);
    lblBattleId.setBounds(27, 183 + TEXT_HEIGHT_SEPARATION, 91, 15);
    lblBattleId.setText("Battle id");

    weightValue = new Text(shell, SWT.BORDER);
    weightValue.addListener(SWT.KeyUp, new Listener() {
        public void handleEvent(Event e) {
            if (!retrievingData) {
                int selectionIndex = btnChooseWeight.getSelectionIndex();
                String text = weightValue.getText();
                double val;
                try {
                    val = Double.parseDouble(text);
                    if (val >= 0 && val <= 1) {
                        dmgRetriever.setWeight(selectionIndex, val);
                    }
                } catch (NumberFormatException exception) {
                    // Not correctly set value
                }
            }
        }
    });
    weightValue.setBounds(26, 264 + 2 * TEXT_HEIGHT_SEPARATION, 92, 23);

    btnChooseWeight = new Combo(shell, SWT.DROP_DOWN | SWT.READ_ONLY);
    btnChooseWeight.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {

            int selecteionIndex = btnChooseWeight.getSelectionIndex();

            String[] weights = dmgRetriever.getWeights();
            weightValue.setText(weights[selecteionIndex]);

        }
    });
    btnChooseWeight.setBounds(140, 264 + 2 * TEXT_HEIGHT_SEPARATION, 170, 23);
    btnChooseWeight.setItems(COMBO_WEIGHTS);
    btnChooseWeight.select(0);
    weightValue.setText(dmgRetriever.getWeights()[0]);

    Label versionLabel = new Label(shell, SWT.COLOR_DARK_GRAY);
    versionLabel.setBounds(10, SHELL_HEIGHT - 80, 300, 15);
    versionLabel.setText("Created by Uldrer.                    Version: " + PROGRAM_VERSION);

    Button btnRemoveBattleId = new Button(shell, SWT.NONE);
    btnRemoveBattleId.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {

            String bIdText = battleId.getText();
            int bId = 0;

            if (bIdText.equals("")) {
                String[] idsSelected = battleIdList.getSelection();
                if (idsSelected.length > 0) {
                    bIdText = idsSelected[0];
                } else {
                    return;
                }
            }

            try {
                String[] tokens = bIdText.split(" ");
                bId = Integer.parseInt(tokens[0]);
            } catch (NumberFormatException exception) {
                battleId.setText("");
                return;
            }

            int index = battles.indexOf(new BattleInfo(bId));
            if (index == -1) {
                battleId.setText("");
                return;
            }
            battles.remove(index);
            String[] info = new String[battles.size()];
            int j = 0;
            for (BattleInfo battle : battles) {
                info[j] = battle.getId().toString() + "     ";
                if (battle.isDefender()) {
                    info[j] += "defending side";
                } else {
                    info[j] += "attacking side";
                }
                j++;
            }

            battleIdList.setItems(info);
            System.out.println("Battle id: " + bId + " removed.");
            battleId.setText("");
        }
    });
    btnRemoveBattleId.setBounds(240, 202 + 2 * TEXT_HEIGHT_SEPARATION, 91, 25);
    btnRemoveBattleId.setText("Remove");

    dmgRetriever.addProgressListener(new ProgressListener() {
        @Override
        public void progressEvent(ProgressEvent e) {

            double percent = e.getPercent();

            if (percent == 1) {

                MemberStorage mbStore;
                switch (e.getType()) {
                case BATTLE:
                    // all done
                    String result = dmgRetriever.getResult();

                    doResultTextUpdate(resultText, result);
                    retrievingData = false;
                    mbStore = dmgRetriever.getMilitaryUnitMemberInfo(currentlySelectedMu);
                    doListUpdate(memberList, mbStore.getNames());
                    doListUpdate(memberBattleDmgList, mbStore.getBattelDmg());
                    doListUpdate(memberT2DmgList, mbStore.getT2Dmg());
                    doListUpdate(memberEnemyDmgList, mbStore.getEnemyDmg());
                    doProgressBarUpdate(progressBar, percent);

                    break;
                case MU:
                    doResultTextUpdate(resultText, "Finished parsing mu members.");
                    mbStore = dmgRetriever.getMilitaryUnitMemberInfo(currentlySelectedMu);
                    doListUpdate(memberList, mbStore.getNames());
                    doListUpdate(memberBattleDmgList, mbStore.getBattelDmg());
                    doListUpdate(memberT2DmgList, mbStore.getT2Dmg());
                    doListUpdate(memberEnemyDmgList, mbStore.getEnemyDmg());
                    setDmgBtnEnabled(btnGetDamage, true);
                    break;

                }
            } else {
                doProgressBarUpdate(progressBar, percent);
            }

        }
    });

}

From source file:at.rc.tacos.client.ui.custom.DatePickerPanel.java

License:Open Source License

/**
 * This method initializes the month combo
 *//*from  w ww  .j  a  v a2s . c om*/
private void createTimeList(Composite composite) {

    DateFormat dateFormat = DateFormat.getTimeInstance(DateFormat.SHORT);
    Calendar tempCalendar = Calendar.getInstance();
    tempCalendar.set(Calendar.MINUTE, 0);
    tempCalendar.set(Calendar.SECOND, 0);
    String[] times = new String[48];
    int pos = 0;
    for (int x = 0; x < 24; x++) {
        // hour
        tempCalendar.set(Calendar.MINUTE, 0);
        tempCalendar.set(Calendar.HOUR_OF_DAY, x);
        times[pos] = dateFormat.format(tempCalendar.getTime());
        // count up the position for the minute
        pos++;
        // minute
        tempCalendar.set(Calendar.MINUTE, 30);
        times[pos] = dateFormat.format(tempCalendar.getTime());
        // count up the position for the hour
        pos++;
    }

    ListViewer listViewer = new ListViewer(composite);

    listViewer.setContentProvider(new ArrayContentProvider());
    listViewer.setInput(times);

    timeList = listViewer.getList();

    listViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent event) {
            // even index -> just hour
            if (timeList.getSelectionIndex() % 2 == 0) {
                date.set(Calendar.HOUR_OF_DAY, timeList.getSelectionIndex() / 2);
                date.set(Calendar.MINUTE, 0);
            } else {
                date.set(Calendar.HOUR_OF_DAY, timeList.getSelectionIndex() / 2);
                date.set(Calendar.MINUTE, 30);
            }
            setSelection(new DateSelection(date));
            notifyListeners(new SelectionChangedEvent(DatePickerPanel.this, getSelection()));
        }
    });

    GridDataFactory.fillDefaults().hint(SWT.DEFAULT, 150).grab(false, true).applyTo(timeList);
    if (date != null) {
        // if we have a minute -> select it
        if (date.get(Calendar.MINUTE) > 0)
            listViewer.setSelection(new StructuredSelection(times[date.get(Calendar.HOUR_OF_DAY) + 1]), true);
        else
            listViewer.setSelection(new StructuredSelection(times[date.get(Calendar.HOUR_OF_DAY)]), true);
    } else {
        listViewer.setSelection(new StructuredSelection(times[8]), true);
    }
    timeList.addKeyListener(this);
}

From source file:com.aptana.formatter.ui.preferences.AbstractFormatterSelectionBlock.java

License:Open Source License

protected void configurePreview(Composite composite, int numColumns) {
    createLabel(composite, FormatterMessages.AbstractFormatterSelectionBlock_preview, numColumns);
    Composite previewGroup = new Composite(composite, SWT.NONE);
    previewGroup.setLayout(new GridLayout(1, true));
    GridData gd = new GridData(GridData.FILL_VERTICAL | GridData.HORIZONTAL_ALIGN_FILL);
    gd.horizontalSpan = numColumns;//from w w  w. ja v a 2  s . com
    previewGroup.setLayoutData(gd);

    // Adds a SashForm to create left and right areas. The left will hold the list of formatters, while the right
    // will hold a preview pane
    SashForm sashForm = new SashForm(previewGroup, SWT.HORIZONTAL);
    sashForm.setLayoutData(new GridData(GridData.FILL_BOTH));
    final ListViewer listViewer = new ListViewer(sashForm, SWT.SINGLE | SWT.BORDER);
    listViewer.getControl().setLayoutData(new GridData(GridData.FILL_BOTH));

    // Add the right panel (code preview and buttons)
    Composite rightPanel = new Composite(sashForm, SWT.NONE);
    GridLayout layout = new GridLayout(1, false);
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    rightPanel.setLayout(layout);
    rightPanel.setLayoutData(new GridData(GridData.FILL_BOTH));

    // Previews area
    final Composite previewPane = new Composite(rightPanel, SWT.BORDER);
    GridData previewGridData = new GridData(GridData.FILL_BOTH);
    previewGridData.heightHint = 300;
    previewGridData.widthHint = 450;
    previewPane.setLayoutData(previewGridData);
    previewStackLayout = new StackLayout();
    previewPane.setLayout(previewStackLayout);

    // Set the data into the list
    listViewer.setContentProvider(ArrayContentProvider.getInstance());
    listViewer.setLabelProvider(new LabelProvider() {
        @Override
        public String getText(Object element) {
            IScriptFormatterFactory factory = (IScriptFormatterFactory) element;
            return factory.getName();
        }
    });
    listViewer.setInput(this.factories);
    if (selectedFormatter < 0) {
        selectedFormatter = 0;
    }
    listViewer.setSelection(new StructuredSelection(this.factories[selectedFormatter]));
    listViewer.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            // Update the preview
            selectedFormatter = listViewer.getList().getSelectionIndex();
            if (selectedFormatter > -1 && selectedFormatter < sourcePreviewViewers.size()) {
                fSelectedPreviewViewer = sourcePreviewViewers.get(selectedFormatter);
                previewStackLayout.topControl = fSelectedPreviewViewer.getControl();
                previewPane.layout();
                updatePreview();
            }
        }
    });
    listViewer.addDoubleClickListener(new IDoubleClickListener() {
        public void doubleClick(DoubleClickEvent event) {
            if (listViewer.getList().getSelectionIndex() > -1) {
                editButtonPressed();
            }
        }
    });

    for (IScriptFormatterFactory factory : this.factories) {
        SourceViewer sourcePreview = createSourcePreview(previewPane, factory);
        sourcePreviewViewers.add(sourcePreview);
    }
    if (selectedFormatter > -1 && sourcePreviewViewers.size() > selectedFormatter) {
        fSelectedPreviewViewer = sourcePreviewViewers.get(selectedFormatter);
        previewStackLayout.topControl = fSelectedPreviewViewer.getControl();
        previewPane.layout();
    }

    sashForm.setWeights(new int[] { 1, 3 });

    // Attach the listeners
    profileChangeListener = new IPropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent event) {
            if (IProfileManager.PROFILE_SELECTED.equals(event.getProperty())) {
                IProfile profile = (IProfile) event.getNewValue();
                fSelectedPreviewViewer = sourcePreviewViewers.get(selectedFormatter);
                previewStackLayout.topControl = fSelectedPreviewViewer.getControl();
                previewPane.layout();
                updatePreview();
                fDefaultButton.setEnabled(!profile.isBuiltInProfile());
            }
        }
    };
    profileManager.addPropertyChangeListener(profileChangeListener);

}

From source file:com.ebmwebsoucing.petals.repositories.explorer.wizards.RepositoryNewWizardPage.java

License:Open Source License

public void createControl(Composite parent) {

    Composite container = new Composite(parent, SWT.NONE);
    GridLayout layout = new GridLayout(2, false);
    layout.marginLeft = 15;//from  w  ww .  j  a  va 2 s .co  m
    layout.marginRight = 15;
    layout.marginTop = 20;
    layout.horizontalSpacing = 15;
    container.setLayout(layout);
    container.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    // Name
    Label label = new Label(container, SWT.NONE);
    label.setText("Name:");
    label.setToolTipText("The name of the repository to create");

    Text text = new Text(container, SWT.SINGLE | SWT.BORDER);
    text.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    text.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            RepositoryNewWizardPage.this.repositoryName = ((Text) e.widget).getText();
            validate();
        }
    });

    // Description
    label = new Label(container, SWT.NONE);
    label.setText("Description:");
    label.setToolTipText("The description of the repository to create");

    text = new Text(container, SWT.SINGLE | SWT.BORDER);
    text.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    text.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            RepositoryNewWizardPage.this.repositoryDescription = ((Text) e.widget).getText();
            validate();
        }
    });

    // Separation
    Composite comp = new Composite(container, SWT.NONE);
    layout = new GridLayout(2, false);
    layout.marginWidth = 0;
    layout.marginTop = 15;
    comp.setLayout(layout);
    GridData layoutData = new GridData(GridData.FILL_BOTH);
    layoutData.horizontalSpan = 2;
    comp.setLayoutData(layoutData);

    label = new Label(comp, SWT.NONE);
    label.setText("Select the Query API this repository supports.");
    layoutData = new GridData(GridData.FILL_HORIZONTAL);
    layoutData.horizontalSpan = 2;
    label.setLayoutData(layoutData);

    // Supported API
    final ListViewer viewer = new ListViewer(comp, SWT.SINGLE | SWT.BORDER);
    viewer.getList().setLayoutData(new GridData(GridData.FILL_BOTH));

    viewer.setContentProvider(new ArrayContentProvider());
    viewer.setLabelProvider(new LabelProvider() {
        @Override
        public String getText(Object element) {
            String result = "";
            if (element instanceof QueryApiBean)
                result = ((QueryApiBean) element).getQueryApi().toString() + " - "
                        + ((QueryApiBean) element).getQueryUri();
            return result;
        }
    });

    viewer.setInput(this.queryApiBeans);

    // Buttons to add / remove an API
    Composite buttonsContainer = new Composite(comp, SWT.NONE);
    layout = new GridLayout();
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    buttonsContainer.setLayout(layout);
    buttonsContainer.setLayoutData(new GridData(SWT.DEFAULT, SWT.TOP, false, false));

    Button addButton = new Button(buttonsContainer, SWT.PUSH);
    addButton.setText("Add...");
    addButton.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
    addButton.setToolTipText("Add a new Query API");
    addButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {

            QueryApiBeanDefinitionDialog dlg = new QueryApiBeanDefinitionDialog(getShell(), null);
            if (dlg.open() == Window.OK) {
                RepositoryNewWizardPage.this.queryApiBeans.add(dlg.getQueryApiBean());
                viewer.refresh();
                validate();
            }
        }
    });

    Button removeButton = new Button(buttonsContainer, SWT.PUSH);
    removeButton.setText("Remove");
    removeButton.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
    removeButton.setToolTipText("Remove a Query API");
    removeButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {

            if (!viewer.getSelection().isEmpty()) {
                Object o = ((IStructuredSelection) viewer.getSelection()).getFirstElement();
                RepositoryNewWizardPage.this.queryApiBeans.remove(o);
                viewer.refresh();
                validate();
            }
        }
    });

    setControl(container);
}

From source file:com.google.eclipse.protobuf.ui.preferences.editor.numerictag.NumericTagPreferencePage.java

License:Open Source License

@Override
protected void doCreateContents(Composite parent) {
    Label lblDescription = new Label(parent, SWT.WRAP);
    GridData gridData = new GridData(SWT.FILL, SWT.CENTER, false, false, 2, 1);
    gridData.widthHint = 150; // only expand further if anyone else requires it
    lblDescription.setLayoutData(gridData);
    lblDescription.setText(pageDescription);
    new Label(parent, SWT.NONE);

    ListViewer lstVwrPatterns = new ListViewer(parent, SWT.BORDER | SWT.V_SCROLL);
    lstPatterns = lstVwrPatterns.getList();
    gridData = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);
    gridData.heightHint = 127;//www  . java 2s . co  m
    lstPatterns.setLayoutData(gridData);

    Composite composite = new Composite(parent, SWT.NONE);
    composite.setLayoutData(new GridData(SWT.LEFT, SWT.FILL, false, false, 1, 1));
    composite.setLayout(new GridLayout(1, false));

    btnAdd = new Button(composite, SWT.NONE);
    btnAdd.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
    btnAdd.setText(add);

    btnEdit = new Button(composite, SWT.NONE);
    btnEdit.setEnabled(false);
    btnEdit.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
    btnEdit.setText(edit);

    btnRemove = new Button(composite, SWT.NONE);
    btnRemove.setEnabled(false);
    btnRemove.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
    btnRemove.setText(remove);

    addEventListeners();
}

From source file:com.redhat.ea.archimate.strategyexport.dialog.ExportDialog.java

License:Open Source License

/**
 * Create contents of the dialog.// www  . j  a v  a 2s  .  c  om
 * 
 * @param parent
 */
@Override
protected Control createDialogArea(Composite parent) {
    Composite container = (Composite) super.createDialogArea(parent);
    container.setLayout(null);

    Label lblExportTheSelected = new Label(container, SWT.CENTER);
    lblExportTheSelected.setBounds(10, 10, 280, 43);
    //lblExportTheSelected
    //      .setText("Export the selected Roadmap to a .dot export file\n for visualization with the GraphViz program.");
    lblExportTheSelected.setText(this.prompt);

    ListViewer listViewer = new ListViewer(container, SWT.BORDER | SWT.V_SCROLL | SWT.MULTI);

    listViewer.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            statuses = ((ListViewer) event.getSelectionProvider()).getList().getSelection();
        }
    });

    List list = listViewer.getList();
    // list.setItems(new String[] {"Proposed", "Validated", "Approved",
    // "Implemented (completed)", "Mandatory (missing dependencies)"});

    for (String s : StateEnum.GetStateEnumList()) {
        list.add(s);
    }
    list.setBounds(52, 74, 208, 116);

    // do the selectAll after we've populated...
    list.selectAll();
    // bootstrap statuses, as if we don't click anything, never gets set
    statuses = list.getSelection();

    _listSelection = list;

    Label lblSelectedStatesWill = new Label(container, SWT.NONE);
    lblSelectedStatesWill.setBounds(52, 54, 193, 14);
    lblSelectedStatesWill.setText("Selected States will be included.");

    return container;
}

From source file:com.vectrace.MercurialEclipse.ui.SWTWidgetHelper.java

License:Open Source License

/**
 * Creates a ListViewer//from  w  ww.  j ava  2  s .  c  o  m
 *
 * @param parent
 *            the parent of the viewer
 * @param title
 *            the text for the title label
 * @param heightHint
 *            the nominal height of the list
 * @param the
 *            label decorator
 * @return the created list viewer
 */
public static ListViewer createListViewer(Composite parent, String title, int heightHint,
        IBaseLabelProvider labelProvider) {
    if (title != null) {
        createLabel(parent, title);
    }
    ListViewer listViewer = new ListViewer(parent,
            SWT.READ_ONLY | SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER | SWT.MULTI);
    listViewer.setContentProvider(new IStructuredContentProvider() {
        public Object[] getElements(Object inputElement) {
            return (Object[]) inputElement;
        }

        public void dispose() {
        }

        public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
        }

    });
    listViewer.setLabelProvider(labelProvider);

    GridData data = new GridData(GridData.FILL_BOTH);
    data.heightHint = heightHint;
    listViewer.getList().setLayoutData(data);
    listViewer.setUseHashlookup(true);
    return listViewer;
}

From source file:eu.hydrologis.jgrass.gpsnmea.actions.GpsSettingsComposite.java

License:Open Source License

public GpsSettingsComposite(final Shell parent) {

    gpsWasLoggingWhenOpened = GpsActivator.getDefault().isGpsLogging();

    /*//from ww  w.  ja  va  2s.  c  o  m
     * Serial ports panel
     */
    Group group = new Group(parent, SWT.None);
    group.setText(PreferenceConstants.PORTUSED);
    group.setLayout(new GridLayout(2, false));
    GridData gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL);
    group.setLayoutData(gridData);

    portLabel = new Label(group, SWT.None);
    portLabel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL));

    Button searchPortButton = new Button(group, SWT.BORDER | SWT.PUSH);
    searchPortButton.setText("search port");
    searchPortButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            String[] ports = getPorts();
            final Shell shell = new Shell(parent.getShell());
            shell.setSize(new Point(300, 400));
            Point cursorLocation = parent.getShell().getDisplay().getCursorLocation();
            shell.setLocation(cursorLocation);
            shell.setLayout(new GridLayout(2, true));

            GridData gridDataList = new GridData(
                    GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL);
            gridDataList.horizontalSpan = 2;
            final ListViewer v = new ListViewer(shell, SWT.H_SCROLL | SWT.V_SCROLL);
            v.setLabelProvider(new LabelProvider());
            v.setContentProvider(new ArrayContentProvider());
            v.setInput(ports);
            v.getList().setLayoutData(gridDataList);

            Button ok = new Button(shell, SWT.BORDER | SWT.PUSH);
            ok.setText("Ok");
            ok.addSelectionListener(new SelectionAdapter() {
                public void widgetSelected(SelectionEvent e) {
                    IStructuredSelection selection = (IStructuredSelection) v.getSelection();
                    String firstElement = (String) selection.getFirstElement();
                    portLabel.setText(firstElement);
                    gpsPortUsed = firstElement;

                    // set the preference
                    prefs.setValue(PreferenceConstants.PORTUSED, gpsPortUsed);

                    shell.dispose();
                }
            });
            Button cancel = new Button(shell, SWT.BORDER | SWT.PUSH);
            cancel.setText("Cancel");
            cancel.addSelectionListener(new SelectionAdapter() {
                public void widgetSelected(SelectionEvent e) {
                    shell.dispose();
                }
            });

            shell.open();
        }
    });

    /*
     * start stop gps connection panel
     */
    Group group2 = new Group(parent, SWT.None);
    group2.setText("Start / Stop the Gps connection");
    group2.setLayout(new GridLayout(2, true));
    GridData gridData2 = new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL);
    group2.setLayoutData(gridData2);

    startButton = new Button(group2, SWT.BORDER | SWT.RADIO);
    startButton.setText("Start Gps");
    startButton.setImage(AbstractUIPlugin.imageDescriptorFromPlugin(GpsActivator.PLUGIN_ID, "icons/start16.png") //$NON-NLS-1$
            .createImage());
    startButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL));
    startButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            try {

                PlatformGIS.runInProgressDialog("Starting Gps...", false, new IRunnableWithProgress() {
                    public void run(IProgressMonitor pm)
                            throws InvocationTargetException, InterruptedException {

                        pm.beginTask("Connecting to the gps. This might take a minute...",
                                IProgressMonitor.UNKNOWN);
                        try {
                            if (!GpsActivator.getDefault().isGpsConnected()) {
                                GpsActivator.getDefault().startGps();
                                GpsActivator.getDefault().startGpsLogging();
                                isFirst = true;
                                gpsIsOn = true;
                                pm.done();

                                // add this as listener to gps
                                GpsActivator.getDefault().addObserverToGps(GpsSettingsComposite.this);

                            }
                        } finally {
                            pm.done();
                        }
                    }
                }, false);

            } catch (Exception e1) {
                String message = "An error occurred while starting the gps logging.";
                ExceptionDetailsDialog.openError(null, message, IStatus.ERROR, GpsActivator.PLUGIN_ID, e1);
                e1.printStackTrace();
            }
        }
    });

    stopButton = new Button(group2, SWT.BORDER | SWT.RADIO);
    stopButton.setText("Stop Gps");
    stopButton.setImage(AbstractUIPlugin.imageDescriptorFromPlugin(GpsActivator.PLUGIN_ID, "icons/stop16.png") //$NON-NLS-1$
            .createImage());
    stopButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL));
    stopButton.setSelection(true);
    stopButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            try {

                PlatformUI.getWorkbench().getProgressService().busyCursorWhile(new IRunnableWithProgress() {
                    public void run(IProgressMonitor pm)
                            throws InvocationTargetException, InterruptedException {
                        pm.beginTask("Stopping Gps...", IProgressMonitor.UNKNOWN);
                        if (GpsActivator.getDefault().isGpsConnected()) {
                            GpsActivator.getDefault().stopGpsLogging();
                            GpsActivator.getDefault().stopGps();
                        }
                        gpsIsOn = false;
                        pm.done();

                        // remove this as listener to gps
                        GpsActivator.getDefault().removeObserverFromGps(GpsSettingsComposite.this);
                    }
                });

            } catch (Exception e1) {
                String message = "An error occurred while stopping the gps logging.";
                ExceptionDetailsDialog.openError(null, message, IStatus.ERROR, GpsActivator.PLUGIN_ID, e1);
                e1.printStackTrace();
            }
        }
    });

    text = new Text(group2, SWT.BORDER | SWT.MULTI);
    GridData gd = new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL);
    gd.horizontalSpan = 2;
    text.setLayoutData(gd);
    text.setEditable(false);

    /*
     * distance and position preferences
     */
    Group group3 = new Group(parent, SWT.None);
    group3.setText("Time and position settings");
    group3.setLayout(new GridLayout(2, false));
    GridData gridData3 = new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL);
    group3.setLayoutData(gridData3);

    Label intervalLabel = new Label(group3, SWT.NONE);
    intervalLabel.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
    intervalLabel.setText(PreferenceConstants.INTERVAL_SECONDS);

    intervalText = new Text(group3, SWT.SINGLE | SWT.LEAD | SWT.BORDER);
    intervalText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    intervalText.setText("");

    Label distanceLabel = new Label(group3, SWT.NONE);
    distanceLabel.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
    distanceLabel.setText(PreferenceConstants.DISTANCE_THRESHOLD);

    distanceText = new Text(group3, SWT.SINGLE | SWT.LEAD | SWT.BORDER);
    distanceText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    distanceText.setText("");

    dummyModeButton = new Button(parent, SWT.CHECK);
    dummyModeButton.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, true, false));
    dummyModeButton.setText(PreferenceConstants.TESTMODE);
    dummyModeButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            prefs.setValue(PreferenceConstants.TESTMODE, dummyModeButton.getSelection());
        }
    });

    /*
     * load saved preferences
     */
    loadPreferences();

    /*
     * ok and cancel buttons
     */
    Composite okCancelComposite = new Composite(parent, SWT.NONE);
    okCancelComposite.setLayoutData(new GridData(SWT.CENTER, SWT.FILL, true, false));
    okCancelComposite.setLayout(new GridLayout(2, true));

    Button okButton = new Button(okCancelComposite, SWT.PUSH);
    okButton.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
    okButton.setText("ok");
    okButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            savePreferences();
            GpsActivator.getDefault().removeObserverFromGps(GpsSettingsComposite.this);
            if (!gpsWasLoggingWhenOpened) {
                GpsActivator.getDefault().stopGpsLogging();
            }
            parent.close();
        }
    });
    Button cancelButton = new Button(okCancelComposite, SWT.PUSH);
    cancelButton.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false));
    cancelButton.setText("cancel");
    cancelButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            GpsActivator.getDefault().removeObserverFromGps(GpsSettingsComposite.this);
            if (!gpsWasLoggingWhenOpened) {
                GpsActivator.getDefault().stopGpsLogging();
            }
            parent.close();
        }
    });

}

From source file:it.eng.spagobi.meta.editor.multi.wizards.SelectionConnectionPage.java

License:Mozilla Public License

@Override
public void createControl(Composite parent) {
    profiles = dseBridge.getConnectionProfiles();

    Composite container = new Composite(parent, SWT.NULL);
    setControl(container);/* www  .  j  a  va 2s . c  o  m*/
    container.setLayout(new GridLayout(1, false));

    Group grpConnection = new Group(container, SWT.NONE);
    grpConnection.setText(RL.getString("multi.editor.wizard.selectionconnection.label"));
    grpConnection.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    FillLayout fl_grpConnection = new FillLayout(SWT.HORIZONTAL);
    grpConnection.setLayout(fl_grpConnection);

    ListViewer listViewer = new ListViewer(grpConnection, SWT.BORDER | SWT.V_SCROLL);
    connectionList = listViewer.getList();
    connectionList.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {

            // reset combos
            catalogCombo.removeAll();
            catalogCombo.setEnabled(false);
            schemaCombo.removeAll();
            schemaCombo.setEnabled(false);

            selectedConnectionName = connectionList.getSelection()[0];
            // ProgressMonitorDialog to show a progress bar for long
            // operation
            ProgressMonitorDialog dialog = new ProgressMonitorDialog(new Shell());
            dialog.setCancelable(false);

            try {
                dialog.run(true, false, new IRunnableWithProgress() {
                    @Override
                    public void run(IProgressMonitor monitor) {
                        // Note: this is a non-UI Thread
                        monitor.beginTask("Checking connection, please wait...", IProgressMonitor.UNKNOWN);
                        // doing task...
                        jdbcConnection = dseBridge.connect(selectedConnectionName);
                        monitor.done();
                    }
                });
            } catch (InvocationTargetException e1) {
                e1.printStackTrace();
            } catch (InterruptedException e1) {
                e1.printStackTrace();
            }

            if (jdbcConnection != null) {
                setErrorMessage(null);
                setPageComplete(true);
                populateCatalogCombo(jdbcConnection);
            } else {
                setPageComplete(false);
                ErrorDialog.openError(null, "Connection failed",
                        "Connection to database failed, please check your settings",
                        new org.eclipse.core.runtime.Status(IStatus.ERROR, "id",
                                "Connection to database failed"));
                setErrorMessage("Please select a valid connection to continue");
            }
        }
    });
    listViewer.setContentProvider(new ArrayContentProvider());
    listViewer.setLabelProvider(new LabelProvider() {
        @Override
        public String getText(Object element) {
            return ((IConnectionProfile) element).getName();
        }
    });
    listViewer.setInput(profiles);
    Group grpCatalogAndSchema = new Group(container, SWT.NONE);
    grpCatalogAndSchema.setText(RL.getString("multi.editor.wizard.selectionconnection.catalogschema.label"));
    grpCatalogAndSchema.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
    grpCatalogAndSchema.setLayout(new FillLayout(SWT.HORIZONTAL));

    Composite composite = new Composite(grpCatalogAndSchema, SWT.NONE);
    composite.setLayout(new GridLayout(4, false));

    Label lblCatalog = new Label(composite, SWT.NONE);
    lblCatalog.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
    lblCatalog.setText(RL.getString("multi.editor.wizard.selectionconnection.catalog.label"));

    catalogCombo = new Combo(composite, SWT.READ_ONLY);
    catalogCombo.setEnabled(false);
    catalogCombo.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            int selectionIndex = catalogCombo.getSelectionIndex();
            String selectedCatalog = catalogCombo.getItem(selectionIndex);
            populateSchemaCombo(jdbcConnection, selectedCatalog);
        }
    });
    catalogCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));

    Label lblSchema = new Label(composite, SWT.NONE);
    lblSchema.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
    lblSchema.setText(RL.getString("multi.editor.wizard.selectionconnection.schema.label"));

    schemaCombo = new Combo(composite, SWT.READ_ONLY);
    schemaCombo.setEnabled(false);
    schemaCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));

}

From source file:net.leboxondelex.daplomb.ui.dialogs.VideoFiltersDialog.java

License:Open Source License

@Override
protected Control createDialogArea(Composite parent) {

    // Shell properties
    getShell().setText("Filtres Vido");

    // The container
    Composite container = new Composite(parent, SWT.NONE);
    container.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_WHITE));
    GridLayoutFactory.swtDefaults().margins(10, 10).numColumns(2).spacing(25, 0).applyTo(container);
    container.setLayoutData(new GridData(GridData.FILL_BOTH));

    // The parts/*  w  ww  .  j  a  v a  2s .  c  o m*/
    Composite menuComposite = new Composite(container, SWT.NONE);
    menuComposite.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_WHITE));
    GridLayoutFactory.swtDefaults().margins(10, 10).spacing(10, 3).applyTo(menuComposite);
    GridDataFactory.fillDefaults().grab(true, true).applyTo(menuComposite);

    Label l = new Label(menuComposite, SWT.NONE);
    l.setText("Liste des Filtres Appliqus :");
    l.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_WHITE));

    final ListViewer menuViewer = new ListViewer(menuComposite, SWT.BORDER);
    GridDataFactory.fillDefaults().grab(true, true).applyTo(menuViewer.getList());
    menuViewer.setContentProvider(new ArrayContentProvider());
    menuViewer.setLabelProvider(new LabelProvider());

    String[] menus = { "Recadrage 1", "Proportions", "Recadrage 2", "Logo", "Nommage" };
    menuViewer.setInput(menus);

    final Composite optionsComposite = new Composite(container, SWT.NONE);
    optionsComposite.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_WHITE));
    GridLayoutFactory.swtDefaults().margins(10, 10).numColumns(2).applyTo(optionsComposite);
    GridDataFactory.fillDefaults().grab(true, true).applyTo(optionsComposite);

    // The listener
    menuViewer.getList().addListener(SWT.Selection, new Listener() {
        @Override
        public void handleEvent(Event e) {
            int index = menuViewer.getList().getSelectionIndex();
            updateOptions(optionsComposite, index);
        }
    });

    menuViewer.getList().setSelection(0);
    menuViewer.getList().notifyListeners(SWT.Selection, new Event());

    return container;
}