Search in sources :

Example 1 with SortedList

use of com.servoy.j2db.util.SortedList in project servoy-client by Servoy.

the class LFPreferencePanel method createUI.

private void createUI() {
    setLayout(new BorderLayout());
    List lafs = _application.getLAFManager().getLAFInfos(_application);
    _dcbm = new DefaultComboBoxModel();
    _dcbm.addElement(new LookAndFeelInfoWrapper(null));
    String sCurrent = UIManager.getLookAndFeel().getClass().getName();
    String sSystemLAF = UIManager.getSystemLookAndFeelClassName();
    Iterator it = lafs.iterator();
    while (it.hasNext()) {
        LookAndFeelInfo li = (LookAndFeelInfo) it.next();
        _dcbm.addElement(new LookAndFeelInfoWrapper(li));
        if (!sSystemLAF.equals(sCurrent) && sCurrent.equals(li.getClassName())) {
            _current = li;
        }
    }
    String font = _application.getSettings().getProperty("font");
    if (RemoteRunnerChecker.getInstance().isRunningWebStart()) {
        URL webstartbase = _application.getServerURL();
        font = _application.getSettings().getProperty(webstartbase.getHost() + webstartbase.getPort() + "_font", font);
    }
    _selectedFont = PersistHelper.createFont(font);
    lnfBox = new JComboBox(_dcbm);
    String msg = getFontButtonText();
    // $NON-NLS-1$
    if (msg == null)
        msg = _application.getI18NMessage("servoy.preference.lookandfeel.msg.undefined");
    fontButton = new JButton(msg);
    fontButton.addActionListener(this);
    fontButton.setActionCommand("font");
    themes = _application.getLAFManager().getLoadedThemes(_application);
    SortedList sl = new SortedList(StringComparator.INSTANCE);
    // $NON-NLS-1$
    sl.add("");
    Iterator th = themes.keySet().iterator();
    while (th.hasNext()) {
        sl.add(th.next());
    }
    DefaultComboBoxModel modelThemes = new DefaultComboBoxModel(sl.toArray());
    // $NON-NLS-1$
    String n = "";
    if (RemoteRunnerChecker.getInstance().isRunningWebStart()) {
        URL webstartbase = _application.getServerURL();
        // $NON-NLS-1$ //$NON-NLS-2$
        n = _application.getSettings().getProperty(webstartbase.getHost() + webstartbase.getPort() + "_lnf.theme", "");
    } else {
        // $NON-NLS-1$//$NON-NLS-2$
        n = _application.getSettings().getProperty("lnf.theme", "");
    }
    int indx = n.lastIndexOf('.');
    if (indx != -1)
        n = n.substring(indx + 1);
    modelThemes.setSelectedItem(n);
    themesBox = new JComboBox(modelThemes);
    JPanel comp = new JPanel(false);
    comp.setLayout(new GridLayout(3, 1, J2DBClient.BUTTON_SPACING, J2DBClient.BUTTON_SPACING));
    comp.add(lnfBox);
    comp.add(themesBox);
    comp.add(fontButton);
    if (_current != null)
        lnfBox.setSelectedItem(new LookAndFeelInfoWrapper(_current));
    lnfBox.addItemListener(this);
    themesBox.addItemListener(this);
    JPanel label = new JPanel(false);
    label.setLayout(new GridLayout(3, 1, J2DBClient.BUTTON_SPACING, J2DBClient.BUTTON_SPACING));
    // $NON-NLS-1$
    label.add(new JLabel(_application.getI18NMessage("servoy.preference.lookandfeel.label.lnf"), SwingConstants.RIGHT));
    // $NON-NLS-1$
    label.add(new JLabel(_application.getI18NMessage("servoy.preference.lookandfeel.label.theme"), SwingConstants.RIGHT));
    // $NON-NLS-1$
    label.add(new JLabel(_application.getI18NMessage("servoy.preference.lookandfeel.label.defaultFont"), SwingConstants.RIGHT));
    JPanel panel = new JPanel(false);
    panel.setLayout(new BorderLayout(5, 5));
    panel.add(label, BorderLayout.WEST);
    panel.add(comp, BorderLayout.CENTER);
    this.add(panel, BorderLayout.NORTH);
    // $NON-NLS-1$
    _errorLabel = new JLabel("");
    this.add(_errorLabel, BorderLayout.SOUTH);
}
Also used : JPanel(javax.swing.JPanel) LookAndFeelInfo(javax.swing.UIManager.LookAndFeelInfo) JComboBox(javax.swing.JComboBox) JButton(javax.swing.JButton) SortedList(com.servoy.j2db.util.SortedList) JLabel(javax.swing.JLabel) DefaultComboBoxModel(javax.swing.DefaultComboBoxModel) URL(java.net.URL) GridLayout(java.awt.GridLayout) BorderLayout(java.awt.BorderLayout) Iterator(java.util.Iterator) SortedList(com.servoy.j2db.util.SortedList) List(java.util.List)

