public Image getColumnImage(Object element, int columnIndex) {
      if (columnIndex == 1) {
        Transaction t = ((TransactionPair<?>) element).getTransaction();

        if (t instanceof AccountTransaction)
          return PortfolioPlugin.image(PortfolioPlugin.IMG_ACCOUNT);
        else if (t instanceof PortfolioTransaction)
          return PortfolioPlugin.image(PortfolioPlugin.IMG_PORTFOLIO);
      }
      return null;
    }
Esempio n. 2
0
  private void addCreateSecurityButton(ToolBar toolBar) {
    Action createSecurity =
        new Action() {
          @Override
          public void run() {
            Security newSecurity = new Security();
            newSecurity.setFeed(QuoteFeed.MANUAL);
            Dialog dialog =
                new WizardDialog(
                    getClientEditor().getSite().getShell(),
                    new EditSecurityWizard(getClient(), newSecurity));
            if (dialog.open() == Dialog.OK) {
              markDirty();
              getClient().addSecurity(newSecurity);

              if (watchlist != null) watchlist.getSecurities().add(newSecurity);

              setSecurityTableInput();
              securities.updateQuotes(newSecurity);
            }
          }
        };
    createSecurity.setImageDescriptor(PortfolioPlugin.descriptor(PortfolioPlugin.IMG_PLUS));
    createSecurity.setToolTipText(Messages.SecurityMenuAddNewSecurity);

    new ActionContributionItem(createSecurity).fill(toolBar, -1);
  }
 private ExportDropDown(ToolBar toolBar) {
   super(
       toolBar,
       Messages.MenuExportData,
       PortfolioPlugin.image(PortfolioPlugin.IMG_EXPORT),
       SWT.NONE);
 }
Esempio n. 4
0
  @Override
  public void linkActivated(HyperlinkEvent event) {
    try {
      String target = (String) event.getHref();

      if ("action:open".equals(target)) // $NON-NLS-1$
      {
        IHandlerService handlerService =
            (IHandlerService) getIntroSite().getService(IHandlerService.class);
        Object result =
            handlerService.executeCommand(
                "name.abuchen.portfolio.ui.commands.openFileCommand", null); // $NON-NLS-1$
        if (result != null) PlatformUI.getWorkbench().getIntroManager().closeIntro(this);
      } else if ("action:new".equals(target)) // $NON-NLS-1$
      {
        IHandlerService handlerService =
            (IHandlerService) getIntroSite().getService(IHandlerService.class);
        handlerService.executeCommand(
            "name.abuchen.portfolio.ui.commands.newFileCommand", null); // $NON-NLS-1$
        PlatformUI.getWorkbench().getIntroManager().closeIntro(this);
      } else if ("action:sample".equals(target)) // $NON-NLS-1$
      {
        openSample("kommer.xml"); // $NON-NLS-1$
      } else if ("action:daxsample".equals(target)) // $NON-NLS-1$
      {
        openSample("dax.xml"); // $NON-NLS-1$
      } else if (target.startsWith("http://")) // $NON-NLS-1$
      {
        IWorkbenchBrowserSupport support = PlatformUI.getWorkbench().getBrowserSupport();
        IWebBrowser browser = support.getExternalBrowser();
        browser.openURL(new URL(target));
      }

    } catch (CommandException e) {
      PortfolioPlugin.log(e);
      MessageDialog.openError(getIntroSite().getShell(), Messages.LabelError, e.getMessage());
    } catch (PartInitException e) {
      PortfolioPlugin.log(e);
      MessageDialog.openError(getIntroSite().getShell(), Messages.LabelError, e.getMessage());
    } catch (MalformedURLException e) {
      PortfolioPlugin.log(e);
      MessageDialog.openError(getIntroSite().getShell(), Messages.LabelError, e.getMessage());
    }
  }
