Révision 2558
tmp/org.txm.core/src/java/org/txm/core/results/TXMResult.java (revision 2558) | ||
---|---|---|
269 | 269 |
|
270 | 270 |
// set result as persistent if AUTO_PERSISTENCE_ENABLED preference is activated |
271 | 271 |
if (TBXPreferences.getInstance().getBoolean(TBXPreferences.AUTO_PERSISTENCE_ENABLED)) { |
272 |
this.userPersistable = true;
|
|
272 |
this.saveParameter(TXMPreferences.PERSITABLE, true);
|
|
273 | 273 |
} |
274 | 274 |
|
275 | 275 |
// retrieving parent from UUID |
... | ... | |
284 | 284 |
|
285 | 285 |
Log.finest("Searching parent with UUID " + parentNodePath + "..."); //$NON-NLS-1$ //$NON-NLS-2$ |
286 | 286 |
|
287 |
// TODO this is quite CPU expensive because 'retrievedParent' is researched in all projects
|
|
287 |
// FIXME: MD: this is quite CPU expensive because 'retrievedParent' researches in all projects
|
|
288 | 288 |
TXMResult retrievedParent = TXMResult.getResult(parentNodePath); |
289 | 289 |
if (retrievedParent != null) { |
290 | 290 |
Log.finest("Parent retrieved from UUID: " + retrievedParent + "."); //$NON-NLS-1$ //$NON-NLS-2$ |
... | ... | |
1583 | 1583 |
/** |
1584 | 1584 |
* Gets the children results specified by their class. |
1585 | 1585 |
* |
1586 |
* @param type
|
|
1586 |
* @param clazz
|
|
1587 | 1587 |
* @return |
1588 | 1588 |
*/ |
1589 |
public List<? extends TXMResult> getChildren(Class type) {
|
|
1590 |
return TXMResult.getNodes(this.children, type, false);
|
|
1589 |
public List<? extends TXMResult> getChildren(Class<? extends TXMResult> clazz) {
|
|
1590 |
return TXMResult.getNodes(this.children, clazz, false);
|
|
1591 | 1591 |
} |
1592 | 1592 |
|
1593 | 1593 |
/** |
1594 | 1594 |
* Gets the children results specified by their class. |
1595 | 1595 |
* |
1596 |
* @param type
|
|
1596 |
* @param clazz
|
|
1597 | 1597 |
* @return |
1598 | 1598 |
*/ |
1599 |
public List<TXMResult> getChildren(Class type, boolean onlyVisible) {
|
|
1600 |
return TXMResult.getNodes(this.children, type, onlyVisible);
|
|
1599 |
public List<TXMResult> getChildren(Class<? extends TXMResult> clazz, boolean onlyVisible) {
|
|
1600 |
return TXMResult.getNodes(this.children, clazz, onlyVisible);
|
|
1601 | 1601 |
} |
1602 | 1602 |
|
1603 | 1603 |
/** |
1604 | 1604 |
* Gets the first child result specified by its class. |
1605 | 1605 |
* |
1606 |
* @param type
|
|
1606 |
* @param clazz
|
|
1607 | 1607 |
* @return the first child if exists otherwise null |
1608 | 1608 |
*/ |
1609 |
public TXMResult getFirstChild(Class type) {
|
|
1610 |
List<TXMResult> children = this.getChildren(type, false);
|
|
1609 |
public TXMResult getFirstChild(Class<? extends TXMResult> clazz) {
|
|
1610 |
List<TXMResult> children = this.getChildren(clazz, false);
|
|
1611 | 1611 |
try { |
1612 | 1612 |
return children.get(0); |
1613 | 1613 |
} |
... | ... | |
1628 | 1628 |
/** |
1629 | 1629 |
* Deletes the children of the specified class. |
1630 | 1630 |
* |
1631 |
* @param type
|
|
1631 |
* @param clazz
|
|
1632 | 1632 |
* @return |
1633 | 1633 |
*/ |
1634 |
public void deleteChildren(Class type) {
|
|
1635 |
List<TXMResult> children = (List<TXMResult>) this.getChildren(type);
|
|
1634 |
public void deleteChildren(Class<? extends TXMResult> clazz) {
|
|
1635 |
List<TXMResult> children = (List<TXMResult>) this.getChildren(clazz);
|
|
1636 | 1636 |
for (int i = 0; i < children.size(); i++) { |
1637 | 1637 |
children.get(i).delete(); |
1638 | 1638 |
} |
1639 | 1639 |
} |
1640 | 1640 |
|
1641 |
/** |
|
1642 |
* Gets the first child. |
|
1643 |
* |
|
1644 |
* @param classSimpleName |
|
1645 |
* @return |
|
1646 |
*/ |
|
1647 |
public TXMResult getFirstChild() { |
|
1648 |
try { |
|
1649 |
return this.children.get(0); |
|
1650 |
} |
|
1651 |
catch (Exception e) { |
|
1652 |
} |
|
1653 |
return null; |
|
1654 |
} |
|
1655 | 1641 |
|
1656 | 1642 |
|
1657 | 1643 |
/** |
1658 |
* Gets the children of all the branch of the specified node in a flat list. |
|
1644 |
* Gets the children of all the branch of the specified node in a flat list according to their specified class.
|
|
1659 | 1645 |
* |
1646 |
* @param parent |
|
1647 |
* @param clazz |
|
1660 | 1648 |
* @return |
1661 | 1649 |
*/ |
1662 | 1650 |
protected static List<TXMResult> getDeepChildren(TXMResult parent, Class<? extends TXMResult> clazz) { |
1663 | 1651 |
|
1664 | 1652 |
List<TXMResult> results = new ArrayList<>(); |
1665 |
List<? extends TXMResult> cc = parent.getChildren(clazz); |
|
1666 |
for (TXMResult r : cc) { |
|
1667 |
results.add(r); |
|
1668 |
results.addAll(r.getDeepChildren()); |
|
1653 |
List<? extends TXMResult> children = parent.getChildren(clazz); |
|
1654 |
|
|
1655 |
for (int i = 0; i < children.size(); i++) { |
|
1656 |
TXMResult child = children.get(i); |
|
1657 |
results.add(child); |
|
1658 |
results.addAll(child.getDeepChildren(clazz)); |
|
1669 | 1659 |
} |
1670 | 1660 |
return results; |
1671 | 1661 |
} |
... | ... | |
1684 | 1674 |
* |
1685 | 1675 |
* @return |
1686 | 1676 |
*/ |
1687 |
public static List<TXMResult> getDeepChildren(TXMResult r) { |
|
1688 |
return TXMResult.getDeepChildren(r, null); |
|
1677 |
public static List<TXMResult> getDeepChildren(TXMResult result) {
|
|
1678 |
return TXMResult.getDeepChildren(result, null);
|
|
1689 | 1679 |
} |
1690 | 1680 |
|
1691 | 1681 |
/** |
... | ... | |
1698 | 1688 |
} |
1699 | 1689 |
|
1700 | 1690 |
/** |
1701 |
* Gets the TXMResult specified by its UUID in the children of the specified root result. |
|
1691 |
* Gets the TXMResult specified by its node path (UUID) in the children of the specified root result. |
|
1692 |
* Returns the root itself if the specified node path is equal to the root node path. |
|
1702 | 1693 |
* |
1703 |
* @param branchRoot
|
|
1704 |
* @param UUID
|
|
1694 |
* @param root
|
|
1695 |
* @param nodePath
|
|
1705 | 1696 |
* @return |
1706 | 1697 |
*/ |
1707 | 1698 |
public static TXMResult getResult(TXMResult root, String nodePath) { |
1708 |
TXMResult result = null; |
|
1699 |
|
|
1700 |
// returns the root itself if the specified node path is equal to the root node path |
|
1709 | 1701 |
if (root.getParametersNodePath().equals(nodePath)) { |
1710 |
return root; // root is the node we are looking for
|
|
1702 |
return root; |
|
1711 | 1703 |
} |
1712 | 1704 |
else { |
1713 |
List<TXMResult> results = root.getChildren(); |
|
1714 |
for (int i = 0; i < results.size(); i++) { |
|
1715 |
if (results.get(i).getParametersNodePath().equals(nodePath)) { |
|
1716 |
return results.get(i); // a direct children is the node we are looking for |
|
1705 |
|
|
1706 |
List<TXMResult> children = root.getChildren(); |
|
1707 |
|
|
1708 |
// pass 1: to optimize, search in direct children |
|
1709 |
for (int i = 0; i < children.size(); i++) { |
|
1710 |
if (children.get(i).getParametersNodePath().equals(nodePath)) { |
|
1711 |
return children.get(i); |
|
1717 | 1712 |
} |
1718 | 1713 |
} |
1719 | 1714 |
|
1720 |
for (int i = 0; i < results.size(); i++) { |
|
1721 |
TXMResult r = getResult(results.get(i), nodePath); |
|
1722 |
if (r != null) { |
|
1723 |
return r; // a deep children is the node we are looking for |
|
1715 |
// pass 2: deep recursively search in all children |
|
1716 |
for (int i = 0; i < children.size(); i++) { |
|
1717 |
TXMResult result = getResult(children.get(i), nodePath); |
|
1718 |
if (result != null) { |
|
1719 |
return result; |
|
1724 | 1720 |
} |
1725 | 1721 |
} |
1726 | 1722 |
} |
1723 |
|
|
1727 | 1724 |
return null; // not found |
1728 | 1725 |
} |
1729 | 1726 |
|
1730 | 1727 |
/** |
1731 |
* Gets the TXMResult specified by its UUID in the children of the Toolbox Workspace member.
|
|
1728 |
* Gets the TXMResult specified by its node path (UUID) in the children of the Toolbox Workspace (root of the tree).
|
|
1732 | 1729 |
* |
1733 |
* @param UUID
|
|
1730 |
* @param nodePath
|
|
1734 | 1731 |
* @return |
1735 | 1732 |
*/ |
1736 | 1733 |
public static TXMResult getResult(String nodePath) { |
... | ... | |
1738 | 1735 |
} |
1739 | 1736 |
|
1740 | 1737 |
/** |
1741 |
* Filters the nodes specified by their class and their visibility state.
|
|
1738 |
* Filters the nodes of the specified source nodes list according to by their class and their visibility state.
|
|
1742 | 1739 |
* |
1743 |
* @param type |
|
1744 |
* @return |
|
1740 |
* @param srcNodes |
|
1741 |
* @param clazz |
|
1742 |
* @param onlyVisible |
|
1743 |
* @return a new filtered nodes list |
|
1745 | 1744 |
*/ |
1746 |
protected static List<TXMResult> getNodes(List<TXMResult> srcNodes, Class<? extends TXMResult> type, boolean onlyVisible) {
|
|
1745 |
protected static List<TXMResult> getNodes(List<TXMResult> srcNodes, Class<? extends TXMResult> clazz, boolean onlyVisible) {
|
|
1747 | 1746 |
List<TXMResult> nodes = new ArrayList<>(); |
1748 | 1747 |
for (TXMResult child : srcNodes) { |
1749 | 1748 |
try { |
1750 |
if ((type == null ||
|
|
1751 |
child.getClass().asSubclass(type) != null)
|
|
1749 |
if ((clazz == null ||
|
|
1750 |
child.getClass().asSubclass(clazz) != null)
|
|
1752 | 1751 |
&& (onlyVisible == false || child.isVisible())) { |
1753 | 1752 |
nodes.add(child); |
1754 | 1753 |
} |
1755 | 1754 |
|
1756 | 1755 |
// add children of a non visible result |
1757 | 1756 |
else if (!child.isVisible() && child.hasChildren()) { |
1758 |
List<TXMResult> subChidlren = child.getChildren(type, onlyVisible);
|
|
1757 |
List<TXMResult> subChidlren = child.getChildren(clazz, onlyVisible);
|
|
1759 | 1758 |
nodes.addAll(subChidlren); |
1760 | 1759 |
} |
1761 | 1760 |
} |
... | ... | |
1778 | 1777 |
|
1779 | 1778 |
/** |
1780 | 1779 |
* Gets the root parent of the branch. |
1780 |
* Returns the result itself if it's the root. |
|
1781 | 1781 |
* |
1782 | 1782 |
* @return |
1783 | 1783 |
*/ |
... | ... | |
1795 | 1795 |
|
1796 | 1796 |
|
1797 | 1797 |
/** |
1798 |
* Gets the first parent of the specified class, eg. this.getFirstParent(Partition.class); |
|
1798 |
* Gets the first parent of the specified class, e.g. this.getFirstParent(Partition.class);
|
|
1799 | 1799 |
* |
1800 |
* @param type
|
|
1801 |
* @return |
|
1800 |
* @param clazz the class of parent to look for
|
|
1801 |
* @return the first parent of the specified class if exist otherwise null
|
|
1802 | 1802 |
*/ |
1803 |
public TXMResult getFirstParent(Class type) {
|
|
1803 |
public TXMResult getFirstParent(Class<? extends TXMResult> clazz) {
|
|
1804 | 1804 |
TXMResult node = null; |
1805 | 1805 |
TXMResult parent = this.parent; |
1806 | 1806 |
do { |
1807 | 1807 |
if (parent != null) { |
1808 |
if (parent.getClass().equals(type)) {
|
|
1808 |
if (parent.getClass().equals(clazz)) {
|
|
1809 | 1809 |
node = parent; |
1810 | 1810 |
} |
1811 | 1811 |
|
... | ... | |
1819 | 1819 |
|
1820 | 1820 |
|
1821 | 1821 |
/** |
1822 |
* Checks if the specified result is a child. |
|
1822 |
* Checks if the specified result is a child of this result.
|
|
1823 | 1823 |
* |
1824 |
* @return |
|
1824 |
* @return true if the specified result is a child of this result otherwise false
|
|
1825 | 1825 |
*/ |
1826 | 1826 |
public boolean isChild(TXMResult child) { |
1827 | 1827 |
return this.getDeepChildren().contains(child); |
... | ... | |
1829 | 1829 |
|
1830 | 1830 |
/** |
1831 | 1831 |
* Gets the sibling nodes of this node result. |
1832 |
* Returns an empty list if the node has no siblings. |
|
1833 |
* |
|
1834 |
* @return a list of the sibling nodes of this result |
|
1832 | 1835 |
*/ |
1833 | 1836 |
public List<TXMResult> getSiblings() { |
1834 | 1837 |
List<TXMResult> sibling = new ArrayList<>(); |
... | ... | |
1841 | 1844 |
|
1842 | 1845 |
/** |
1843 | 1846 |
* Gets the sibling nodes of this node result, specified by their class. |
1847 |
* Returns an empty list if the node has no siblings of the specified class. |
|
1848 |
* |
|
1849 |
* @param clazz the class of siblings to look for |
|
1850 |
* @return |
|
1844 | 1851 |
*/ |
1845 |
public List<TXMResult> getSiblings(Class type) {
|
|
1852 |
public List<TXMResult> getSiblings(Class<? extends TXMResult> clazz) {
|
|
1846 | 1853 |
List<TXMResult> sibling = new ArrayList<>(); |
1847 | 1854 |
if (this.parent != null) { |
1848 |
sibling.addAll(TXMResult.getNodes(this.parent.getChildren(), type, true));
|
|
1855 |
sibling.addAll(TXMResult.getNodes(this.parent.getChildren(), clazz, true));
|
|
1849 | 1856 |
sibling.remove(this); |
1850 | 1857 |
} |
1851 | 1858 |
return sibling; |
... | ... | |
1854 | 1861 |
/** |
1855 | 1862 |
* Checks if the result must be displayed. |
1856 | 1863 |
* |
1857 |
* @return |
|
1864 |
* @return true if the result must be displayed otherwise false
|
|
1858 | 1865 |
*/ |
1859 | 1866 |
public boolean isVisible() { |
1860 | 1867 |
return this.visible; |
1861 | 1868 |
} |
1862 | 1869 |
|
1870 |
/** |
|
1871 |
* Checks if the parent of this result must be displayed. |
|
1872 |
* |
|
1873 |
* @return true if the parent of this result must be displayed otherwise false |
|
1874 |
*/ |
|
1863 | 1875 |
public boolean isParentVisible() { |
1864 | 1876 |
return parent != null && (parent.isVisible() || parent.isInternalPersistable()); |
1865 | 1877 |
} |
... | ... | |
1869 | 1881 |
* Dedicated to UI purposes. |
1870 | 1882 |
* |
1871 | 1883 |
* @param visible |
1872 |
* @return |
|
1873 | 1884 |
*/ |
1874 | 1885 |
public void setVisible(boolean visible) { |
1875 | 1886 |
this.visible = visible; |
1876 | 1887 |
} |
1877 | 1888 |
|
1878 | 1889 |
/** |
1879 |
* Sets the parent. |
|
1890 |
* Sets the parent of this result.
|
|
1880 | 1891 |
* |
1881 |
* @param parent |
|
1892 |
* @param parent the parent to set
|
|
1882 | 1893 |
*/ |
1883 | 1894 |
public void setParent(TXMResult parent) { |
1884 | 1895 |
this.parent = parent; |
1885 | 1896 |
} |
1886 | 1897 |
|
1887 | 1898 |
/** |
1888 |
* Gets the parent. |
|
1899 |
* Gets the parent of this result.
|
|
1889 | 1900 |
* |
1890 | 1901 |
* @return the parent |
1891 | 1902 |
*/ |
... | ... | |
2768 | 2779 |
* |
2769 | 2780 |
* @param userPersistable the state to set |
2770 | 2781 |
*/ |
2771 |
protected void setUserPersistable(boolean userPersistable, boolean deep) { |
|
2782 |
public void setUserPersistable(boolean userPersistable) { |
|
2783 |
|
|
2784 |
if (this.userPersistable == userPersistable) { |
|
2785 |
return; |
|
2786 |
} |
|
2787 |
|
|
2772 | 2788 |
this.userPersistable = userPersistable; |
2773 | 2789 |
|
2774 | 2790 |
// 1- MANAGE THE PARENTS |
2775 | 2791 |
// recursively force the persistable state of the parents if this result is set to persistable |
2776 | 2792 |
if (userPersistable && this.parent != null && !this.parent.isInternalPersistable()) { |
2777 |
this.parent.setUserPersistable(true, false);
|
|
2793 |
this.parent.setUserPersistable(true); |
|
2778 | 2794 |
} |
2779 | 2795 |
// recursively unpersist hidden parents |
2780 | 2796 |
else if (!userPersistable && !this.parent.isVisible()) { |
2781 |
this.parent.setUserPersistable(false, false);
|
|
2797 |
this.parent.setUserPersistable(false); |
|
2782 | 2798 |
} |
2783 | 2799 |
// 2- MANAGE THE CHILDREN |
2784 | 2800 |
// recursively force non-persistable state of children if this result is set to non-persistable |
2785 | 2801 |
// also transfer this result state to its children marked as "must be synchronized with parent" |
2786 |
if (deep) { |
|
2787 |
for (TXMResult child : this.getChildren()) { |
|
2788 |
if (!userPersistable || child.mustBeSynchronizedWithParent()) { |
|
2789 |
child.setUserPersistable(userPersistable); |
|
2790 |
} |
|
2802 |
for (TXMResult child : this.getChildren()) { |
|
2803 |
if (!userPersistable || child.mustBeSynchronizedWithParent()) { |
|
2804 |
child.setUserPersistable(userPersistable); |
|
2791 | 2805 |
} |
2792 | 2806 |
} |
2793 | 2807 |
|
... | ... | |
2804 | 2818 |
} |
2805 | 2819 |
} |
2806 | 2820 |
|
2807 |
/** |
|
2808 |
* Sets the user defined persistable state of the result and its children. |
|
2809 |
* |
|
2810 |
* @param userPersistable |
|
2811 |
*/ |
|
2812 |
public void setUserPersistable(boolean userPersistable) { |
|
2813 |
this.setUserPersistable(userPersistable, true); |
|
2814 |
} |
|
2815 | 2821 |
|
2816 | 2822 |
/** |
2817 | 2823 |
* Swaps the user persistable state. |
tmp/org.txm.chartsengine.rcp/src/org/txm/chartsengine/rcp/editors/ChartEditor.java (revision 2558) | ||
---|---|---|
30 | 30 |
|
31 | 31 |
/** |
32 | 32 |
* Base class of all charts SWT <code>EditorPart</code> subclasses. |
33 |
* |
|
33 | 34 |
* @author sjacquot |
34 | 35 |
* |
35 | 36 |
*/ |
36 |
public abstract class ChartEditor<T extends ChartResult> extends TXMEditor<ChartResult>{ |
|
37 |
|
|
37 |
public abstract class ChartEditor<T extends ChartResult> extends TXMEditor<ChartResult> { |
|
38 | 38 |
|
39 |
|
|
39 | 40 |
public final static String CONTEXT_ID_CHART_EDITOR = ChartEditor.class.getName(); |
40 | 41 |
|
41 | 42 |
|
42 | 43 |
// ChartEditor RCP context activation/deactivation |
43 |
static {
|
|
44 |
static {
|
|
44 | 45 |
|
45 | 46 |
IPartService service = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getPartService(); |
46 | 47 |
service.addPartListener(new IPartListener() { |
... | ... | |
53 | 54 |
|
54 | 55 |
@Override |
55 | 56 |
public void partDeactivated(IWorkbenchPart part) { |
56 |
if(part instanceof ChartEditor) {
|
|
57 |
if (part instanceof ChartEditor) {
|
|
57 | 58 |
((ChartEditor) part).onPartDeactivated(); |
58 | 59 |
} |
59 | 60 |
} |
... | ... | |
72 | 73 |
|
73 | 74 |
@Override |
74 | 75 |
public void partActivated(IWorkbenchPart part) { |
75 |
if(part instanceof ChartEditor) {
|
|
76 |
if (part instanceof ChartEditor) {
|
|
76 | 77 |
((ChartEditor) part).onPartActivated(); |
77 | 78 |
} |
78 | 79 |
} |
... | ... | |
83 | 84 |
|
84 | 85 |
/** |
85 | 86 |
* SWT chart components provider used to create the chart composite. |
86 |
* Store it allows the switch of component provider in the RCP in keeping the chart editors in a coherent state, by testing that the SWT Components providers charts engine match the result charts engine. |
|
87 |
* Store it allows the switch of component provider in the RCP in keeping the chart editors in a coherent state, by testing that the SWT Components providers charts engine match the result charts |
|
88 |
* engine. |
|
87 | 89 |
*/ |
88 | 90 |
protected SWTChartsComponentsProvider swtChartsComponentsProvider; |
89 |
|
|
91 |
|
|
90 | 92 |
/** |
91 | 93 |
* The tool bar. |
92 | 94 |
*/ |
93 | 95 |
protected ChartEditorToolBar chartToolBar; |
94 |
|
|
96 |
|
|
95 | 97 |
/** |
96 | 98 |
* Export chart editor view tool item button. |
97 | 99 |
*/ |
98 | 100 |
protected ToolItem exportChartEditorViewButton; |
99 |
|
|
101 |
|
|
100 | 102 |
/** |
101 | 103 |
* Copy chart view to clipboard tool item button. |
102 | 104 |
*/ |
... | ... | |
116 | 118 |
* The advanced rendering parameters group. |
117 | 119 |
*/ |
118 | 120 |
protected Group advancedToolBarGroup; |
119 |
|
|
121 |
|
|
120 | 122 |
/** |
121 | 123 |
* The chart drawing area composite. |
122 | 124 |
*/ |
123 | 125 |
protected ChartComposite chartComposite; |
124 |
|
|
126 |
|
|
125 | 127 |
/** |
126 | 128 |
* To check whether this editor was already opened when calling SWTChartsComponentsProvider.openEditor(). |
127 | 129 |
*/ |
... | ... | |
131 | 133 |
* The multi pages editor which contains this editor if exists. |
132 | 134 |
*/ |
133 | 135 |
protected TXMMultiPageEditor parentMultiPagesEditor = null; |
134 |
|
|
136 |
|
|
135 | 137 |
/** |
136 | 138 |
* Token used to deactivate the context after it has been activated. |
137 |
* The context is used by the RCP to bind keys or contextual menu to an editor.
|
|
139 |
* The context is used by the RCP to bind keys or contextual menu to an editor. |
|
138 | 140 |
*/ |
139 | 141 |
protected IContextActivation contextActivationToken; |
140 | 142 |
|
141 |
|
|
143 |
|
|
142 | 144 |
/** |
143 | 145 |
* |
144 | 146 |
*/ |
145 |
public ChartEditor() {
|
|
147 |
public ChartEditor() {
|
|
146 | 148 |
super(); |
147 | 149 |
} |
148 |
|
|
149 |
|
|
150 |
|
|
151 |
|
|
150 | 152 |
/** |
151 | 153 |
* Creates a new editor. |
154 |
* |
|
152 | 155 |
* @param swtComponentsProvider |
153 | 156 |
* @param chartEditorInput |
154 | 157 |
*/ |
... | ... | |
158 | 161 |
|
159 | 162 |
this.wasAlreadyOpened = false; |
160 | 163 |
} |
161 |
|
|
162 | 164 |
|
165 |
|
|
163 | 166 |
/** |
164 | 167 |
* Subclasses manual creation. |
165 |
* @throws Exception |
|
168 |
* |
|
169 |
* @throws Exception |
|
166 | 170 |
*/ |
167 | 171 |
public abstract void __createPartControl() throws Exception; |
168 | 172 |
|
... | ... | |
173 | 177 |
// Toolbar |
174 | 178 |
this.chartToolBar = new ChartEditorToolBar(this, this.getFirstLineComposite(), null, SWT.FLAT | SWT.RIGHT); |
175 | 179 |
this.getFirstLineComposite().getLayout().numColumns += 1; |
176 |
|
|
180 |
|
|
177 | 181 |
this.exportChartEditorViewButton = this.chartToolBar.getItemByContributionId("exportChartEditorView"); //$NON-NLS-1$ |
178 | 182 |
this.copyChartViewToClipboardButton = this.chartToolBar.getItemByContributionId("copyChartViewToClipboard"); //$NON-NLS-1$ |
179 | 183 |
|
180 | 184 |
|
181 | 185 |
// Advanced tool bar |
182 |
Group group = this.topToolBar.installGroup(ChartsUIMessages.rendering, ChartsUIMessages.showHideRenderingParameters,
|
|
186 |
Group group = this.topToolBar.installGroup(ChartsUIMessages.rendering, ChartsUIMessages.showHideRenderingParameters, |
|
183 | 187 |
"platform:/plugin/org.txm.chartsengine.rcp/icons/show_rendering_parameters.png", //$NON-NLS-1$ |
184 | 188 |
"platform:/plugin/org.txm.chartsengine.rcp/icons/hide_rendering_parameters.png", //$NON-NLS-1$ |
185 | 189 |
false); |
186 | 190 |
this.advancedChartToolBar = new AdvancedChartEditorToolBar(this, group, this.getParametersGroupsComposite(), SWT.FLAT); |
187 |
|
|
191 |
|
|
188 | 192 |
this.swtChartsComponentsProvider = SWTChartsComponentsProvider.getComponentsProvider(this.getResult().getChartsEngine()); |
189 | 193 |
|
190 |
if(this.swtChartsComponentsProvider == null) {
|
|
194 |
if (this.swtChartsComponentsProvider == null) {
|
|
191 | 195 |
throw new Exception("No suitable component found to render the specified chart."); |
192 | 196 |
} |
193 | 197 |
|
... | ... | |
196 | 200 |
|
197 | 201 |
GridData gd = new GridData(GridData.FILL_BOTH); |
198 | 202 |
this.chartComposite.setLayoutData(gd); |
199 |
|
|
200 |
// subclasses manual creation
|
|
203 |
|
|
204 |
// subclasses manual creation |
|
201 | 205 |
this.__createPartControl(); |
202 | 206 |
|
203 | 207 |
|
204 |
// repack the toolbars after eventual item adding by subclasses
|
|
208 |
// repack the toolbars after eventual item adding by subclasses |
|
205 | 209 |
this.chartToolBar.pack(); |
206 | 210 |
this.advancedChartToolBar.pack(); |
207 | 211 |
|
208 | 212 |
} |
209 |
|
|
210 |
|
|
213 |
|
|
214 |
|
|
211 | 215 |
@Override |
212 | 216 |
public void setDirty(boolean dirty) { |
213 | 217 |
super.setDirty(dirty); |
... | ... | |
220 | 224 |
|
221 | 225 |
/** |
222 | 226 |
* Opens an editor where id is the specified result class name, computes the result then refreshes the editor components. |
227 |
* |
|
223 | 228 |
* @param result |
224 | 229 |
*/ |
225 | 230 |
public static ChartEditor openEditor(ChartResult result) { |
226 | 231 |
return openEditor(result, false); |
227 | 232 |
} |
228 |
|
|
233 |
|
|
229 | 234 |
/** |
230 | 235 |
* |
231 | 236 |
* @param result |
232 | 237 |
* @param alwaysRecreateEditor |
233 | 238 |
* @return |
234 | 239 |
*/ |
235 |
public static ChartEditor openEditor(ChartResult result, boolean alwaysRecreateEditor) {
|
|
240 |
public static ChartEditor openEditor(ChartResult result, boolean alwaysRecreateEditor) {
|
|
236 | 241 |
return openEditor(result, result.getClass().getName(), alwaysRecreateEditor); |
237 | 242 |
} |
238 | 243 |
|
... | ... | |
242 | 247 |
* @param editorPartId |
243 | 248 |
* @return |
244 | 249 |
*/ |
245 |
public static ChartEditor openEditor(ChartResult result, String editorPartId) {
|
|
250 |
public static ChartEditor openEditor(ChartResult result, String editorPartId) {
|
|
246 | 251 |
return openEditor(result, editorPartId, false); |
247 | 252 |
} |
248 | 253 |
|
249 | 254 |
/** |
250 | 255 |
* Opens an editor specified by its id, computes the specified result then refreshes the editor components. |
256 |
* |
|
251 | 257 |
* @param result |
252 | 258 |
* @param editorPartId |
253 | 259 |
* @param alwaysRecreateEditor force editor creation |
254 | 260 |
* @return |
255 | 261 |
*/ |
256 |
public static ChartEditor openEditor(ChartResult result, String editorPartId, boolean alwaysRecreateEditor) {
|
|
262 |
public static ChartEditor openEditor(ChartResult result, String editorPartId, boolean alwaysRecreateEditor) {
|
|
257 | 263 |
|
258 |
ChartEditorInput<ChartResult> editorInput = new ChartEditorInput<ChartResult>(result);
|
|
264 |
ChartEditorInput<ChartResult> editorInput = new ChartEditorInput<>(result); |
|
259 | 265 |
editorInput.setAlwaysRecreateEditor(alwaysRecreateEditor); |
260 | 266 |
|
261 | 267 |
return (ChartEditor) openEditor(editorInput, editorPartId); |
262 | 268 |
} |
263 |
|
|
264 |
|
|
269 |
|
|
270 |
|
|
265 | 271 |
@Override |
266 | 272 |
public void updateResultFromEditor() { |
267 | 273 |
// does nothing by default |
268 | 274 |
} |
269 | 275 |
|
270 | 276 |
/** |
271 |
* Synchronizes the editor with the chart result.
|
|
277 |
* Synchronizes the editor with the chart result. |
|
272 | 278 |
* Dedicated to dynamically change the editor components values from the stored result data. |
273 | 279 |
*/ |
274 | 280 |
public abstract void updateEditorFromChart(boolean update); |
... | ... | |
279 | 285 |
|
280 | 286 |
// check that the charts engine used for the result matches the SWT components provider otherwise find a suitable components provider |
281 | 287 |
// and recreate new ChartCoomposite and ChartComponent |
282 |
if(this.getResult().getChartsEngine() != this.swtChartsComponentsProvider.getChartsEngine()) {
|
|
288 |
if (this.getResult().getChartsEngine() != this.swtChartsComponentsProvider.getChartsEngine()) {
|
|
283 | 289 |
|
284 |
Log.finest("ChartEditor.updateEditorFromResult(): result charts engine = " + this.getResult().getChartsEngine().getName() + " / Editor charts engine = " + this.swtChartsComponentsProvider.getChartsEngine().getName() + "."); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ |
|
290 |
Log.finest("ChartEditor.updateEditorFromResult(): result charts engine = " + this.getResult().getChartsEngine().getName() + " / Editor charts engine = " + this.swtChartsComponentsProvider //$NON-NLS-1$ //$NON-NLS-2$ |
|
291 |
.getChartsEngine().getName() + "."); //$NON-NLS-1$ |
|
285 | 292 |
|
286 | 293 |
this.swtChartsComponentsProvider = SWTChartsComponentsProvider.getComponentsProvider(this.getResult().getChartsEngine()); |
287 | 294 |
this.swtChartsComponentsProvider.setChartsEngine(this.getResult().getChartsEngine()); |
288 | 295 |
|
289 |
Log.finest("ChartEditor.updateEditorFromResult(): charts engine used to create the chart does not match the editor one. The SWT components provider has been changed to match it: " + this.getSWTChartsComponentsProvider() + "."); //$NON-NLS-1$ //$NON-NLS-2$ |
|
296 |
Log.finest("ChartEditor.updateEditorFromResult(): charts engine used to create the chart does not match the editor one. The SWT components provider has been changed to match it: " + this //$NON-NLS-1$ |
|
297 |
.getSWTChartsComponentsProvider() + "."); //$NON-NLS-1$ |
|
290 | 298 |
|
291 | 299 |
// recreating the chart composite |
292 | 300 |
Composite parent = this.chartComposite.getParent(); |
... | ... | |
297 | 305 |
this.chartComposite.setLayoutData(gd); |
298 | 306 |
parent.layout(); |
299 | 307 |
} |
300 |
|
|
301 | 308 |
|
302 | 309 |
|
310 |
|
|
303 | 311 |
boolean needInit = (this.chartComposite.getChartComponent() == null) && (this.getResult().getChart() != null); |
304 | 312 |
|
305 | 313 |
// loading chart |
... | ... | |
308 | 316 |
|
309 | 317 |
|
310 | 318 |
// FIXME: this code should be moved in ChartComposite.loadChart()? |
311 |
if(needInit) {
|
|
319 |
if (needInit) {
|
|
312 | 320 |
this.onInit(); |
313 | 321 |
} |
314 | 322 |
|
315 | 323 |
// sublcass updating |
316 | 324 |
this.updateEditorFromChart(update); |
317 |
|
|
325 |
|
|
318 | 326 |
} |
319 |
|
|
320 | 327 |
|
328 |
|
|
321 | 329 |
/** |
322 |
* Method called if the editor needs initialization (if the chart component has not yet been created and if the chart is not null) and dedicated to be override by subclasses if needed to do some process after the initialization. |
|
330 |
* Method called if the editor needs initialization (if the chart component has not yet been created and if the chart is not null) and dedicated to be override by subclasses if needed to do some |
|
331 |
* process after the initialization. |
|
323 | 332 |
*/ |
324 |
protected void onInit() {
|
|
333 |
protected void onInit() {
|
|
325 | 334 |
// nothing to do |
326 | 335 |
} |
327 | 336 |
|
... | ... | |
329 | 338 |
* Activates the chart editor context. |
330 | 339 |
* The context is used, for example, to enable keyboard shortcut only for ChartEditor. |
331 | 340 |
*/ |
332 |
public void activateContext() {
|
|
333 |
IContextService contextService = (IContextService)getSite().getService(IContextService.class);
|
|
334 |
if(contextService != null) {
|
|
341 |
public void activateContext() {
|
|
342 |
IContextService contextService = getSite().getService(IContextService.class); |
|
343 |
if (contextService != null) {
|
|
335 | 344 |
this.contextActivationToken = contextService.activateContext(CONTEXT_ID_CHART_EDITOR); |
336 | 345 |
|
337 | 346 |
Log.finest(TXMCoreMessages.bind("ChartEditor.activateContext(): context activated (token = {0}).", this.contextActivationToken)); //$NON-NLS-1$ |
338 | 347 |
} |
339 |
else {
|
|
348 |
else {
|
|
340 | 349 |
Log.finest("ChartEditor.activateContext(): context activation falied."); //$NON-NLS-1$ |
341 | 350 |
} |
342 | 351 |
} |
343 | 352 |
|
344 |
|
|
353 |
|
|
345 | 354 |
/** |
346 | 355 |
* Deactivates the chart editor context. |
347 | 356 |
* The context is used, for example, to enable keyboard shortcut only for ChartEditor. |
348 | 357 |
*/ |
349 |
public void deactivateContext() {
|
|
350 |
IContextService contextService = (IContextService)getSite().getService(IContextService.class);
|
|
351 |
if(contextService != null) {
|
|
358 |
public void deactivateContext() {
|
|
359 |
IContextService contextService = getSite().getService(IContextService.class); |
|
360 |
if (contextService != null) {
|
|
352 | 361 |
contextService.deactivateContext(this.contextActivationToken); |
353 | 362 |
|
354 | 363 |
Log.finest(TXMCoreMessages.bind("ChartEditor.deactivateContext(): context deactivated (token = {0}).", this.contextActivationToken)); //$NON-NLS-1$ |
355 | 364 |
} |
356 |
else {
|
|
365 |
else {
|
|
357 | 366 |
Log.finest("ChartEditor.activateContext(): context deactivation failed."); //$NON-NLS-1$ |
358 | 367 |
} |
359 | 368 |
} |
360 | 369 |
|
361 |
|
|
370 |
|
|
362 | 371 |
@Override |
363 | 372 |
public void setFocus() { |
364 |
|
|
373 |
|
|
365 | 374 |
// FIXME: SJ: old code, temporary disabled |
366 | 375 |
// Debug |
367 | 376 |
Log.finest("ChartEditor.setFocus(): giving focus to chart composite..."); //$NON-NLS-1$ |
368 | 377 |
|
369 | 378 |
this.parent.setFocus(); |
370 |
//super.setFocus(); |
|
371 |
// |
|
372 |
//this.chartComposite.setFocus(); |
|
373 |
//
|
|
374 |
//
|
|
379 |
// super.setFocus();
|
|
380 |
//
|
|
381 |
// this.chartComposite.setFocus();
|
|
382 |
//
|
|
383 |
//
|
|
375 | 384 |
|
376 | 385 |
// SJ: new code |
377 |
//super.setFocus(); |
|
386 |
// super.setFocus();
|
|
378 | 387 |
|
379 | 388 |
} |
380 |
|
|
381 | 389 |
|
382 |
|
|
383 |
public void onPartActivated() { |
|
390 |
|
|
391 |
|
|
392 |
public void onPartActivated() { |
|
384 | 393 |
Log.finest("+++++ ChartEditor.onPartActivated(): " + this.getResult()); |
385 | 394 |
this.activateContext(); |
386 | 395 |
} |
387 |
|
|
388 |
public void onPartDeactivated() {
|
|
396 |
|
|
397 |
public void onPartDeactivated() {
|
|
389 | 398 |
Log.finest("----- ChartEditor.onPartDeactivated(): " + this.getResult()); |
390 | 399 |
this.deactivateContext(); |
391 | 400 |
} |
392 |
|
|
393 | 401 |
|
402 |
|
|
394 | 403 |
/** |
395 | 404 |
* Convenience method the get the casted linked editor input. |
405 |
* |
|
396 | 406 |
* @return the editorInput |
397 | 407 |
*/ |
408 |
@Override |
|
398 | 409 |
public ChartEditorInput<T> getEditorInput() { |
399 | 410 |
return (ChartEditorInput) super.getEditorInput(); |
400 | 411 |
} |
401 |
|
|
402 |
|
|
412 |
|
|
413 |
|
|
403 | 414 |
/** |
404 | 415 |
* Gets the chart drawing area composite. |
416 |
* |
|
405 | 417 |
* @return the composite |
406 | 418 |
*/ |
407 | 419 |
public ChartComposite getComposite() { |
408 | 420 |
return this.chartComposite; |
409 | 421 |
} |
410 |
|
|
411 |
|
|
422 |
|
|
423 |
|
|
412 | 424 |
/** |
413 | 425 |
* Resets the chart view (zoom, pan, rotation). |
414 | 426 |
*/ |
415 | 427 |
public void resetView() { |
416 | 428 |
this.chartComposite.resetView(); |
417 | 429 |
} |
418 |
|
|
430 |
|
|
419 | 431 |
/** |
420 |
* Clears the selected items in chart.
|
|
432 |
* Clears the selected items in chart. |
|
421 | 433 |
*/ |
422 |
public void clearChartItemsSelection() {
|
|
434 |
public void clearChartItemsSelection() {
|
|
423 | 435 |
this.chartComposite.clearChartItemsSelection(); |
424 | 436 |
} |
425 | 437 |
|
426 | 438 |
/** |
427 | 439 |
* Zooms the chart view at x and y coordinates. |
440 |
* |
|
428 | 441 |
* @param x |
429 | 442 |
* @param y |
430 | 443 |
* @param zoomIn |
431 | 444 |
*/ |
432 |
public void zoom(double x, double y, boolean zoomIn) {
|
|
445 |
public void zoom(double x, double y, boolean zoomIn) {
|
|
433 | 446 |
this.chartComposite.zoom(x, y, zoomIn); |
434 | 447 |
} |
435 |
|
|
448 |
|
|
436 | 449 |
/** |
437 | 450 |
* Pans the chart view. |
451 |
* |
|
438 | 452 |
* @param chartComponent |
439 | 453 |
* @param srcX |
440 | 454 |
* @param srcY |
... | ... | |
442 | 456 |
* @param dstY |
443 | 457 |
* @param panFactor |
444 | 458 |
*/ |
445 |
public void pan(double srcX, double srcY, double dstX, double dstY, double panFactor) {
|
|
459 |
public void pan(double srcX, double srcY, double dstX, double dstY, double panFactor) {
|
|
446 | 460 |
this.chartComposite.pan(srcX, srcY, dstX, dstY, panFactor); |
447 | 461 |
} |
448 | 462 |
|
... | ... | |
450 | 464 |
/** |
451 | 465 |
* Copy the current chart view to clipboard. |
452 | 466 |
*/ |
453 |
public void copyChartViewToClipboard() {
|
|
467 |
public void copyChartViewToClipboard() {
|
|
454 | 468 |
try { |
455 | 469 |
this.chartComposite.copyChartViewToClipboard(); |
456 | 470 |
} |
... | ... | |
458 | 472 |
Log.finest("ChartEditor.copyChartViewToClipboard(): nothing done, the chart has not yet been computed."); //$NON-NLS-1$ |
459 | 473 |
} |
460 | 474 |
} |
461 |
|
|
475 |
|
|
462 | 476 |
/** |
463 | 477 |
* Loads the chart from the chart object stored into the composite. |
478 |
* |
|
464 | 479 |
* @param resetView |
465 | 480 |
* @param clearChartItemsSelection |
466 | 481 |
*/ |
467 |
public void loadChart() {
|
|
482 |
public void loadChart() {
|
|
468 | 483 |
getSite().getShell().getDisplay().syncExec(new Runnable() { |
484 |
|
|
469 | 485 |
@Override |
470 | 486 |
public void run() { |
471 | 487 |
chartComposite.loadChart( |
472 |
getResult().needsToResetView(),
|
|
488 |
getResult().needsToResetView(), |
|
473 | 489 |
getResult().needsToClearItemsSelection(), |
474 | 490 |
getResult().needsToSquareOff()); |
475 | 491 |
} |
... | ... | |
482 | 498 |
* Implementations using a Composite to embed AWT/Swing components should manually call this.chartComposite.dispose() in the redefined method. |
483 | 499 |
*/ |
484 | 500 |
@Override |
485 |
public void dispose() {
|
|
501 |
public void dispose() {
|
|
486 | 502 |
if (this.chartComposite != null && !this.chartComposite.isDisposed()) { |
487 | 503 |
this.chartComposite.dispose(); |
488 | 504 |
} |
489 | 505 |
super.dispose(); |
490 | 506 |
} |
491 |
|
|
507 |
|
|
492 | 508 |
/** |
493 | 509 |
* Returns the tool bar of this editor. |
510 |
* |
|
494 | 511 |
* @return the toolBar |
495 | 512 |
*/ |
496 | 513 |
public ChartEditorToolBar getToolBar() { |
497 | 514 |
return chartToolBar; |
498 | 515 |
} |
499 |
|
|
516 |
|
|
500 | 517 |
/** |
501 | 518 |
* Returns the advanced tool bar of this editor. |
519 |
* |
|
502 | 520 |
* @return |
503 | 521 |
*/ |
504 |
public AdvancedChartEditorToolBar getAdvancedToolBar() {
|
|
522 |
public AdvancedChartEditorToolBar getAdvancedToolBar() {
|
|
505 | 523 |
return this.advancedChartToolBar; |
506 | 524 |
} |
507 | 525 |
|
508 |
|
|
526 |
|
|
509 | 527 |
/** |
510 | 528 |
* Gets the chart type. A same result can be drawn as multiple chart types (eg. pie, bar, etc.). |
529 |
* |
|
511 | 530 |
* @return |
512 | 531 |
*/ |
513 |
public String getChartType() {
|
|
532 |
public String getChartType() {
|
|
514 | 533 |
return this.getResult().getChartType(); |
515 | 534 |
} |
516 | 535 |
|
517 | 536 |
/** |
518 | 537 |
* Returns the chart associated with the editor. |
538 |
* |
|
519 | 539 |
* @return |
520 | 540 |
*/ |
521 |
public Object getChart() {
|
|
541 |
public Object getChart() {
|
|
522 | 542 |
return this.getResult().getChart(); |
523 | 543 |
} |
524 | 544 |
|
525 | 545 |
/** |
526 | 546 |
* Returns the chart components provider associated with the editor. |
547 |
* |
|
527 | 548 |
* @return |
528 | 549 |
*/ |
529 |
public SWTChartsComponentsProvider getSWTChartsComponentsProvider() {
|
|
550 |
public SWTChartsComponentsProvider getSWTChartsComponentsProvider() {
|
|
530 | 551 |
return this.swtChartsComponentsProvider; |
531 | 552 |
} |
532 |
|
|
553 |
|
|
533 | 554 |
/** |
534 | 555 |
* Gets the charts engine used by the result. |
556 |
* |
|
535 | 557 |
* @return |
536 | 558 |
*/ |
537 |
public ChartsEngine getChartsEngine() {
|
|
559 |
public ChartsEngine getChartsEngine() {
|
|
538 | 560 |
return this.getResult().getChartsEngine(); |
539 | 561 |
} |
540 |
|
|
562 |
|
|
541 | 563 |
/** |
542 | 564 |
* Exports the current view of the chart editor in the specified file. |
543 | 565 |
* |
... | ... | |
545 | 567 |
* @param fileFormat |
546 | 568 |
* @return |
547 | 569 |
*/ |
548 |
public File exportView(File file, String fileFormat) {
|
|
570 |
public File exportView(File file, String fileFormat) {
|
|
549 | 571 |
return this.chartComposite.exportView(file, fileFormat); |
550 | 572 |
} |
551 |
|
|
552 | 573 |
|
574 |
|
|
553 | 575 |
/** |
554 | 576 |
* Returns the export formats supported by the implementation of the <code>ChartComposite</code> for exporting the current the view. |
555 | 577 |
* |
556 | 578 |
* @return |
557 | 579 |
*/ |
558 |
public ArrayList<String> getEditorSupportedExportFileFormats() {
|
|
580 |
public ArrayList<String> getEditorSupportedExportFileFormats() {
|
|
559 | 581 |
return this.chartComposite.getEditorSupportedExportFileFormats(); |
560 | 582 |
} |
561 | 583 |
|
562 | 584 |
/** |
563 | 585 |
* Gets the parent multipages editor part if exists. |
586 |
* |
|
564 | 587 |
* @return the parentMultiPagesEditor |
565 | 588 |
*/ |
566 | 589 |
public MultiPageEditorPart getParentMultiPagesEditor() { |
567 | 590 |
return parentMultiPagesEditor; |
568 | 591 |
} |
569 |
|
|
592 |
|
|
570 | 593 |
/** |
571 | 594 |
* Sets the specified multipages editor part as parent of this one. |
595 |
* |
|
572 | 596 |
* @param parentMultiPagesEditor the parentMultiPagesEditor to set |
573 | 597 |
*/ |
574 | 598 |
public void setParentMultiPagesEditor(TXMMultiPageEditor parentMultiPagesEditor) { |
575 | 599 |
this.parentMultiPagesEditor = parentMultiPagesEditor; |
576 | 600 |
} |
577 |
|
|
601 |
|
|
578 | 602 |
/** |
579 | 603 |
* To check whether this editor was already opened when calling openEditor(). |
604 |
* |
|
580 | 605 |
* @return the wasAlreadyOpened |
581 | 606 |
*/ |
582 | 607 |
public boolean wasAlreadyOpened() { |
583 | 608 |
return wasAlreadyOpened; |
584 | 609 |
} |
585 |
|
|
610 |
|
|
586 | 611 |
/** |
587 | 612 |
* To check whether this editor was already opened when calling openEditor(). |
613 |
* |
|
588 | 614 |
* @param wasAlreadyOpened the wasAlreadyOpened to set |
589 | 615 |
*/ |
590 | 616 |
public void setWasAlreadyOpened(boolean wasAlreadyOpened) { |
591 | 617 |
this.wasAlreadyOpened = wasAlreadyOpened; |
592 | 618 |
} |
593 |
|
|
619 |
|
|
594 | 620 |
/** |
595 | 621 |
* Checks whatever the chart composite has the focus or not. |
622 |
* |
|
596 | 623 |
* @return <code>true</code> if the chart composite has the focus otherwise <code>false</code> |
597 | 624 |
*/ |
598 |
public boolean hasFocus() {
|
|
625 |
public boolean hasFocus() {
|
|
599 | 626 |
return this.chartComposite.hasFocus(); |
600 | 627 |
} |
601 |
|
|
628 |
|
|
602 | 629 |
/** |
603 | 630 |
* Gets the chart composite. |
631 |
* |
|
604 | 632 |
* @return the chartComposite |
605 | 633 |
*/ |
606 | 634 |
public ChartComposite getChartComposite() { |
... | ... | |
609 | 637 |
|
610 | 638 |
/** |
611 | 639 |
* Gets the chart toolbar. |
640 |
* |
|
612 | 641 |
* @return the chartToolBar |
613 | 642 |
*/ |
614 | 643 |
public ChartEditorToolBar getChartToolBar() { |
615 | 644 |
return chartToolBar; |
616 | 645 |
} |
617 |
|
|
646 |
|
|
618 | 647 |
@Override |
619 |
public T getResult() {
|
|
648 |
public T getResult() {
|
|
620 | 649 |
return (T) this.getEditorInput().getResult(); |
621 | 650 |
} |
622 | 651 |
|
623 |
|
|
624 |
} |
|
652 |
@Override |
|
653 |
public void close() { |
|
654 |
super.close(); |
|
655 |
|
|
656 |
// FIXME: SJ: temporary work around to close a multipage editor from one of this editor page |
|
657 |
if (this.parentMultiPagesEditor != null) { |
|
658 |
this.getSite().getShell().getDisplay().syncExec(new Runnable() { |
|
659 |
|
|
660 |
@Override |
|
661 |
public void run() { |
|
662 |
|
|
663 |
getSite().getPage().closeEditor(parentMultiPagesEditor, false); |
|
664 |
} |
|
665 |
}); |
|
666 |
} |
|
667 |
|
|
668 |
|
|
669 |
} |
|
670 |
|
|
671 |
} |
tmp/org.txm.annotation.kr.rcp/src/org/txm/annotation/kr/rcp/commands/SaveAnnotations.java (revision 2558) | ||
---|---|---|
1 | 1 |
package org.txm.annotation.kr.rcp.commands; |
2 | 2 |
|
3 |
import java.util.ArrayList;
|
|
3 |
import java.util.Set;
|
|
4 | 4 |
|
5 | 5 |
import org.eclipse.core.commands.AbstractHandler; |
6 | 6 |
import org.eclipse.core.commands.ExecutionEvent; |
... | ... | |
11 | 11 |
import org.eclipse.jface.dialogs.MessageDialog; |
12 | 12 |
import org.eclipse.jface.viewers.ISelection; |
13 | 13 |
import org.eclipse.jface.viewers.IStructuredSelection; |
14 |
import org.eclipse.osgi.util.NLS; |
|
14 | 15 |
import org.eclipse.swt.widgets.Display; |
15 |
import org.eclipse.swt.widgets.MessageBox; |
|
16 | 16 |
import org.eclipse.ui.handlers.HandlerUtil; |
17 | 17 |
import org.txm.annotation.kr.core.AnnotationManager; |
18 | 18 |
import org.txm.annotation.kr.core.KRAnnotationEngine; |
19 | 19 |
import org.txm.core.results.TXMResult; |
20 |
import org.txm.rcp.TXMWindows; |
|
21 |
import org.txm.rcp.commands.CloseEditorsUsing; |
|
22 |
import org.txm.rcp.commands.workspace.UpdateCorpus; |
|
23 | 20 |
import org.txm.rcp.editors.ITXMResultEditor; |
24 |
import org.txm.rcp.editors.TXMEditor; |
|
25 |
import org.txm.rcp.messages.TXMUIMessages; |
|
26 | 21 |
import org.txm.rcp.utils.JobHandler; |
27 | 22 |
import org.txm.rcp.utils.SWTEditorsUtils; |
28 | 23 |
import org.txm.rcp.views.corpora.CorporaView; |
... | ... | |
30 | 25 |
import org.txm.utils.logger.Log; |
31 | 26 |
|
32 | 27 |
public class SaveAnnotations extends AbstractHandler { |
33 |
|
|
28 |
|
|
34 | 29 |
public static final String ID = SaveAnnotations.class.getCanonicalName(); |
35 |
|
|
30 |
|
|
36 | 31 |
@Override |
37 | 32 |
public Object execute(ExecutionEvent event) throws ExecutionException { |
38 |
|
|
39 |
ISelection sel = (IStructuredSelection) HandlerUtil.getCurrentSelection(event);
|
|
33 |
|
|
34 |
ISelection sel = HandlerUtil.getCurrentSelection(event); |
|
40 | 35 |
if (!(sel instanceof IStructuredSelection)) return null; |
41 | 36 |
IStructuredSelection selection = (IStructuredSelection) sel; |
42 |
|
|
37 |
|
|
43 | 38 |
Object s = selection.getFirstElement(); |
44 | 39 |
if (!(s instanceof MainCorpus)) |
45 | 40 |
return null; |
... | ... | |
49 | 44 |
if (job == null) { |
50 | 45 |
return null; |
51 | 46 |
} |
52 |
} catch (Exception e) { |
|
47 |
} |
|
48 |
catch (Exception e) { |
|
53 | 49 |
// TODO Auto-generated catch block |
54 | 50 |
e.printStackTrace(); |
55 | 51 |
return null; |
56 | 52 |
} |
57 | 53 |
|
58 | 54 |
CorporaView.refresh(); |
59 |
|
|
55 |
|
|
60 | 56 |
return corpus; |
61 | 57 |
} |
62 |
|
|
58 |
|
|
63 | 59 |
public static JobHandler save(final MainCorpus corpus) throws Exception { |
64 | 60 |
final AnnotationManager am = KRAnnotationEngine.getAnnotationManager(corpus); |
65 | 61 |
if (am == null) return null; // nothing to do |
... | ... | |
67 | 63 |
if (!KRAnnotationEngine.needToSaveAnnotations(corpus)) { |
68 | 64 |
return null; |
69 | 65 |
} |
70 |
|
|
71 |
//System.out.println("DISPLAY="+Display.getDefault()); |
|
66 |
|
|
67 |
// System.out.println("DISPLAY="+Display.getDefault());
|
|
72 | 68 |
final Boolean[] doit = new Boolean[1]; |
73 | 69 |
doit[0] = true; |
74 | 70 |
Display.getDefault().syncExec(new Runnable() { |
71 |
|
|
75 | 72 |
@Override |
76 | 73 |
public void run() { |
77 |
if (!MessageDialog.openConfirm(Display.getDefault().getActiveShell(), "Before saving annotations...", "All editors using this corpus are going to be closed. Continue ?")) {
|
|
74 |
if (!MessageDialog.openConfirm(Display.getDefault().getActiveShell(), "Before saving annotations...", "All editors using this corpus will going to be closed. Continue?")) {
|
|
78 | 75 |
doit[0] = false; |
79 | 76 |
} |
80 | 77 |
} |
... | ... | |
83 | 80 |
return null; |
84 | 81 |
} |
85 | 82 |
|
86 |
JobHandler jobhandler = new JobHandler("Saving annotations of "+corpus) { //$NON-NLS-1$ |
|
83 |
JobHandler jobhandler = new JobHandler(NLS.bind("Saving annotations of {0}", corpus)) { |
|
84 |
|
|
87 | 85 |
@Override |
88 | 86 |
protected IStatus run(IProgressMonitor monitor) { |
89 | 87 |
this.runInit(monitor); |
90 | 88 |
try { |
91 | 89 |
|
92 |
ArrayList<ITXMResultEditor<?>> editors = SWTEditorsUtils.getEditors() ; |
|
93 |
monitor.beginTask("Closing editors", editors.size()); |
|
94 |
for (ITXMResultEditor<?> editor : editors) { |
|
95 |
TXMResult result = editor.getResult(); |
|
96 |
if (corpus.equals(result.getFirstParent(MainCorpus.class))) { |
|
97 |
editor.close(); |
|
98 |
} |
|
99 |
monitor.worked(1); |
|
100 |
} |
|
90 |
// close all opened editors of all children corpus |
|
91 |
SWTEditorsUtils.closeEditors(corpus, true); |
|
101 | 92 |
|
102 | 93 |
boolean rez = am.saveAnnotations(monitor); |
103 | 94 |
monitor.worked(30); |
104 |
|
|
95 |
|
|
105 | 96 |
if (rez) { |
106 | 97 |
Log.fine("Annotations are saved in XML-TXM files. Updating corpus indexes and editions"); |
107 |
} else { |
|
98 |
} |
|
99 |
else { |
|
108 | 100 |
Log.severe("** Error while saving annotations (see logs above)."); |
109 | 101 |
} |
110 |
|
|
111 |
} catch(Exception e) { |
|
112 |
System.out.println("Error while saving annotations: "+e); |
|
102 |
|
|
103 |
} |
|
104 |
catch (Exception e) { |
|
105 |
System.out.println("Error while saving annotations: " + e); |
|
113 | 106 |
Log.printStackTrace(e); |
114 | 107 |
return Status.CANCEL_STATUS; |
115 | 108 |
} |
116 | 109 |
return Status.OK_STATUS; |
117 | 110 |
} |
118 | 111 |
}; |
119 |
|
|
112 |
|
|
120 | 113 |
if (doit[0]) jobhandler.startJob(true); |
121 | 114 |
jobhandler.join(); |
122 | 115 |
return jobhandler; |
tmp/org.txm.rcp/src/main/java/org/txm/rcp/editors/imports/CorpusPage.java (revision 2558) | ||
---|---|---|
1037 | 1037 |
} |
1038 | 1038 |
} |
1039 | 1039 |
|
1040 |
DeleteObject.closeEditorOf(project, true);
|
|
1040 |
SWTEditorsUtils.closeEditors(project, true);
|
|
1041 | 1041 |
|
1042 | 1042 |
ExecuteImportScript.executeScript(project); |
1043 | 1043 |
|
tmp/org.txm.rcp/src/main/java/org/txm/rcp/editors/TXMEditor.java (revision 2558) | ||
---|---|---|
8 | 8 |
import java.util.Arrays; |
9 | 9 |
import java.util.HashSet; |
10 | 10 |
import java.util.List; |
11 |
import java.util.Set; |
|
12 |
import java.util.Timer; |
|
13 |
import java.util.TimerTask; |
|
11 | 14 |
|
12 | 15 |
import org.eclipse.core.runtime.IConfigurationElement; |
13 | 16 |
import org.eclipse.core.runtime.IProgressMonitor; |
... | ... | |
19 | 22 |
import org.eclipse.core.runtime.jobs.Job; |
20 | 23 |
import org.eclipse.jface.action.MenuManager; |
21 | 24 |
import org.eclipse.jface.dialogs.MessageDialog; |
25 |
import org.eclipse.jface.dialogs.ProgressMonitorDialog; |
|
26 |
import org.eclipse.jface.operation.IRunnableWithProgress; |
|
22 | 27 |
import org.eclipse.jface.viewers.ISelectionProvider; |
23 | 28 |
import org.eclipse.jface.viewers.IStructuredSelection; |
24 | 29 |
import org.eclipse.jface.viewers.StructuredSelection; |
... | ... | |
84 | 89 |
import org.txm.searchengine.cqp.ReferencePattern; |
85 | 90 |
import org.txm.searchengine.cqp.corpus.Property; |
86 | 91 |
import org.txm.searchengine.cqp.corpus.query.CQLQuery; |
87 |
import org.txm.utils.LogMonitor; |
|
88 | 92 |
import org.txm.utils.logger.Log; |
89 | 93 |
|
90 | 94 |
/** |
... | ... | |
387 | 391 |
public final void createPartControl(Composite parent) { |
388 | 392 |
|
389 | 393 |
try { |
394 |
|
|
395 |
// since some editor fields need some values of their parent ensure the parent is ready (e.g. Sub-corpus properties in Cooccurrence editor, etc.) |
|
396 |
// need to set deep, eg. for Partition that must synchronize its Parts (if false, the Parts are not computed) |
|
397 |
// it does not break the lazy since the children lazy is now determined by the hasBeenComputedOnce state |
|
398 |
// Runnable job = new Runnable() { |
|
399 |
// |
|
400 |
// @Override |
|
401 |
// public void run() { |
|
402 |
// // TODO Auto-generated method stub |
|
403 |
// TXMEditor.this.getResult().getParent().compute(true); |
|
404 |
// } |
|
405 |
// }; |
|
406 |
// |
|
407 |
// BusyIndicator.showWhile(getSite().getShell().getDisplay(), job); |
|
408 |
|
|
409 |
// FIXME: SJ: tests to show modal blocking cancelable progression dialog |
|
410 |
try { |
|
411 |
if (!this.getResult().getParent().hasBeenComputedOnce()) { |
|
412 |
IRunnableWithProgress job2 = new IRunnableWithProgress() { |
|
413 |
|
|
414 |
@Override |
|
415 |
public void run(IProgressMonitor monitor) { |
|
416 |
// TODO Auto-generated method stub |
|
417 |
TXMEditor.this.getResult().getParent().compute(monitor); |
|
418 |
} |
|
419 |
}; |
|
420 |
|
|
421 |
ProgressMonitorDialog dialog = new ProgressMonitorDialog(getSite().getShell()) { |
|
422 |
|
|
423 |
@Override |
|
424 |
protected void cancelPressed() { |
|
425 |
super.cancelPressed(); |
|
426 |
Thread.currentThread().stop(); |
|
427 |
} |
|
428 |
}; |
|
429 |
|
|
430 |
// Trying to display the dialog only after X seconds, not at start so it not appears for short tasks |
|
431 |
dialog.setOpenOnRun(false); |
|
432 |
Timer timer = new Timer(); |
|
433 |
timer.schedule(new TimerTask() { |
|
434 |
|
|
435 |
protected int elapsedTime = 0; |
|
436 |
|
|
437 |
@Override |
|
438 |
public void run() { |
|
439 |
elapsedTime += 10; |
|
440 |
if (elapsedTime > 1000) { |
|
441 |
Display.getDefault().asyncExec(new Runnable() { |
|
442 |
|
|
443 |
@Override |
|
444 |
public void run() { |
|
445 |
dialog.open(); |
|
446 |
} |
|
447 |
}); |
|
448 |
timer.purge(); |
|
449 |
timer.cancel(); |
|
450 |
} |
|
451 |
} |
|
452 |
}, 0, 10); |
|
453 |
// end of test |
|
454 |
|
|
455 |
|
|
456 |
|
|
457 |
dialog.run(true, true, job2); |
|
458 |
} |
|
459 |
} |
|
460 |
catch (ThreadDeath e) { |
|
461 |
// TODO Auto-generated catch block |
|
462 |
// e.printStackTrace(); |
|
463 |
CorporaView.refresh(); |
|
464 |
|
|
465 |
// TODO: SJ: may need to clean some things here |
|
466 |
|
|
467 |
this.close(); |
|
468 |
return; |
|
469 |
|
|
470 |
} |
|
471 |
|
|
472 |
// JobHandler job3 = new JobHandler(TXMCoreMessages.bind(TXMUIMessages.computing, this.getResult().getParent().getName()), true) { |
|
473 |
// |
|
474 |
// @Override |
|
475 |
// protected IStatus run(IProgressMonitor monitor) { |
|
476 |
// this.runInit(monitor); |
|
477 |
// // TODO Auto-generated method stub |
|
478 |
// TXMEditor.this.getResult().getParent().compute(true); |
|
479 |
// return Status.OK_STATUS; |
|
480 |
// } |
|
481 |
// }; |
|
482 |
// job3.setUser(true); |
|
483 |
// job3.startJob(); |
|
484 |
|
|
485 |
|
|
486 |
|
|
487 |
|
|
488 |
// job3.setProperty(IProgressConstants.PROPERTY_IN_DIALOG, true); |
|
489 |
// IProgressService ps = PlatformUI.getWorkbench().getProgressService(); |
|
490 |
// ps.showInDialog(getSite().getShell(), job3); |
|
491 |
// ps.runInUI(ps, (IRunnableWithProgress) job3, org.eclipse.core.resources.ResourcesPlugin.getWorkspace().getRoot()); |
|
492 |
// ps.busyCursorWhile((IRunnableWithProgress) job3); |
|
493 |
// job3.wait(); |
|
494 |
|
|
495 |
|
|
496 |
// this.getResult().getParent().compute(true); |
|
497 |
|
|
498 |
// TXMResult corpus = this.getResult().getFirstParent(CorpusBuild.class); |
|
499 |
// if (corpus != null) { |
|
500 |
// corpus.compute(false); |
|
501 |
// } |
|
502 |
|
|
503 |
|
|
504 |
|
|
390 | 505 |
this.parent = parent; |
391 | 506 |
|
392 | 507 |
// disable the rendering while creating the widgets |
... | ... | |
1106 | 1221 |
@Override |
1107 | 1222 |
public final void refresh(boolean update) throws Exception { |
1108 | 1223 |
|
1109 |
if (this.parent.isDisposed()) return; // nothing to refresh |
|
1224 |
// nothing to refresh |
|
1225 |
if (this.parent.isDisposed()) { |
|
1226 |
return; |
|
1227 |
} |
|
1110 | 1228 |
|
1111 | 1229 |
// skip refresh if the part creation has failed |
1112 |
if (!createPartControlDoneSucessfully) { |
|
1230 |
if (!this.createPartControlDoneSucessfully) {
|
|
1113 | 1231 |
return; |
1114 | 1232 |
} |
1115 | 1233 |
|
... | ... | |
1123 | 1241 |
// this.getContainer().setRedraw(false); |
1124 | 1242 |
|
1125 | 1243 |
String title = result.getName(); |
1126 |
if (title.length() > MAX_NAME_LENGTH) { // limit title length |
|
1244 |
// limit tab title length |
|
1245 |
if (title.length() > MAX_NAME_LENGTH) { |
|
1127 | 1246 |
title = title.substring(0, MAX_NAME_LENGTH - 1) + "..."; |
1128 | 1247 |
} |
1129 | 1248 |
this.setPartName(title); |
... | ... | |
1162 | 1281 |
// FIXME: SJ: this code breaks the dirty/chart dirty separation state, eg. if a non electric rendering parameter is changed then the chart is dirty but not the result, need to check this |
1163 | 1282 |
this.setDirty(this.getResult().isDirty()); |
1164 | 1283 |
|
1165 |
// FIXME: update all open editors of the children result but also of the result itself |
|
1284 |
// FIXME: update all opened editors of the children result but also of the result itself
|
|
1166 | 1285 |
// FIXME: debug |
1167 | 1286 |
Log.finest("TXMEditor.refresh(): " + this.getClass().getSimpleName() + ": synchronizing and refreshing result children opened editors."); //$NON-NLS-1$ //$NON-NLS-2$ |
1168 | 1287 |
|
1169 | 1288 |
List<TXMResult> results = this.getResult().getDeepChildren(); |
1170 | 1289 |
|
1171 | 1290 |
for (int i = 0; i < results.size(); i++) { |
1172 |
ArrayList<ITXMResultEditor<?>> editors = SWTEditorsUtils.getEditors(results.get(i));
|
|
1173 |
for (int j = 0; j < editors.size(); j++) { |
|
1174 |
ITXMResultEditor<?> txmEditor = editors.get(j);
|
|
1291 |
Set<ITXMResultEditor<TXMResult>> editors = SWTEditorsUtils.getEditors(results.get(i));
|
|
1292 |
|
|
1293 |
for (ITXMResultEditor<TXMResult> txmEditor : editors) {
|
|
1175 | 1294 |
if (txmEditor != this |
1176 | 1295 |
// && txmEditor.isDirty() |
1177 | 1296 |
) { |
1297 |
|
|
1178 | 1298 |
// txmEditor.synchronizeResultFromEditor(); |
1179 | 1299 |
|
1180 | 1300 |
// FIXME: SJ: need to prove/test this code |
1181 | 1301 |
// recreate all if the parent result is altered |
1182 | 1302 |
// txmEditor.refresh(!this.getResult().isAltered()); |
1303 |
|
|
1304 |
|
|
1183 | 1305 |
txmEditor.refresh(true); |
1184 | 1306 |
} |
1307 |
|
|
1185 | 1308 |
} |
1186 | 1309 |
} |
1187 | 1310 |
|
... | ... | |
1538 | 1661 |
*/ |
1539 | 1662 |
@Override |
1540 | 1663 |
public void close() { |
1541 |
close(false); |
|
1664 |
this.close(false);
|
|
1542 | 1665 |
} |
1543 | 1666 |
|
1544 | 1667 |
|
tmp/org.txm.rcp/src/main/java/org/txm/rcp/handlers/export/ImportResultParameters.java (revision 2558) | ||
---|---|---|
124 | 124 |
r.setDirty(); |
125 | 125 |
CorporaView.refreshObject(r); |
126 | 126 |
System.out.println(NLS.bind("Parameter imported from the {0} file.", outfile)); |
127 |
SWTEditorsUtils.refreshEditor(r); |
|
127 |
SWTEditorsUtils.refreshEditors(r);
|
|
128 | 128 |
} |
129 | 129 |
} catch (ThreadDeath td) { |
130 | 130 |
return Status.CANCEL_STATUS; |
tmp/org.txm.rcp/src/main/java/org/txm/rcp/handlers/results/DeleteObject.java (revision 2558) | ||
---|---|---|
45 | 45 |
import org.eclipse.swt.SWT; |
46 | 46 |
import org.eclipse.swt.widgets.Display; |
47 | 47 |
import org.eclipse.swt.widgets.MessageBox; |
48 |
import org.eclipse.ui.IWorkbenchPage; |
|
49 |
import org.eclipse.ui.IWorkbenchWindow; |
|
50 | 48 |
import org.eclipse.ui.handlers.HandlerUtil; |
51 |
import org.eclipse.ui.internal.Workbench; |
|
52 | 49 |
import org.txm.core.messages.TXMCoreMessages; |
53 | 50 |
import org.txm.core.results.TXMResult; |
54 |
import org.txm.objects.CorpusBuild; |
|
55 |
import org.txm.objects.Project; |
Formats disponibles : Unified diff