Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 152015
Collapse All | Expand All

(-)src/org/eclipse/hyades/logging/adapter/ui/internal/presentation/AdaptorActionBarContributor.java (-10 / +157 lines)
Lines 12-20 Link Here
12
package org.eclipse.hyades.logging.adapter.ui.internal.presentation;
12
package org.eclipse.hyades.logging.adapter.ui.internal.presentation;
13
13
14
14
15
import java.util.ArrayList;
15
import java.util.Collection;
16
import java.util.Collection;
16
import java.util.Iterator;
17
import java.util.Iterator;
17
import java.util.LinkedList;
18
import java.util.LinkedList;
19
import java.util.List;
18
20
19
import org.eclipse.emf.common.util.EList;
21
import org.eclipse.emf.common.util.EList;
20
import org.eclipse.emf.edit.command.CommandParameter;
22
import org.eclipse.emf.edit.command.CommandParameter;
Lines 43-50 Link Here
43
import org.eclipse.jface.viewers.SelectionChangedEvent;
45
import org.eclipse.jface.viewers.SelectionChangedEvent;
44
import org.eclipse.ui.IEditorPart;
46
import org.eclipse.ui.IEditorPart;
45
import org.eclipse.xsd.XSDComplexTypeDefinition;
47
import org.eclipse.xsd.XSDComplexTypeDefinition;
48
import org.eclipse.xsd.XSDCompositor;
46
import org.eclipse.xsd.XSDElementDeclaration;
49
import org.eclipse.xsd.XSDElementDeclaration;
50
import org.eclipse.xsd.XSDModelGroup;
51
import org.eclipse.xsd.XSDParticle;
47
import org.eclipse.xsd.XSDSimpleTypeDefinition;
52
import org.eclipse.xsd.XSDSimpleTypeDefinition;
53
import org.eclipse.xsd.XSDTerm;
48
import org.eclipse.xsd.XSDTypeDefinition;
54
import org.eclipse.xsd.XSDTypeDefinition;
49
55
50
56
Lines 182-206 Link Here
182
		if (createChildMenuManager != null) {
188
		if (createChildMenuManager != null) {
183
			depopulateManager(createChildMenuManager, createChildActions);
189
			depopulateManager(createChildMenuManager, createChildActions);
184
		}
190
		}
185
191
	
186
		// Query the new selection for appropriate new child/sibling descriptors
192
		// Query the new selection for appropriate new child/sibling descriptors
187
		//
193
		//
188
		Collection newChildDescriptors = null;
194
		Collection newChildDescriptors = null;
189
195
	
190
		ISelection selection = event.getSelection();
196
		ISelection selection = event.getSelection();
191
		if (selection instanceof IStructuredSelection && ((IStructuredSelection)selection).size() == 1) {
197
		if (selection instanceof IStructuredSelection && ((IStructuredSelection)selection).size() == 1) {
192
			Object object = ((IStructuredSelection)selection).getFirstElement();
198
			Object object = ((IStructuredSelection)selection).getFirstElement();
193
199
	
194
			EditingDomain domain =
200
			EditingDomain domain =
195
				((IEditingDomainProvider) activeEditorPart).getEditingDomain();
201
				((IEditingDomainProvider) activeEditorPart).getEditingDomain();
196
202
	
197
			newChildDescriptors = domain.getNewChildDescriptors(object, null);
203
			newChildDescriptors = domain.getNewChildDescriptors(object, null);
198
		}
204
		}
199
205
	
200
		// Generate actions for selection; populate and redraw the menus.
206
		// Generate actions for selection; populate and redraw the menus.
201
		//
207
		//
202
		createChildActions = generateCreateChildActions(newChildDescriptors, selection);
208
		createChildActions = generateCreateChildActions(newChildDescriptors, selection);
203
209
	