Example 2 with SortedList

use of com.servoy.j2db.util.SortedList in project servoy-client by Servoy.

the class FormElementHelper method getControlledTabSeqReplacementFor.

/**
 * Generates a Servoy controlled tab-sequence-index. We try to avoid sending default (0 or null) tabSeq even
 * for forms that do use default tab sequence in order to avoid problems with nesting default and non-default tabSeq forms.
 *
 * @param designValue the value the persist holds for the tabSeq.
 * @param form the form containing the persist
 * @param persistIfAvailable the persist. For now, 'component' type properties might work with non-persist-linked FormElements so it could be null.
 * When those become persist based as well this will never be null.
 * @return the requested controlled tabSeq (should make tabSeq be identical to the one shown in developer).
 */
public Integer getControlledTabSeqReplacementFor(Integer designValue, PropertyDescription pd, Form flattenedForm, IPersist persistIfAvailable, // TODO more args will be needed here such as the tabSeq property name or description
FlattenedSolution flattenedSolution, // TODO more args will be needed here such as the tabSeq property name or description
boolean design) {
    // TODO this can be removed when we know we'll always have a persist here; currently don't handle this in any way as it's not supported
    if (persistIfAvailable == null || (nestedCall.get() != null && nestedCall.get().booleanValue()))
        return designValue;
    nestedCall.set(Boolean.TRUE);
    final boolean responsiveForm = flattenedForm.isResponsiveLayout();
    try {
        if (flattenedForm.isFormComponent() && persistIfAvailable instanceof AbstractBase) {
            String mainFormName = ((AbstractBase) persistIfAvailable).getRuntimeProperty(FORM_COMPONENT_FORM_NAME);
            if (mainFormName != null) {
                flattenedForm = flattenedSolution.getFlattenedForm(flattenedSolution.getForm(mainFormName));
                // just return the skip value if this is somehow invalid.
                if (flattenedForm == null)
                    return Integer.valueOf(-2);
            }
        }
        boolean formWasModifiedViaSolutionModel = flattenedSolution.hasCopy(flattenedForm);
        Map<TabSeqProperty, Integer> cachedTabSeq = null;
        if (formWasModifiedViaSolutionModel) {
            Pair<Long, Map<TabSeqProperty, Integer>> pair = flattenedForm.getRuntimeProperty(FORM_TAB_SEQUENCE);
            if (pair != null && flattenedForm.getLastModified() == pair.getLeft().longValue()) {
                cachedTabSeq = pair.getRight();
            }
        } else
            cachedTabSeq = formTabSequences.get(flattenedForm.getUUID());
        if (cachedTabSeq == null) {
            cachedTabSeq = new HashMap<TabSeqProperty, Integer>();
            SortedList<TabSeqProperty> selected = new SortedList<TabSeqProperty>(new Comparator<TabSeqProperty>() {

                public int compare(TabSeqProperty o1, TabSeqProperty o2) {
                    int seq1 = o1.getSeqValue();
                    int seq2 = o2.getSeqValue();
                    if (seq1 == ISupportTabSeq.DEFAULT && seq2 == ISupportTabSeq.DEFAULT) {
                        if (responsiveForm) {
                            if (o1.element.getParent() == o2.element.getParent()) {
                                int positionComparator = PositionComparator.comparePoint(false, o1.getLocation(), o2.getLocation());
                                if (positionComparator != 0) {
                                    return positionComparator;
                                }
                            } else {
                                List<ISupportChilds> ancestors = new ArrayList<ISupportChilds>();
                                IPersist persist = o1.element;
                                while (persist.getParent() instanceof AbstractContainer) {
                                    ancestors.add(persist.getParent());
                                    persist = persist.getParent();
                                }
                                persist = o2.element;
                                while (persist.getParent() instanceof AbstractContainer) {
                                    if (ancestors.contains(persist.getParent())) {
                                        // we found the common ancestor
                                        int index = ancestors.indexOf(persist.getParent());
                                        IPersist comparablePersist = index == 0 ? o1.element : ancestors.get(index - 1);
                                        int positionComparator = PositionComparator.comparePoint(false, ((ISupportBounds) comparablePersist).getLocation(), ((ISupportBounds) persist).getLocation());
                                        if (positionComparator != 0) {
                                            return positionComparator;
                                        }
                                    }
                                    persist = persist.getParent();
                                }
                            }
                        } else {
                            int positionComparator = PositionComparator.comparePoint(false, o1.getLocation(), o2.getLocation());
                            if (positionComparator != 0) {
                                return positionComparator;
                            }
                        }
                    }
                    return compareTabSeq(seq1, o1.element, seq2, o2.element, flattenedSolution);
                }
            });
            Map<TabSeqProperty, List<TabSeqProperty>> listFormComponentMap = new HashMap<TabSeqProperty, List<TabSeqProperty>>();
            List<TabSeqProperty> listFormComponentElements = null;
            TabSeqProperty listFormComponentTabSeq = null;
            Iterator<IFormElement> iterator = flattenedForm.getFlattenedObjects(null).iterator();
            while (iterator.hasNext()) {
                IFormElement formElement = iterator.next();
                if (FormTemplateGenerator.isWebcomponentBean(formElement)) {
                    String componentType = FormTemplateGenerator.getComponentTypeName(formElement);
                    WebObjectSpecification specification = WebComponentSpecProvider.getSpecProviderState().getWebComponentSpecification(componentType);
                    if (specification != null) {
                        Collection<PropertyDescription> properties = specification.getProperties(NGTabSeqPropertyType.NG_INSTANCE);
                        Collection<PropertyDescription> formComponentProperties = specification.getProperties(FormComponentPropertyType.INSTANCE);
                        boolean isListFormComponent = isListFormComponent(formComponentProperties);
                        if (properties != null && properties.size() > 0) {
                            IBasicWebComponent webComponent = (IBasicWebComponent) formElement;
                            for (PropertyDescription tabSeqProperty : properties) {
                                int tabseq = Utils.getAsInteger(webComponent.getProperty(tabSeqProperty.getName()));
                                TabSeqProperty seqProperty = new TabSeqProperty(formElement, tabSeqProperty.getName());
                                if (listFormComponentTabSeq == null && isListFormComponent) {
                                    listFormComponentTabSeq = seqProperty;
                                    listFormComponentElements = new ArrayList<TabSeqProperty>();
                                    listFormComponentMap.put(listFormComponentTabSeq, listFormComponentElements);
                                }
                                if (tabseq >= 0) {
                                    selected.add(seqProperty);
                                } else {
                                    cachedTabSeq.put(seqProperty, Integer.valueOf(-2));
                                }
                            }
                        }
                        addFormComponentProperties(formComponentProperties, formElement, flattenedSolution, cachedTabSeq, selected, listFormComponentElements, design, new HashSet<String>());
                    }
                } else if (formElement instanceof ISupportTabSeq) {
                    if (((ISupportTabSeq) formElement).getTabSeq() >= 0) {
                        selected.add(new TabSeqProperty(formElement, StaticContentSpecLoader.PROPERTY_TABSEQ.getPropertyName()));
                    } else {
                        cachedTabSeq.put(new TabSeqProperty(formElement, StaticContentSpecLoader.PROPERTY_TABSEQ.getPropertyName()), Integer.valueOf(-2));
                    }
                }
            }
            int i = 1;
            for (TabSeqProperty tabSeq : selected) {
                cachedTabSeq.put(tabSeq, Integer.valueOf(i++));
            }
            for (TabSeqProperty tabSeq : listFormComponentMap.keySet()) {
                List<TabSeqProperty> elements = listFormComponentMap.get(tabSeq);
                if (elements != null) {
                    Integer value = cachedTabSeq.get(tabSeq);
                    // all elements inside list form component have same tabindex as the list itself
                    for (TabSeqProperty tabSeqElement : elements) {
                        cachedTabSeq.put(tabSeqElement, value);
                    }
                }
            }
            if (!formWasModifiedViaSolutionModel) {
                formTabSequences.putIfAbsent(flattenedForm.getUUID(), cachedTabSeq);
            } else {
                flattenedForm.setRuntimeProperty(FORM_TAB_SEQUENCE, new Pair<>(Long.valueOf(flattenedForm.getLastModified()), cachedTabSeq));
            }
        }
        IPersist realPersist = flattenedForm.findChild(persistIfAvailable.getUUID());
        if (realPersist == null) {
            realPersist = persistIfAvailable;
        }
        Integer controlledTabSeq = cachedTabSeq.get(new TabSeqProperty(realPersist, pd.getName()));
        // if not in tabSeq, use "skip" value
        if (controlledTabSeq == null)
            controlledTabSeq = Integer.valueOf(-2);
        return controlledTabSeq;
    } finally {
        nestedCall.set(Boolean.FALSE);
    }
}
Also used : WebObjectSpecification(org.sablo.specification.WebObjectSpecification) AbstractContainer(com.servoy.j2db.persistence.AbstractContainer) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) WeakHashMap(java.util.WeakHashMap) SortedList(com.servoy.j2db.util.SortedList) ISupportBounds(com.servoy.j2db.persistence.ISupportBounds) ISupportTabSeq(com.servoy.j2db.persistence.ISupportTabSeq) List(java.util.List) ArrayList(java.util.ArrayList) SortedList(com.servoy.j2db.util.SortedList) IBasicWebComponent(com.servoy.j2db.persistence.IBasicWebComponent) ISupportChilds(com.servoy.j2db.persistence.ISupportChilds) AbstractBase(com.servoy.j2db.persistence.AbstractBase) Point(java.awt.Point) PropertyDescription(org.sablo.specification.PropertyDescription) IFormElement(com.servoy.j2db.persistence.IFormElement) IPersist(com.servoy.j2db.persistence.IPersist) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) WeakHashMap(java.util.WeakHashMap)

