Example usage for org.eclipse.jface.viewers StructuredSelection getFirstElement

List of usage examples for org.eclipse.jface.viewers StructuredSelection getFirstElement

Introduction

In this page you can find the example usage for org.eclipse.jface.viewers StructuredSelection getFirstElement.

Prototype

@Override
    public Object getFirstElement() 

Source Link

Usage

From source file:br.com.dimag.safetycar.gui.views.AutomovelListView.java

License:Open Source License

/**
 * This is a callback that will allow us to create the viewer and initialize
 * it.//from  w w  w. j a v a 2  s  .c  o m
 */
public void createPartControl(Composite parent) {

    viewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER_SOLID);
    viewer.setColumnProperties(new String[] { "Placa", "Marca" });
    viewer.setContentProvider(new ViewContentProvider());
    viewer.setLabelProvider(new ViewLabelProvider());
    viewer.setInput(createModel());
    viewer.addDoubleClickListener(new IDoubleClickListener() {

        @Override
        public void doubleClick(DoubleClickEvent event) {
            // TODO Auto-generated method stub
            StructuredSelection sl = (StructuredSelection) event.getSelection();
            closeView();
            openView(AutomovelView.ID);
            AutomovelView view = (AutomovelView) findView(AutomovelView.ID);
            view.loadAutomovel((Automovel) sl.getFirstElement());
        }

    });
}

From source file:br.com.dimag.safetycar.gui.views.ClienteListView.java

License:Open Source License

/**
 * This is a callback that will allow us to create the viewer and initialize
 * it./*w  w  w  .  ja  va2s  .c  om*/
 */
public void createPartControl(Composite parent) {

    viewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER_SOLID);
    viewer.setColumnProperties(new String[] { "Nome", "Endereo" });
    viewer.setContentProvider(new ViewContentProvider());
    viewer.setLabelProvider(new ViewLabelProvider());
    viewer.setInput(createModel());
    viewer.addDoubleClickListener(new IDoubleClickListener() {

        @Override
        public void doubleClick(DoubleClickEvent event) {
            // TODO Auto-generated method stub
            StructuredSelection sl = (StructuredSelection) event.getSelection();
            closeView();
            openView(ClienteView.ID);
            ClienteView view = (ClienteView) findView(ClienteView.ID);
            view.loadCliente((Cliente) sl.getFirstElement());
        }

    });
}

From source file:br.com.dimag.safetycar.gui.views.OSListView.java

License:Open Source License

/**
 * This is a callback that will allow us to create the viewer and initialize
 * it./*from   w w  w. j a  v  a2s.co  m*/
 */
public void createPartControl(Composite composite) {

    {

        composite.setSize(484, 418);
        GridLayout mainLayout = new GridLayout();
        mainLayout.numColumns = 1;
        composite.setLayout(mainLayout);
        {
            groupDadosServico = new Group(composite, SWT.NONE);
            GridLayout dadosServicoLayout = new GridLayout();
            dadosServicoLayout.numColumns = 2;

            GridData dadosServicoLData = new GridData();
            dadosServicoLData.verticalAlignment = SWT.FILL;
            dadosServicoLData.horizontalAlignment = SWT.FILL;
            groupDadosServico.setLayoutData(dadosServicoLData);

            groupDadosServico.setLayout(dadosServicoLayout);
            groupDadosServico.setText("Dados da Consulta OS");
            groupDadosServico.setSize(243, 215);

            // PLACA ORDEM SERVIO

            {
                labelPlaca = new Label(groupDadosServico, SWT.NONE);
                labelPlaca.setText("Placa:");
            }
            {
                textPlaca = new Text(groupDadosServico, SWT.NONE);
                GridData descricaoProdutoLData = new GridData();
                descricaoProdutoLData.heightHint = 13;
                descricaoProdutoLData.horizontalAlignment = GridData.FILL;
                descricaoProdutoLData.grabExcessHorizontalSpace = true;
                textPlaca.setLayoutData(descricaoProdutoLData);
            }

            // view BOTO PESQUISAR
            {
                buttonPesquisar = new Button(groupDadosServico, SWT.PUSH | SWT.CENTER);
                GridData buttonConfirmaLData = new GridData();
                buttonConfirmaLData.verticalAlignment = GridData.BEGINNING;
                buttonConfirmaLData.horizontalAlignment = GridData.BEGINNING;
                buttonPesquisar.setLayoutData(buttonConfirmaLData);
                buttonPesquisar.setText("Pesquisar");

                buttonPesquisar.addSelectionListener(new SelectionListener() {

                    @Override
                    public void widgetSelected(SelectionEvent event) {
                        pesquisar();
                    }

                    @Override
                    public void widgetDefaultSelected(SelectionEvent arg0) {
                        // TODO Auto-generated method stub
                    }

                });
            }

            viewer = new TableViewer(composite, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER_SOLID);
            viewer.getTable().setLinesVisible(true);
            viewer.getTable().setHeaderVisible(true);

            viewer.setContentProvider(new ViewContentProvider());
            GridData viewerLData = new GridData();
            viewerLData.grabExcessHorizontalSpace = true;
            viewerLData.grabExcessVerticalSpace = true;
            viewerLData.horizontalAlignment = SWT.FILL;
            viewerLData.verticalAlignment = SWT.FILL;
            viewer.getControl().setLayoutData(viewerLData);
            viewer.setLabelProvider(new ViewLabelProvider());

            for (ColumnProperty columnProperty : ColumnProperty.values()) {
                TableColumn coluna = new TableColumn(viewer.getTable(), SWT.NONE);
                coluna.setText(columnProperty.getName());
                coluna.setWidth(columnProperty.getWidth());
            }

            viewer.addDoubleClickListener(new IDoubleClickListener() {

                @Override
                public void doubleClick(DoubleClickEvent event) {
                    // TODO Auto-generated method stub
                    StructuredSelection sl = (StructuredSelection) event.getSelection();
                    closeView();
                    openView(OSView.ID);
                    OSView view = (OSView) findView(OSView.ID);
                    view.loadOS((OrdemServico) sl.getFirstElement());
                }

            });
            loadData();
        }
    }
}

