Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 738017
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T07:47:18+00:00 2026-05-14T07:47:18+00:00

I want to build a user interface similar to the sketch below: When the

  • 0

I want to build a user interface similar to the sketch below:

sketch

When the user fills out the form on the right and clicks the ‘Plot!’ button, a new closeable tab opens on the left with a chart.

I am new to RCP and have been following this tutorial. I am able to bring up tabs with charts triggered from a menu item. How do I go about:

  1. creating the tab (view?) with the form
  2. open a new chart tab when the user clicks the button

Edit

Here is my current code. It satisfies the basic requirements outlined in this question, but I am not sure if that is the best approach. I would be delighted if someone here can guide me in the right direction.

A view with the form; the button’s listener invokes a command.

public class FormView extends ViewPart {
    public static final String ID = 
        FormView.class.getPackage().getName() + ".Form";

    private FormToolkit toolkit;
    private Form form;
    public Text text;

    @Override
    public void createPartControl(Composite parent) {
        toolkit = new FormToolkit(parent.getDisplay());
        form = toolkit.createForm(parent);
        form.setText("Pie Chucker");
        GridLayout layout = new GridLayout();
        form.getBody().setLayout(layout);
        layout.numColumns = 2;
        GridData gd = new GridData();
        gd.horizontalSpan = 2;
        Label label = new Label(form.getBody(), SWT.NULL);
        label.setText("Chart Title:");
        text = new Text(form.getBody(), SWT.BORDER);
        text.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
        Button button = new Button(form.getBody(), SWT.PUSH);
        button.setText("Plot");
        gd = new GridData();
        gd.horizontalSpan = 2;
        button.setLayoutData(gd);
        button.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseDown(MouseEvent e) {
                IHandlerService handlerService = (IHandlerService) getSite()
                    .getService(IHandlerService.class);
                try {
                    handlerService.executeCommand(ShowChartHandler.ID, null);
                } catch (Exception ex) {
                    throw new RuntimeException(ShowChartHandler.ID + 
                        " not found");
                }
            }
        });

    }

    @Override
    public void setFocus() {
    }
}

The command invoked by the button from the form. This opens a new view with a chart.

public class ShowChartHandler extends AbstractHandler implements IHandler {
    public static final String ID = 
        ShowChartHandler.class.getPackage().getName() + ".ShowChart";
    private int count = 0;

    @Override
    public Object execute(ExecutionEvent event) throws ExecutionException {
        IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event);
        try {
            window.getActivePage().showView(ChartView.ID, 
                String.valueOf(++count), IWorkbenchPage.VIEW_ACTIVATE);
        } catch (PartInitException e) {
            e.printStackTrace();
        }
        return null;
    }
}

The view with the chart. It looks up the form view and reads a value from a text field in the form (?!):

public class ChartView extends ViewPart {
    public static final String ID = 
        ChartView.class.getPackage().getName() + ".Chart";

    private static final Random random = new Random();

    public ChartView() {
        // TODO Auto-generated constructor stub
    }

    @Override
    public void createPartControl(Composite parent) {
        FormView form = 
            (FormView) Workbench.getInstance()
                                .getActiveWorkbenchWindow()
                                .getActivePage()
                                .findView(FormView.ID);
        String title = form == null? null : form.text.getText();
        if (title == null || title.trim().length() == 0) {
            title = "Pie Chart";
        }
        setPartName(title);
        JFreeChart chart = createChart(createDataset(), title);
        new ChartComposite(parent, SWT.NONE, chart, true);
    }

    @Override
    public void setFocus() {
        // TODO Auto-generated method stub
    }

    /**
     * Creates the Dataset for the Pie chart
     */
    private PieDataset createDataset() {
        Double[] nums = getRandomNumbers();
        DefaultPieDataset dataset = new DefaultPieDataset();
        dataset.setValue("One", nums[0]);
        dataset.setValue("Two", nums[1]);
        dataset.setValue("Three", nums[2]);
        dataset.setValue("Four", nums[3]);
        dataset.setValue("Five", nums[4]);
        dataset.setValue("Six", nums[5]);
        return dataset;
    }