Example 3 with SortedList

use of com.servoy.j2db.util.SortedList in project servoy-client by Servoy.

the class RootObjectCache method getRootObjectMetaDatasForType.

RootObjectMetaData[] getRootObjectMetaDatasForType(int objectTypeId) throws RepositoryException {
    AbstractRepository.lock();
    try {
        List list = new SortedList(NameComparator.INSTANCE);
        Iterator<CacheRecord> iterator = rootObjectsById.values().iterator();
        while (iterator.hasNext()) {
            RootObjectMetaData metaData = iterator.next().rootObjectMetaData;
            if (metaData.getObjectTypeId() == objectTypeId) {
                list.add(metaData);
            }
        }
        RootObjectMetaData[] filtered = new RootObjectMetaData[list.size()];
        return (RootObjectMetaData[]) list.toArray(filtered);
    } finally {
        AbstractRepository.unlock();
    }
}
Also used : SortedList(com.servoy.j2db.util.SortedList) SortedList(com.servoy.j2db.util.SortedList) List(java.util.List)

Example 4 with SortedList

use of com.servoy.j2db.util.SortedList in project servoy-client by Servoy.

the class J2DBClient method fillToolbar.

/**
 * @param actions
 */
protected void fillToolbar(Map<String, Action> actions) {
    toolbarsPanel.clear();
    SortedList<Toolbar.ToolbarKey> sortedList = new SortedList<Toolbar.ToolbarKey>();
    createToolBars(sortedList, actions);
    int offsetRow = 0;
    if (sortedList.size() > 0) {
        offsetRow = sortedList.get(0).getRow();
        if (offsetRow == -1)
            offsetRow = 0;
    }
    for (ToolbarKey key : sortedList) {
        if (toolbarsPanel.getToolBar(key.getToolbar().getName()) == null) {
            if (// $NON-NLS-1$
            "edit".equals(key.getToolbar().getName())) {
                fillBrowseToolbar(key.getToolbar(), actions);
            }
            toolbarsPanel.addToolbar(key.getToolbar(), key.getRow() - offsetRow);
            toolbarsPanel.setToolbarVisible(key.getToolbar().getName(), key.isVisible());
        }
    }
}
Also used : SortedList(com.servoy.j2db.util.SortedList) ToolbarKey(com.servoy.j2db.util.toolbar.Toolbar.ToolbarKey) Toolbar(com.servoy.j2db.util.toolbar.Toolbar)