From source file:br.com.dimag.safetycar.gui.views.ProdutoListView.java

License:Open Source License

/**
 * This is a callback that will allow us to create the viewer and initialize
 * it./*from w  ww . j a  v  a 2  s. c o  m*/
 */
public void createPartControl(Composite parent) {

    viewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER_SOLID);
    viewer.setColumnProperties(new String[] { "EAN", "Descrio" });
    viewer.setContentProvider(new ViewContentProvider());
    viewer.setLabelProvider(new ViewLabelProvider());
    viewer.setInput(createModel());
    viewer.addDoubleClickListener(new IDoubleClickListener() {

        @Override
        public void doubleClick(DoubleClickEvent event) {
            // TODO Auto-generated method stub
            StructuredSelection sl = (StructuredSelection) event.getSelection();
            closeView();
            openView(ProdutoView.ID);
            ProdutoView view = (ProdutoView) findView(ProdutoView.ID);
            view.loadProduto((Produto) sl.getFirstElement());
        }

    });
}

From source file:br.com.dimag.safetycar.gui.views.ServicoListView.java

License:Open Source License

/**
 * This is a callback that will allow us to create the viewer and initialize
 * it./*from   w w w.ja v a 2s . com*/
 */
public void createPartControl(Composite composite) {
    {

        composite.setSize(484, 418);
        GridLayout mainLayout = new GridLayout();
        mainLayout.numColumns = 1;
        composite.setLayout(mainLayout);
        {
            groupDadosServico = new Group(composite, SWT.NONE);
            GridLayout dadosServicoLayout = new GridLayout();
            dadosServicoLayout.numColumns = 2;

            GridData dadosServicoLData = new GridData();
            dadosServicoLData.verticalAlignment = SWT.FILL;
            dadosServicoLData.horizontalAlignment = SWT.FILL;
            groupDadosServico.setLayoutData(dadosServicoLData);

            groupDadosServico.setLayout(dadosServicoLayout);
            groupDadosServico.setText("Dados da Consulta Servio");
            groupDadosServico.setSize(243, 215);

            // DESCRIO SERVIO

            {
                labelDescricao = new Label(groupDadosServico, SWT.NONE);
                labelDescricao.setText("Descrio:");
            }
            {
                textDescricao = new Text(groupDadosServico, SWT.NONE);
                GridData descricaoProdutoLData = new GridData();
                descricaoProdutoLData.heightHint = 13;
                descricaoProdutoLData.horizontalAlignment = GridData.FILL;
                descricaoProdutoLData.grabExcessHorizontalSpace = true;
                textDescricao.setLayoutData(descricaoProdutoLData);
            }

            // view BOTO CONFIRMA
            {
                buttonPesquisar = new Button(groupDadosServico, SWT.PUSH | SWT.CENTER);
                GridData buttonConfirmaLData = new GridData();
                buttonConfirmaLData.verticalAlignment = GridData.BEGINNING;
                buttonConfirmaLData.horizontalAlignment = GridData.BEGINNING;
                buttonPesquisar.setLayoutData(buttonConfirmaLData);
                buttonPesquisar.setText("Pesquisar");

                buttonPesquisar.addSelectionListener(new SelectionListener() {

                    @Override
                    public void widgetSelected(SelectionEvent event) {
                        pesquisar();
                    }

                    @Override
                    public void widgetDefaultSelected(SelectionEvent arg0) {
                        // TODO Auto-generated method stub
                    }

                });
            }

            // PRA BAIXO JA ESTAVA

            viewer = new TableViewer(composite, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER_SOLID);
            viewer.getTable().setLinesVisible(true);
            viewer.getTable().setHeaderVisible(true);

            viewer.setContentProvider(new ViewContentProvider());
            GridData viewerLData = new GridData();
            viewerLData.grabExcessHorizontalSpace = true;
            viewerLData.grabExcessVerticalSpace = true;
            viewerLData.horizontalAlignment = SWT.FILL;
            viewerLData.verticalAlignment = SWT.FILL;
            viewer.getControl().setLayoutData(viewerLData);
            viewer.setLabelProvider(new ViewLabelProvider());

            for (ColumnProperty columnProperty : ColumnProperty.values()) {
                TableColumn coluna = new TableColumn(viewer.getTable(), SWT.NONE);
                coluna.setText(columnProperty.getName());
                coluna.setWidth(columnProperty.getWidth());
            }

            viewer.addDoubleClickListener(new IDoubleClickListener() {

                @Override
                public void doubleClick(DoubleClickEvent event) {
                    // TODO Auto-generated method stub
                    StructuredSelection sl = (StructuredSelection) event.getSelection();
                    closeView();
                    openView(ServicoView.ID);
                    ServicoView view = (ServicoView) findView(ServicoView.ID);
                    view.loadServico((Servico) sl.getFirstElement());
                }

            });
            loadData();
        }
    }
}

