1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
|
public class SmtOngletsProprietes extends ViewPart {
public static String ID= "smtBaseExplorer.SmtOngletsProprietes";
private static TabFolder tabfolder;
private Composite window;
private ISelectionListener listener = new ISelectionListener() {
@Override
public void selectionChanged(IWorkbenchPart part, ISelection selection) {
ITreeSelection sel = (ITreeSelection) selection;
try {
if(sel.getFirstElement() instanceof BaseSem_Base) {
createTabForBase();
}
else if(sel.getFirstElement() instanceof BaseSem_Application) {
createTabForApplication((BaseSem_Application) sel.getFirstElement());
}
else if(sel.getFirstElement() instanceof BaseSem_Type) {
//suppression des anciens onglets
removeAllTabItems();
createTabForType((BaseSem_Type) sel.getFirstElement());
}
}
catch (Exception e) {
e.printStackTrace();
}
}
};
@Override
public void createPartControl(Composite parent) {
window = parent;
tabfolder = new TabFolder(window , SWT.NONE);
getSite().getWorkbenchWindow().getSelectionService().addSelectionListener(listener );
}
/***
* création des onglets quand la sélection est une BaseSem_Type
* @param selection
* @throws SmtNodeNotFoundException
* @throws FileNotFoundException
*/
protected void createTabForType(BaseSem_Type selection) throws SmtNodeNotFoundException, FileNotFoundException {
//créationd des onglets
TabItem ongletType = new TabItem(tabfolder, SWT.NONE);
ongletType.setText(selection.getName());
//création du contenu du premier onglet
SmtPageProprietes contenu = new SmtPageProprietes(tabfolder,SWT.NONE,true);
contenu.setListViewerContenProviderWithComponent(selection.component_get());
ongletType.setControl(contenu);
if(selection.getName().equals(Constant.TYPE_COBOL)) {
//créationd des onglets
TabItem ongletCopy = new TabItem(tabfolder, SWT.NONE);
ongletCopy.setText(Constant.TYPE_COBOL_ONGLET2_TITLE);
SmtPageProprietes p = new SmtPageProprietes(tabfolder,SWT.NONE,true);
ongletCopy.setControl(p);
}
}
/***
* création des onglets quand la sélection est une BaseSem_Application
* @param selection
* @throws SmtNodeNotFoundException
* @throws FileNotFoundException
*/
protected void createTabForApplication(BaseSem_Application selection) throws SmtNodeNotFoundException, FileNotFoundException {
//suppression des anciens onglets
removeAllTabItems();
for (BaseSem_Type el : selection.type_get()) {
createTabForType(el);
}
//créationd des onglets
TabItem ongletmessages = new TabItem(tabfolder, SWT.NONE);
ongletmessages.setText(Constant.APPLICATION_LAST_ONGLET_TITLE);
Composite pageOngletStatistiques = new Composite(tabfolder,SWT.NONE);
Text text = new Text(pageOngletStatistiques, SWT.BORDER | SWT.MULTI | SWT.READ_ONLY);
text.setSize(tabfolder.getBounds().width,
tabfolder.getBounds().height);
text.setBackground( new Color(pageOngletStatistiques.getDisplay(),255,255,255));
//contenu du text (Statistiques)
StringBuffer statsContenu = new StringBuffer();
statsContenu.append(selection.getInformations());
text.setText(statsContenu.toString());
ongletmessages.setControl(pageOngletStatistiques);
}
/***
* création des onglets quand la sélection est une BaseSem_Base
* @throws SmtNodeNotFoundException
* @throws FileNotFoundException
* @throws Exception
*/
protected void createTabForBase() throws SmtNodeNotFoundException, FileNotFoundException, Exception {
//suppression des anciens onglets
removeAllTabItems();
//créationd des onglets
TabItem ongletlisteApplication = new TabItem(tabfolder, SWT.NONE);
ongletlisteApplication.setText(Constant.TITLE_TAB1_BASE);
TabItem ongletStats = new TabItem(tabfolder, SWT.NONE);
ongletStats.setText(Constant.TITLE_TAB2_BASE);
//création du contenu du premier onglet
SmtPageProprietes p = new SmtPageProprietes(tabfolder,SWT.NONE,false);
BaseSem_Base firstNode = SmtBase.getInstance().getFirstNode();
p.setListViewerContenProviderWithApplications(firstNode.application_get());
ongletlisteApplication.setControl(p);
//création du contenu du second onglet
Composite pageOngletStatistiques = new Composite(tabfolder,SWT.NONE);
Text text = new Text(pageOngletStatistiques, SWT.BORDER | SWT.MULTI | SWT.READ_ONLY);
text.setSize(tabfolder.getBounds().width,
tabfolder.getBounds().height);
text.setBackground( new Color(pageOngletStatistiques.getDisplay(),255,255,255));
text.setText(firstNode.getInformations());
ongletStats.setControl(pageOngletStatistiques);
}
} |
Partager