204
		if (createChildMenuManager != null) {
210
		if (createChildMenuManager != null) {
205
			populateManager(createChildMenuManager, createChildActions, null);
211
			populateManager(createChildMenuManager, createChildActions, null);
206
			createChildMenuManager.update(true);
212
			createChildMenuManager.update(true);
Lines 217-224 Link Here
217
	protected Collection generateCreateChildActions(Collection descriptors, ISelection selection) {
223
	protected Collection generateCreateChildActions(Collection descriptors, ISelection selection) {
218
		Collection actions = new LinkedList();
224
		Collection actions = new LinkedList();
219
		Object object = ((IStructuredSelection)selection).getFirstElement();
225
		Object object = ((IStructuredSelection)selection).getFirstElement();
220
		
226
				
221
		if (descriptors != null) {
227
		if (descriptors != null) {
228
			List execlusiveElementsList = null;
229
			/**
230
			 * Bugzilla 152015, It first gets the element/atrribute names for the execlusive elements/atrributes
231
			 */
232
			if(object instanceof RuleElementType)
233
			{
234
				execlusiveElementsList = getExclusiveElementList(object);
235
			}
222
			for (Iterator i = descriptors.iterator(); i.hasNext(); ) {
236
			for (Iterator i = descriptors.iterator(); i.hasNext(); ) {
223
				
237
				
224
				CommandParameter command = (CommandParameter)i.next();
238
				CommandParameter command = (CommandParameter)i.next();
Lines 244-259 Link Here
244
				}
258
				}
245
				else if(object instanceof RuleElementType)
259
				else if(object instanceof RuleElementType)
246
				{
260
				{
261
			
247
					Object value = command.getValue();
262
					Object value = command.getValue();
263
					
248
					if(value != null && value instanceof RuleAttributeType)
264
					if(value != null && value instanceof RuleAttributeType)
249
					{
265
					{
250
						action.setText(((RuleAttributeType)value).getName());
266
						action.setText(((RuleAttributeType)value).getName());
251
						enableAttributeAction(action, (RuleElementType)object);					
267
						/**
268
						 * Bugzilla 152015, then it checks if the action is in the exclusvie list
269
						 * and wheather the selected object already has another element which belongs to
270
						 * exclusive list. If yes, disable this action.
271
						 */
272
						if(execlusiveElementsList != null)
273
						{
274
							boolean disabledAction = disableExclusiveAction(action, (RuleElementType)object, execlusiveElementsList);
275
							if(!disabledAction)
276
								enableAttributeAction(action, (RuleElementType)object);		
277
						}
278
						else
279
						{
280
							enableAttributeAction(action, (RuleElementType)object);		
281
						}
282
									
252
					}
283
					}
253
					if(value != null && value instanceof RuleElementType)
284
					if(value != null && value instanceof RuleElementType)
254
					{
285
					{
255
						action.setText(((RuleElementType)value).getName());	
286
						action.setText(((RuleElementType)value).getName());	
256
						enableElementAction(action, (RuleElementType)object);											
287
						if(execlusiveElementsList != null)
288
						{
289
							boolean disabledAction = disableExclusiveAction(action, (RuleElementType)object, execlusiveElementsList);
290
							if(!disabledAction)
291
								enableElementAction(action, (RuleElementType)object);		
292
						}
293
						else
294
						{
295
							enableElementAction(action, (RuleElementType)object);		
296
						}
297
																
257
					}					
298
					}					
258
				}				
299
				}				
259
			}
300
			}
Lines 388-393 Link Here
388
			}
429
			}
389
			return;
430
			return;
390
		}
431
		}
432
		
391
		if (name.equals("hexValue"))
433
		if (name.equals("hexValue"))