From source file:br.com.dimag.safetycar.gui.views.UsuarioListView.java

License:Open Source License

/**
 * This is a callback that will allow us to create the viewer and initialize
 * it./*from  w  w  w  .  j a  v a  2  s.  c o  m*/
 */
public void createPartControl(Composite composite) {
    {

        composite.setSize(484, 418);
        GridLayout mainLayout = new GridLayout();
        mainLayout.numColumns = 1;
        composite.setLayout(mainLayout);
        {
            groupDadosUsuario = new Group(composite, SWT.NONE);
            GridLayout dadosUsuarioLayout = new GridLayout();
            dadosUsuarioLayout.numColumns = 1;

            GridData dadosServicoLData = new GridData();
            dadosServicoLData.verticalAlignment = SWT.FILL;
            dadosServicoLData.horizontalAlignment = SWT.FILL;
            groupDadosUsuario.setLayoutData(dadosServicoLData);

            groupDadosUsuario.setLayout(dadosUsuarioLayout);
            groupDadosUsuario.setText("Dados da Consulta Usurios");
            groupDadosUsuario.setSize(243, 215);

            // LOGIN

            {
                labelLogin = new Label(groupDadosUsuario, SWT.NONE);
                labelLogin.setText("Login:");
            }
            {
                textLogin = new Text(groupDadosUsuario, SWT.NONE);
                GridData loginUsuarioLData = new GridData();
                loginUsuarioLData.heightHint = 13;
                loginUsuarioLData.horizontalAlignment = GridData.FILL;
                loginUsuarioLData.grabExcessHorizontalSpace = true;
                textLogin.setLayoutData(loginUsuarioLData);
            }

            // view BOTO CONFIRMA
            {
                buttonPesquisar = new Button(groupDadosUsuario, SWT.PUSH | SWT.CENTER);
                GridData buttonConfirmaLData = new GridData();
                buttonConfirmaLData.verticalAlignment = GridData.BEGINNING;
                buttonConfirmaLData.horizontalAlignment = GridData.BEGINNING;
                buttonPesquisar.setLayoutData(buttonConfirmaLData);
                buttonPesquisar.setText("Pesquisar");

                buttonPesquisar.addSelectionListener(new SelectionListener() {

                    @Override
                    public void widgetSelected(SelectionEvent event) {
                        pesquisar();
                    }

                    @Override
                    public void widgetDefaultSelected(SelectionEvent arg0) {
                        // TODO Auto-generated method stub
                    }

                });
            }

            // PRA BAIXO JA ESTAVA

            viewer = new TableViewer(composite, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER_SOLID);
            viewer.getTable().setLinesVisible(true);
            viewer.getTable().setHeaderVisible(true);

            viewer.setContentProvider(new ViewContentProvider());
            GridData viewerLData = new GridData();
            viewerLData.grabExcessHorizontalSpace = true;
            viewerLData.grabExcessVerticalSpace = true;
            viewerLData.horizontalAlignment = SWT.FILL;
            viewerLData.verticalAlignment = SWT.FILL;
            viewer.getControl().setLayoutData(viewerLData);
            viewer.setLabelProvider(new ViewLabelProvider());

            for (ColumnProperty columnProperty : ColumnProperty.values()) {
                TableColumn coluna = new TableColumn(viewer.getTable(), SWT.NONE);
                coluna.setText(columnProperty.getName());
                coluna.setWidth(columnProperty.getWidth());
            }

            viewer.addDoubleClickListener(new IDoubleClickListener() {

                @Override
                public void doubleClick(DoubleClickEvent event) {
                    // TODO Auto-generated method stub
                    StructuredSelection sl = (StructuredSelection) event.getSelection();
                    closeView();
                    openView(UsuarioView.ID);
                    UsuarioView view = (UsuarioView) findView(UsuarioView.ID);
                    view.loadUsuario((Usuario) sl.getFirstElement());
                }

            });
            loadData();
        }
    }
}