    private Double[] getRandomNumbers() {
        Double[] nums = new Double[6];
        int sum = 0;
        for (int i = 0; i < 5; i++) {
            int r = random.nextInt(20);
            nums[i] = new Double(r);
            sum += r;
        }
        nums[5] = new Double(100 - sum);
        return nums;
    }

    /**
     * Creates the Chart based on a dataset
     */
    private JFreeChart createChart(PieDataset dataset, String title) {

        JFreeChart chart = ChartFactory.createPieChart(title, // chart title
                dataset, // data
                true, // include legend
                true, false);

        PiePlot plot = (PiePlot) chart.getPlot();
        plot.setSectionOutlinesVisible(false);
        plot.setLabelFont(new Font("SansSerif", Font.PLAIN, 12));
        plot.setNoDataMessage("No data available");
        plot.setCircular(false);
        plot.setLabelGap(0.02);
        return chart;

    }

}

The perspective that ties it all together:

public class Perspective implements IPerspectiveFactory {

    public void createInitialLayout(IPageLayout layout) {
        layout.setEditorAreaVisible(false);
        layout.addStandaloneView(FormView.ID, false, 
                IPageLayout.RIGHT, 0.3f, 
                IPageLayout.ID_EDITOR_AREA);
        IFolderLayout charts = layout.createFolder("Charts", 
                IPageLayout.LEFT, 0.7f, FormView.ID);
        charts.addPlaceholder(ChartView.ID + ":*");
    }
}
  • 1 1 Answer
  • 2 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T07:47:18+00:00Added an answer on May 14, 2026 at 7:47 am

    I would recommend a different aproach. Eclipse has viewparts (views) and editors. It is easy to open multiple editors. Views are not so much for open multiple ones.
    So my suggestion is, that you implement the part you call “FormView” as a StandAloneView and implement the “ChartView” as an editor.

    I would also recommend to use a different listener for the button, so also the code will be executed when using the keyboard to click the button.

    My proposal:

    public class FormView extends ViewPart { 
    ...
    button.addSelectionListener(new SelectionAdapter() {
    @Override
    public void widgetSelected(SelectionEvent e) {
        // this below can also be called by a command but you need to take care about the data, which the user put into the fields in  different way.
        Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
        IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
        IWorkbenchPage page = window.getActivePage();
    
        ChartEditorInput input = new ChartEditorInput(text.getText(),...<other data you need to pass>);
        try {
         page.openEditor(input, ChartEditor.ID);
        } catch (PartInitException e) { 
           e.printStackTrace();
        }
    
    }
    });
    

    ChartView needs to be changed to ChartEditor. See here http://www.vogella.de/articles/RichClientPlatform/article.html#editor_editorinput how that is done.
    ChartEditorInput hereby is a class you need to implement aside the editor class, which holds the data.

    In your perspective you call:

    public void createInitialLayout(IPageLayout layout) {
       String editorArea = layout.getEditorArea();
       layout.setFixed(false);
       layout.setEditorAreaVisible(true);
    
       layout.addStandaloneView("your.domain.and.FormView", true,IPageLayout.RIGHT, 0.15f, editorArea);
    

    Hope this helps!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i want to build a screen for user to get his marks on competitions,
I want to build an application that exports user data of another app. The
I want to build flash application that can detect the user eyes color and
I want to build a component, where the user can play a video in
I have a devise user model with pro boolean column.I want to build a
I want to a build a website that show the user all videos that
I want build a sketch pad app on iPhone, I assume that this type
I want to build a form_tag that will allow me to post a new
Alright all you wonderful people out there; In my user interface I am building
I need to build a user interface to edit and create xml documents that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.