Search in sources :

Example 1 with TaxonomyTemplate

use of name.abuchen.portfolio.model.TaxonomyTemplate in project portfolio by buchen.

the class OpenSampleHandler method applyTaxonomyLabels.

private void applyTaxonomyLabels(TaxonomyTemplate template, Taxonomy taxonomy) {
    Taxonomy original = template.buildOriginal();
    taxonomy.setName(original.getName());
    taxonomy.setDimensions(original.getDimensions());
    Map<String, Classification> translated = // 
    original.getAllClassifications().stream().collect(Collectors.toMap(c -> c.getId(), c -> c));
    taxonomy.foreach(new Visitor() {

        @Override
        public void visit(Classification classification) {
            Classification t = translated.get(classification.getId());
            if (t != null) {
                classification.setName(t.getName());
                classification.setNote(t.getNote());
            }
        }
    });
}
Also used : Client(name.abuchen.portfolio.model.Client) IServiceConstants(org.eclipse.e4.ui.services.IServiceConstants) ProgressMonitorInputStream(name.abuchen.portfolio.util.ProgressMonitorInputStream) EPartService(org.eclipse.e4.ui.workbench.modeling.EPartService) Execute(org.eclipse.e4.core.di.annotations.Execute) Classification(name.abuchen.portfolio.model.Classification) MPartStack(org.eclipse.e4.ui.model.application.ui.basic.MPartStack) Visitor(name.abuchen.portfolio.model.Taxonomy.Visitor) Inject(javax.inject.Inject) MPart(org.eclipse.e4.ui.model.application.ui.basic.MPart) TokenReplacingReader(name.abuchen.portfolio.util.TokenReplacingReader) ResourceBundle(java.util.ResourceBundle) Map(java.util.Map) ClientFactory(name.abuchen.portfolio.model.ClientFactory) Named(javax.inject.Named) ITokenResolver(name.abuchen.portfolio.util.TokenReplacingReader.ITokenResolver) Taxonomy(name.abuchen.portfolio.model.Taxonomy) TaxonomyTemplate(name.abuchen.portfolio.model.TaxonomyTemplate) UIConstants(name.abuchen.portfolio.ui.UIConstants) MApplication(org.eclipse.e4.ui.model.application.MApplication) Shell(org.eclipse.swt.widgets.Shell) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) MissingResourceException(java.util.MissingResourceException) IOException(java.io.IOException) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) InvocationTargetException(java.lang.reflect.InvocationTargetException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) UISynchronize(org.eclipse.e4.ui.di.UISynchronize) PortfolioPlugin(name.abuchen.portfolio.ui.PortfolioPlugin) EModelService(org.eclipse.e4.ui.workbench.modeling.EModelService) PartState(org.eclipse.e4.ui.workbench.modeling.EPartService.PartState) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) InputStream(java.io.InputStream) Visitor(name.abuchen.portfolio.model.Taxonomy.Visitor) Taxonomy(name.abuchen.portfolio.model.Taxonomy) Classification(name.abuchen.portfolio.model.Classification)

Example 2 with TaxonomyTemplate

use of name.abuchen.portfolio.model.TaxonomyTemplate in project portfolio by buchen.

the class AddTaxonomyPage method createControl.