Example 5 with SortedList

use of com.servoy.j2db.util.SortedList in project servoy-client by Servoy.

the class DataRendererFactory method createPortalRenderer.

public IDataRenderer createPortalRenderer(IApplication app, Portal objToRender, Form dataProviderLookup, IScriptExecuter listner, boolean printing, ControllerUndoManager undoManager) throws Exception {
    List<IPersist> allObjectsAsList = objToRender.getAllObjectsAsList();
    List<IFormElement> formElements = new ArrayList<IFormElement>(allObjectsAsList.size());
    for (IPersist persist : allObjectsAsList) {
        if (persist instanceof IFormElement) {
            formElements.add((IFormElement) persist);
        }
    }
    List<IFormElement> children = new SortedList<IFormElement>(new Comparator<IFormElement>() {

        public int compare(IFormElement o1, IFormElement o2) {
            // reverse order, right order for tab sequence
            int result = -PositionComparator.XY_PERSIST_COMPARATOR.compare(o1, o2);
            if (result == 0) {
                return (o1.getFormIndex() - o2.getFormIndex());
            }
            return result;
        }
    }, formElements);
    Iterator<IFormElement> e1 = children.iterator();
    Map emptyDataRenderers = new LinkedHashMap();
    DataRenderer dr = null;
    int height = objToRender.getRowHeight();
    boolean calculateHeight = (height == 0);
    // for safety
    if (height == 0)
        height = 100;
    // int leftBorder = 0;
    // int bottomBorder = 0;
    // if (objToRender.getShowHorizontalLines())
    // {
    // bottomBorder = 1;
    // }
    // if (objToRender.getShowVerticalLines())
    // {
    // leftBorder = 4;
    // }
    boolean showSelection = objToRender.getShowVerticalLines();
    dr = (DataRenderer) getEmptyDataRenderer(ComponentFactory.getWebID(dataProviderLookup, objToRender), "portal_" + objToRender.getName(), app, showSelection);
    setBasicSettings(dr, objToRender.getBackground(), new Dimension(objToRender.getSize().width, height), new Point(0, 0), printing);
    // first is dummy saying is portal
    emptyDataRenderers.put(new Boolean(true), dr);
    dr.setLocation(objToRender.getLocation());
    Border b = ComponentFactoryHelper.createBorder(objToRender.getBorderType());
    Insets ins = new Insets(0, 0, 0, 0);
    if (b != null) {
        ins = ComponentFactoryHelper.getBorderInsetsForNoComponent(b);
    }
    // if (b instanceof EmptyBorder)
    // {
    // ins = ((EmptyBorder)b).getBorderInsets();
    // }
    placeElements(e1, app, dataProviderLookup, listner, emptyDataRenderers, objToRender.getSize().width, -(objToRender.getLocation().x + ins.right), -ins.top, printing, true, undoManager, true, null);
    int biggest_width = 10;
    int biggest_height = calculateHeight ? 0 : height;
    Component[] comps = dr.getComponents();
    boolean hasRowBGColorCalc = objToRender.getRowBGColorCalculation() != null;
    for (Component element : comps) {
        int w = element.getLocation().x + element.getSize().width;
        if (w > biggest_width)
            biggest_width = w;
        if (hasRowBGColorCalc && element instanceof JComponent)
            ((JComponent) element).setOpaque(false);
        if (calculateHeight) {
            int h = element.getLocation().y + element.getSize().height;
            if (h > biggest_height)
                biggest_height = h;
        }
    }
    dr.setSize(new Dimension(biggest_width, biggest_height));
    dr.setPreferredSize(new Dimension(biggest_width, biggest_height));
    if (printing) {
        // sliding inside a multiline portal renderer is nor supported, be we have to attach the springs for resizes
        addSpringsBetweenComponents(app, dr);
    }
    return dr;
}
Also used : Insets(java.awt.Insets) IDataRenderer(com.servoy.j2db.ui.IDataRenderer) ArrayList(java.util.ArrayList) SortedList(com.servoy.j2db.util.SortedList) JComponent(javax.swing.JComponent) Dimension(java.awt.Dimension) Point(java.awt.Point) Point(java.awt.Point) LinkedHashMap(java.util.LinkedHashMap) IFormElement(com.servoy.j2db.persistence.IFormElement) IPersist(com.servoy.j2db.persistence.IPersist) GraphicalComponent(com.servoy.j2db.persistence.GraphicalComponent) IFieldComponent(com.servoy.j2db.ui.IFieldComponent) Component(java.awt.Component) JComponent(javax.swing.JComponent) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Border(javax.swing.border.Border)

Aggregations

SortedList (com.servoy.j2db.util.SortedList)5 List (java.util.List)3 IFormElement (com.servoy.j2db.persistence.IFormElement)2 IPersist (com.servoy.j2db.persistence.IPersist)2 Point (java.awt.Point)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 AbstractBase (com.servoy.j2db.persistence.AbstractBase)1 AbstractContainer (com.servoy.j2db.persistence.AbstractContainer)1 GraphicalComponent (com.servoy.j2db.persistence.GraphicalComponent)1 IBasicWebComponent (com.servoy.j2db.persistence.IBasicWebComponent)1 ISupportBounds (com.servoy.j2db.persistence.ISupportBounds)1 ISupportChilds (com.servoy.j2db.persistence.ISupportChilds)1 ISupportTabSeq (com.servoy.j2db.persistence.ISupportTabSeq)1 IDataRenderer (com.servoy.j2db.ui.IDataRenderer)1 IFieldComponent (com.servoy.j2db.ui.IFieldComponent)1 Toolbar (com.servoy.j2db.util.toolbar.Toolbar)1 ToolbarKey (com.servoy.j2db.util.toolbar.Toolbar.ToolbarKey)1 BorderLayout (java.awt.BorderLayout)1