392
		{
434
		{
393
			EList attributes = object.getRuleAttribute();
435
			EList attributes = object.getRuleAttribute();
Lines 420-426 Link Here
420
	protected void enableElementAction(Action action, RuleElementType object)
462
	protected void enableElementAction(Action action, RuleElementType object)
421
	{
463
	{
422
		String name = action.getText();
464
		String name = action.getText();
423
		
465
				
424
		Object cbeObject = AcadEditorPlugin.INSTANCE.getElementDefinitionForType(object);
466
		Object cbeObject = AcadEditorPlugin.INSTANCE.getElementDefinitionForType(object);
425
		if(cbeObject != null && cbeObject instanceof XSDElementDeclaration)
467
		if(cbeObject != null && cbeObject instanceof XSDElementDeclaration)
426
		{			
468
		{			
Lines 498-503 Link Here
498
	}
540
	}
499
	
541
	
500
	
542
	
543
	protected boolean disableExclusiveAction(Action action, RuleElementType object, List execlusiveElementsList)
544
	{
545
		for(int i=0; i<execlusiveElementsList.size();i++)
546
		{
547
			ArrayList nameList = (ArrayList)execlusiveElementsList.get(i);
548
			for(int j=0; j<nameList.size();j++)
549
			{
550
				String actionName = action.getText();
551
				if(nameList.contains(action.getText()))
552
				{
553
					
554
					EList ruleElements = object.getRuleElement();
555
					EList atrributeElements = object.getRuleAttribute();
556
					for(int idx=0; idx<ruleElements.size(); idx++)
557
					{
558
						String elementName = null;
559
						elementName = ((RuleElementType)ruleElements.get(idx)).getName();
560
						
561
						if(!actionName.equals(elementName)&&nameList.contains(elementName))
562
						{
563
							action.setEnabled(false);
564
						
565
							return true;
566
						}
567
						
568
					}
569
					for(int attr_idx=0; attr_idx<atrributeElements.size(); attr_idx++)
570
					{
571
						String attributeElement = null;
572
						attributeElement = ((RuleAttributeType)atrributeElements.get(attr_idx)).getName();
573
						
574
						if(!actionName.equals(attributeElement)&&nameList.contains(attributeElement))
575
						{
576
							action.setEnabled(false);
577
							return true;
578
						}
579
						
580
					}
581
				}
582
			}
583
		}
584
		return false;
585
	}
586
	
501
	protected void enableComplexType(Action action, XSDComplexTypeDefinition tdef, RuleElementType object)
587
	protected void enableComplexType(Action action, XSDComplexTypeDefinition tdef, RuleElementType object)
502
	{
588
	{
503
		String name = action.getText();
589
		String name = action.getText();
Lines 518-521 Link Here
518
		
604
		
519
		action.setEnabled(true);
605
		action.setEnabled(true);
520
	}
606
	}
607
	
608
	private List getExclusiveElementList(Object value)
609
	{
610
611
612
		if(value instanceof RuleElementType)
613
		{
614
	
615
			List list = new ArrayList();
616
			Object type = AcadEditorPlugin.INSTANCE.getElementDefinitionForType((RuleElementType)value);
617
			if(type != null)
618
			{
619
				if(type instanceof XSDElementDeclaration)
620
				{
621
					EList contents=((XSDElementDeclaration)type).getType().eContents();
622
					for(int l=0;l<contents.size();l++)
623
					{
624
						Object content = contents.get(l);
625
						if( content instanceof XSDParticle )
626
						{
627
							EList particles = ((XSDParticle)content).eContents();
628
							for(int k=0; k<particles.size();k++)
629
							{
630
								Object particleConent =particles.get(k);
631
								if(particleConent instanceof XSDModelGroup)
632
								{
633
									XSDModelGroup xsdModelGroup = (XSDModelGroup)particleConent;
634
									if( xsdModelGroup.getCompositor()==XSDCompositor.CHOICE_LITERAL)
635
									{
636
              							//This is a choice group. Get elements included in this group.
637
										ArrayList nameList = new ArrayList();
638
										for (Iterator i = xsdModelGroup.getParticles().iterator(); i.hasNext(); )
639
										{
640
											XSDTerm tmpTerm = ((XSDParticle)i.next()).getTerm();
641
											if( tmpTerm instanceof XSDElementDeclaration)
642
											{
643
												XSDElementDeclaration tmpElement = (XSDElementDeclaration)tmpTerm; 
644
												nameList.add(tmpElement.getName());
645
											}
646
647
648
										}
649
										list.add(nameList);
650
									}
651
								}
652
							}
653
						}
654
655
					}
656
				}
657
				if(list.size() == 0)
658
				{
659
					return null;
660
				}
661
				return list;
662
			}
663
		}
664
		return null;
665
	}
666
	
667
	
521
}
668
}

Return to bug 152015