@Override
public void createControl(Composite parent) {
    Composite container = new Composite(parent, SWT.NONE);
    setControl(container);
    TableColumnLayout layout = new TableColumnLayout();
    container.setLayout(layout);
    final TableViewer viewer = new TableViewer(container);
    TableViewerColumn column = new TableViewerColumn(viewer, SWT.NONE);
    layout.setColumnData(column.getColumn(), new ColumnWeightData(90));
    column.getColumn().setText(Messages.ColumnTaxonomy);
    column.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            return ((TaxonomyTemplate) element).getName();
        }
    });
    column = new TableViewerColumn(viewer, SWT.NONE);
    layout.setColumnData(column.getColumn(), new ColumnWeightData(10));
    column.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            return null;
        }

        @Override
        public Image getImage(Object element) {
            TaxonomyTemplate t = (TaxonomyTemplate) element;
            if (taxonomiesAdded.contains(t.getId()))
                return Images.CHECK.image();
            else
                return null;
        }
    });
    viewer.addDoubleClickListener(new IDoubleClickListener() {

        @Override
        public void doubleClick(DoubleClickEvent event) {
            TaxonomyTemplate template = (TaxonomyTemplate) ((IStructuredSelection) event.getSelection()).getFirstElement();
            if (template != null && !taxonomiesAdded.contains(template.getId())) {
                taxonomiesAdded.add(template.getId());
                client.addTaxonomy(template.build());
                viewer.refresh(template);
            }
        }
    });
    viewer.getTable().setHeaderVisible(true);
    viewer.setContentProvider(ArrayContentProvider.getInstance());
    viewer.setInput(TaxonomyTemplate.list());
    setPageComplete(true);
}
Also used : ColumnWeightData(org.eclipse.jface.viewers.ColumnWeightData) Composite(org.eclipse.swt.widgets.Composite) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Image(org.eclipse.swt.graphics.Image) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) TaxonomyTemplate(name.abuchen.portfolio.model.TaxonomyTemplate) TableViewer(org.eclipse.jface.viewers.TableViewer) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn)

Example 3 with TaxonomyTemplate

use of name.abuchen.portfolio.model.TaxonomyTemplate in project portfolio by buchen.

the class ClientEditorSidebar method taxonomyCreateMenuAboutToShow.

private void taxonomyCreateMenuAboutToShow(IMenuManager manager) {
    manager.add(new Action(Messages.MenuTaxonomyCreate) {

        @Override
        public void run() {
            String name = askTaxonomyName(Messages.LabelNewTaxonomy);
            if (name == null)
                return;
            Taxonomy taxonomy = new Taxonomy(name);
            taxonomy.setRootNode(new Classification(UUID.randomUUID().toString(), name));
            addAndOpenTaxonomy(taxonomy);
        }
    });
    manager.add(new Separator());
    manager.add(new LabelOnly(Messages.LabelTaxonomyTemplates));
    for (final TaxonomyTemplate template : TaxonomyTemplate.list()) {
        manager.add(new Action(template.getName()) {

            @Override
            public void run() {
                addAndOpenTaxonomy(template.build());
            }
        });
    }
}
Also used : SimpleAction(name.abuchen.portfolio.ui.util.SimpleAction) Action(org.eclipse.jface.action.Action) Taxonomy(name.abuchen.portfolio.model.Taxonomy) LabelOnly(name.abuchen.portfolio.ui.util.LabelOnly) Classification(name.abuchen.portfolio.model.Classification) TaxonomyTemplate(name.abuchen.portfolio.model.TaxonomyTemplate) Separator(org.eclipse.jface.action.Separator)

Aggregations

TaxonomyTemplate (name.abuchen.portfolio.model.TaxonomyTemplate)3 Classification (name.abuchen.portfolio.model.Classification)2 Taxonomy (name.abuchen.portfolio.model.Taxonomy)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 Reader (java.io.Reader)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 StandardCharsets (java.nio.charset.StandardCharsets)1 Map (java.util.Map)1 MissingResourceException (java.util.MissingResourceException)1 ResourceBundle (java.util.ResourceBundle)1 Collectors (java.util.stream.Collectors)1 Inject (javax.inject.Inject)1 Named (javax.inject.Named)1 Client (name.abuchen.portfolio.model.Client)1 ClientFactory (name.abuchen.portfolio.model.ClientFactory)1 Visitor (name.abuchen.portfolio.model.Taxonomy.Visitor)1 PortfolioPlugin (name.abuchen.portfolio.ui.PortfolioPlugin)1 UIConstants (name.abuchen.portfolio.ui.UIConstants)1