From source file:br.ufam.pnmp.ezrealtime.exporter.ui.action.EZRealtime2PnmlAction.java

License:Open Source License

public void run(IAction action) {

    System.out.println("Export into PNML - start.");

    StructuredSelection selection = (StructuredSelection) this.activePart.getSite().getSelectionProvider()
            .getSelection();//from  ww  w  .  j a  va 2  s. c o  m

    org.eclipse.core.internal.resources.File file = (org.eclipse.core.internal.resources.File) selection
            .getFirstElement();

    String pathToRealtimeFile = file.getLocation().toFile().getAbsolutePath();

    final String PNML_FILE_NAME = FileHelper.getPnmlFileSelected(selection);

    EZRealtimeSpec realtimeSystem;
    try {
        realtimeSystem = EZRealtimeParser.getInstance().parse(pathToRealtimeFile);

        java.io.File pnmlFile = new java.io.File(PNML_FILE_NAME);
        if (pnmlFile.exists() && pnmlFile.isFile()) {
            System.out.println("Deleting pnml file...");
            pnmlFile.delete();
        }

        EZRealtime2PnmlExport exportExample = new EZRealtime2PnmlExport();
        exportExample.realtimeSpec2Pnml(realtimeSystem, PNML_FILE_NAME);

    } catch (IOException e1) {
        e1.printStackTrace();
    } catch (PnmlException e1) {
        e1.printStackTrace();
    }

    System.out.println("Export into PNML done.");

    Shell shell = new Shell();

    try {
        Util.refreshWorkspace();
    } catch (CoreException e) {
        MessageDialog.openError(shell, "Real Time Translator",
                "Unable do refresh the workspace.\nPlease refresh it manually");
    }

}

From source file:br.ufam.pnmp.ezrealtime.exporter.util.FileHelper.java

License:Open Source License

public static String getPnmlFileSelected(StructuredSelection selection) {
    org.eclipse.core.internal.resources.File file = (org.eclipse.core.internal.resources.File) selection
            .getFirstElement();/*  w w w .j  av a2s  .  c o m*/

    String pathToFile = file.getLocation().toFile().getAbsolutePath();

    String fileExt = file.getLocation().getFileExtension();

    int index = pathToFile.lastIndexOf(fileExt);

    final String PNML_FILE_NAME = pathToFile.substring(0, index) + "pnml";

    System.out.println("pathToFile: " + pathToFile);

    return PNML_FILE_NAME;
}

From source file:br.unb.cic.rtgoretoprism.action.RunJadexAgentAction.java

License:Open Source License

public void selectionChanged(IAction action, ISelection selection) {
    StructuredSelection ss = (StructuredSelection) selection;
    //rememeber the selected file, it will be our source for the transformation
    selectedFolder = (IFolder) ss.getFirstElement();
}

From source file:ca.uwaterloo.gp.fmp.constraints.ui.ConstraintsViewDropAdapter.java

License:Open Source License

public boolean performDrop(Object data) {
    // TODO Auto-generated method stub
    StructuredSelection structuredSelection = (StructuredSelection) data;

    // dropping only 1 feature is allowed
    if (structuredSelection.size() == 1) {
        Object toBeDroppedObj = structuredSelection.getFirstElement();

        // check the type of the feature to be dropped
        if (toBeDroppedObj instanceof Feature && !(toBeDroppedObj instanceof Node)) //to be changed
        {// ww w.j a  v  a2 s.  co m
            Feature toBeDroppedFeature = (Feature) toBeDroppedObj;

            // Get the constraint to be dropped onto
            Object target = getCurrentTarget();

            // if it is confirmed that the feature will be dropped onto an existing constraint
            if (target != null && target instanceof Constraint && ((Constraint) target).getText() != null) {
                Constraint constraintToBeModified = (Constraint) target;
                String featureName = toBeDroppedFeature.getName() == null ? "unnamed feature"
                        : toBeDroppedFeature.getName();
                constraintToBeModified.setText(constraintToBeModified.getText() + featureName);

                // update the view
                ((TreeViewer) getViewer()).update(target, null);
            }
        }
    }

    return true;
}