Esempio n. 5
0
  @Override
  public void createPartControl(Composite parent) {
    Composite container = new Composite(parent, SWT.NONE);
    container.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_WHITE));

    container.setLayout(new FormLayout());

    FormToolkit toolkit = new FormToolkit(container.getDisplay());
    Form form = toolkit.createForm(container);

    FormData data = new FormData();
    data.top = new FormAttachment(0, 20);
    data.left = new FormAttachment(50, -100);
    data.right = new FormAttachment(50, 100);
    data.bottom = new FormAttachment(100, -20);

    form.setLayoutData(data);

    // form.setText(Messages.IntroTitle);

    FillLayout layout = new FillLayout();
    layout.marginHeight = layout.marginWidth = 5;
    form.getBody().setLayout(layout);

    FormText text = toolkit.createFormText(form.getBody(), true);

    StringBuilder buf = new StringBuilder();
    buf.append("<form>"); // $NON-NLS-1$
    buf.append("<p><img href=\"logo\"/></p>"); // $NON-NLS-1$
    buf.append("<p><span color=\"header\" font=\"header\">") // $NON-NLS-1$
        .append(Messages.IntroTitle) //
        .append("</span></p>"); // $NON-NLS-1$
    addLink(buf, "action:open", Messages.IntroOpenFile, Messages.IntroOpenFileText); // $NON-NLS-1$
    addLink(buf, "action:new", Messages.IntroNewFile, Messages.IntroNewFileText); // $NON-NLS-1$
    addLink(
        buf,
        "action:sample",
        Messages.IntroOpenSample,
        Messages.IntroOpenSampleText); // $NON-NLS-1$
    addLink(
        buf,
        "action:daxsample",
        Messages.IntroOpenDaxSample,
        Messages.IntroOpenDaxSampleText); // $NON-NLS-1$
    addLink(
        buf,
        "http://buchen.github.com/portfolio/new_and_noteworthy.html", //$NON-NLS-1$
        Messages.IntroReadNews,
        Messages.IntroReadNewsText);
    buf.append("</form>"); // $NON-NLS-1$
    text.setText(buf.toString(), true, false);
    text.setImage("logo", PortfolioPlugin.image(PortfolioPlugin.IMG_LOGO)); // $NON-NLS-1$
    text.setColor("header", toolkit.getColors().getColor(IFormColors.TITLE)); // $NON-NLS-1$
    text.setFont("header", JFaceResources.getHeaderFont()); // $NON-NLS-1$
    text.addHyperlinkListener(this);
  }
Esempio n. 6
0
  @Override
  public boolean performFinish() {
    Object exportItem = exportPage.getExportItem();
    Class<?> exportClass = exportPage.getExportClass();

    File file = getFile(exportItem);

    try {
      // account transactions
      if (exportItem == AccountTransaction.class) {
        new CSVExporter().exportAccountTransactions(file, client.getAccounts());
      } else if (exportClass == AccountTransaction.class) {
        new CSVExporter().exportAccountTransactions(file, (Account) exportItem);
      }

      // portfolio transactions
      else if (exportItem == PortfolioTransaction.class) {
        new CSVExporter().exportPortfolioTransactions(file, client.getPortfolios());
      } else if (exportClass == PortfolioTransaction.class) {
        new CSVExporter().exportPortfolioTransactions(file, (Portfolio) exportItem);
      }

      // master data
      else if (exportItem == Security.class) {
        new CSVExporter()
            .exportSecurityMasterData(
                new File(file, Messages.ExportWizardSecurityMasterData + ".csv"),
                client.getSecurities()); // $NON-NLS-1$
      } else if (exportClass == Security.class) {
        if (Messages.ExportWizardSecurityMasterData.equals(exportItem))
          new CSVExporter().exportSecurityMasterData(file, client.getSecurities());
        else if (Messages.ExportWizardMergedSecurityPrices.equals(exportItem))
          new CSVExporter().exportMergedSecurityPrices(file, client.getSecurities());
      }

      // historical quotes
      else if (exportItem == SecurityPrice.class) {
        new CSVExporter().exportSecurityPrices(file, client.getSecurities());
      } else if (exportClass == SecurityPrice.class) {
        new CSVExporter().exportSecurityPrices(file, (Security) exportItem);
      } else {
        throw new UnsupportedOperationException(
            MessageFormat.format(Messages.ExportWizardUnsupportedExport, exportClass, exportItem));
      }
    } catch (IOException e) {
      PortfolioPlugin.log(e);
      MessageDialog.openError(getShell(), Messages.ExportWizardErrorExporting, e.getMessage());
    }

    return true;
  }
Esempio n. 7
0
  private void addExportButton(ToolBar toolBar) {
    Action export =
        new Action() {
          @Override
          public void run() {
            new TableViewerCSVExporter(securities.getTableViewer()) //
                .export(getTitle() + ".csv"); // $NON-NLS-1$
          }
        };
    export.setImageDescriptor(PortfolioPlugin.descriptor(PortfolioPlugin.IMG_EXPORT));
    export.setToolTipText(Messages.MenuExportData);

    new ActionContributionItem(export).fill(toolBar, -1);
  }
  private void addConfigButton(ToolBar toolBar) {
    Action save =
        new Action() {
          @Override
          public void run() {
            picker.showSaveMenu(getActiveShell());
          }
        };
    save.setImageDescriptor(PortfolioPlugin.descriptor(PortfolioPlugin.IMG_SAVE));
    save.setToolTipText(Messages.MenuSaveChart);
    new ActionContributionItem(save).fill(toolBar, -1);

    Action config =
        new Action() {
          @Override
          public void run() {
            picker.showMenu(getActiveShell());
          }
        };
    config.setImageDescriptor(PortfolioPlugin.descriptor(PortfolioPlugin.IMG_CONFIG));
    config.setToolTipText(Messages.MenuConfigureChart);
    new ActionContributionItem(config).fill(toolBar, -1);
  }
Esempio n. 9
0
  private void addConfigButton(ToolBar toolBar) {
    Action config =
        new Action() {
          @Override
          public void run() {
            securities
                .getColumnHelper()
                .showHideShowColumnsMenu(getClientEditor().getSite().getShell());
          }
        };
    config.setImageDescriptor(PortfolioPlugin.descriptor(PortfolioPlugin.IMG_CONFIG));
    config.setToolTipText(Messages.MenuShowHideColumns);

    new ActionContributionItem(config).fill(toolBar, -1);
  }
  private void setChartSeries() {
    List<Exception> warnings = new ArrayList<Exception>();

    for (DataSeries item : picker.getSelectedDataSeries()) {
      if (item.getType() == Client.class)
        addClient(item, (ClientDataSeries) item.getInstance(), warnings);
      else if (item.getType() == Security.class)
        addSecurity(item, (Security) item.getInstance(), warnings);
      else if (item.getType() == Portfolio.class)
        addPortfolio(item, (Portfolio) item.getInstance(), warnings);
      else if (item.getType() == Account.class)
        addAccount(item, (Account) item.getInstance(), warnings);
      else if (item.getType() == Classification.class)
        addClassification(item, (Classification) item.getInstance(), warnings);
    }

    PortfolioPlugin.log(warnings);
  }
Esempio n. 11
0
  private void createFromColumnConfig(String config) {
    if (config == null || config.trim().length() == 0) return;

    try {
      policy.setRedraw(false);
      int count = policy.getColumnCount();

      StringTokenizer tokens = new StringTokenizer(config, ";"); // $NON-NLS-1$
      while (tokens.hasMoreTokens()) {
        Matcher matcher = CONFIG_PATTERN.matcher(tokens.nextToken());
        if (!matcher.matches()) continue;

        // index
        Column col = id2column.get(matcher.group(1));
        if (col == null) continue;

        // option
        String o = matcher.group(2);
        Integer option = o != null ? Integer.parseInt(o) : null;

        // direction
        String d = matcher.group(3);
        Integer direction = d != null ? Integer.parseInt(d) : null;

        // width
        int width = Integer.parseInt(matcher.group(4));

        policy.create(col, option, direction, width);
      }

      for (int ii = 0; ii < count; ii++) policy.getColumn(0).dispose();
    } catch (NumberFormatException e) {
      PortfolioPlugin.log(e);
    } finally {
      policy.setRedraw(true);
    }
  }