From 61d511443a8815bc1159927893da289a8b2fd61d Mon Sep 17 00:00:00 2001 From: jinxuesong Date: Wed, 12 May 2021 09:27:53 +0800 Subject: [PATCH 1/2] Update --- .../hit/education/action/AddCourseAction.java | 5 +- .../education/action/AddPropertyAction.java | 5 +- .../labelprovider/CourseLabelProvider.java | 15 ++- .../hit/education/model/CourseRootNode.java | 63 +++++++--- .../education/service/IProcessService.java | 29 ++--- .../education/service/IPropertyService.java | 28 ++--- .../education/service/ProcessServiceImpl.java | 37 +++--- .../service/PropertyServiceImpl.java | 39 +++--- .../hit/education/view/CourseExploreView.java | 119 +++++++++++++----- 9 files changed, 207 insertions(+), 133 deletions(-) diff --git a/src/cn/edu/hit/education/action/AddCourseAction.java b/src/cn/edu/hit/education/action/AddCourseAction.java index 4e8b8a9..1bc9dcc 100644 --- a/src/cn/edu/hit/education/action/AddCourseAction.java +++ b/src/cn/edu/hit/education/action/AddCourseAction.java @@ -16,12 +16,14 @@ import educationschedule.Application; public class AddCourseAction extends Action { private CourseExploreView viewPart; ICourseService courseService = (ICourseService)Application.applicationContext.getBean("courseServiceImpl"); + private int propertyId; - public AddCourseAction(CourseExploreView viewPart){ + public AddCourseAction(CourseExploreView viewPart,int propertyId){ this.setImageDescriptor(AbstractUIPlugin.imageDescriptorFromPlugin(Activator.PLUGIN_ID, "icons/toolbar/course_code_16px.png")); this.setToolTipText("增加课程"); this.setText("增加课程"); this.viewPart = viewPart; + this.propertyId = propertyId; } @Override @@ -29,6 +31,7 @@ public class AddCourseAction extends Action { Shell parentShell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); CourseDialog courseDialog = new CourseDialog(parentShell); Course course = new Course(); + course.setPropertyId(propertyId); courseDialog.setCourse(course); if(IDialogConstants.OK_ID == courseDialog.open()){ int count = courseService.insert(course); diff --git a/src/cn/edu/hit/education/action/AddPropertyAction.java b/src/cn/edu/hit/education/action/AddPropertyAction.java index a6d0dbc..f229827 100644 --- a/src/cn/edu/hit/education/action/AddPropertyAction.java +++ b/src/cn/edu/hit/education/action/AddPropertyAction.java @@ -17,11 +17,13 @@ import educationschedule.Application; public class AddPropertyAction extends Action { private CourseExploreView viewPart; IPropertyService propertyService = (IPropertyService)Application.applicationContext.getBean("propertyServiceImpl"); + private int processId; - public AddPropertyAction(CourseExploreView viewPart){ + public AddPropertyAction(CourseExploreView viewPart,int processId){ this.setImageDescriptor(AbstractUIPlugin.imageDescriptorFromPlugin(Activator.PLUGIN_ID, "icons/toolbar/course_code_16px.png")); this.setToolTipText("增加课程性质"); this.setText("增加课程性质"); + this.processId = processId; this.viewPart = viewPart; } @@ -30,6 +32,7 @@ public class AddPropertyAction extends Action { Shell parentShell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); PropertyDialog propertyDialog = new PropertyDialog(parentShell); Property property = new Property(); + property.setProcessId(processId); propertyDialog.setProperty(property); if(IDialogConstants.OK_ID == propertyDialog.open()){ int count = propertyService.insert(property); diff --git a/src/cn/edu/hit/education/labelprovider/CourseLabelProvider.java b/src/cn/edu/hit/education/labelprovider/CourseLabelProvider.java index 29ebf0d..8103ebc 100644 --- a/src/cn/edu/hit/education/labelprovider/CourseLabelProvider.java +++ b/src/cn/edu/hit/education/labelprovider/CourseLabelProvider.java @@ -10,11 +10,11 @@ import org.eclipse.swt.graphics.Image; import org.eclipse.ui.plugin.AbstractUIPlugin; import cn.edu.hit.education.model.CourseNode; +import cn.edu.hit.education.model.CourseRootNode; import cn.edu.hit.education.model.ProcessNode; import cn.edu.hit.education.model.PropertyNode; -import cn.edu.hit.education.model.CourseRootNode; +import cn.edu.hit.education.model.ResourceNode; import educationschedule.Activator; -import educationschedule.Application; public class CourseLabelProvider implements ILabelProvider { @@ -25,7 +25,10 @@ public class CourseLabelProvider implements ILabelProvider { public Image getImage(Object element) { ImageDescriptor descriptor = null; // obtain the cached image corresponding to the descriptor - if (element instanceof ProcessNode) { + if (element instanceof ResourceNode) { + descriptor = AbstractUIPlugin.imageDescriptorFromPlugin( + Activator.PLUGIN_ID, "icons/process.png"); + } else if (element instanceof ProcessNode) { descriptor = AbstractUIPlugin.imageDescriptorFromPlugin( Activator.PLUGIN_ID, "icons/process.png"); } else if (element instanceof PropertyNode) { @@ -47,9 +50,11 @@ public class CourseLabelProvider implements ILabelProvider { @Override public String getText(Object element) { String text = ""; - if (element instanceof CourseRootNode) + if (element instanceof CourseRootNode){ text = "root"; - else if (element instanceof ProcessNode) { + }else if (element instanceof ResourceNode) { + text = ((ResourceNode) element).getName(); + }else if (element instanceof ProcessNode) { text = ((ProcessNode) element).getName(); } else if (element instanceof PropertyNode) { text = ((PropertyNode) element).getName(); diff --git a/src/cn/edu/hit/education/model/CourseRootNode.java b/src/cn/edu/hit/education/model/CourseRootNode.java index 3516a79..ab5462d 100644 --- a/src/cn/edu/hit/education/model/CourseRootNode.java +++ b/src/cn/edu/hit/education/model/CourseRootNode.java @@ -47,9 +47,10 @@ public class CourseRootNode extends Node { public static synchronized CourseRootNode getRootNode() { if (root == null) { root = new CourseRootNode(); - initSpecialties(); + //initSpecialties(); root.setParent(null); - root.initRootNode(getSpecialtiesIds()); + //root.initRootNode(getSpecialtiesIds()); + root.initRootNode(1); } return root; @@ -64,14 +65,12 @@ public class CourseRootNode extends Node { } else if (subject.hasRole("president")) { User user = (User) subject.getPrincipal(); // 根据院长的用户Id查询到关联的专业Id - List ids = userSpeciatyService.querySpeciatyIdsByUser(user - .getId()); + List ids = userSpeciatyService.querySpeciatyIdsByUser(user.getId()); specialties = specialtyService.queryRelativeSpecialty(ids); } else if (subject.hasRole("director")) { User user = (User) subject.getPrincipal(); // 根据普通用户的用户Id查询到关联的专业Id - List ids = userSpeciatyService.querySpeciatyIdsByUser(user - .getId()); + List ids = userSpeciatyService.querySpeciatyIdsByUser(user.getId()); specialties = specialtyService.queryRelativeSpecialty(ids); } @@ -87,24 +86,22 @@ public class CourseRootNode extends Node { } private void initRootNode(List specialtiesIds) { - List universities = universityService.queryAllUniversity(); + ResourceNode resourceNode = new ResourceNode(0,"教育资源"); + root.addChild(resourceNode); + List processes = processService.queryAllProcess(); if (processes != null && processes.size() > 0) { for (Process process : processes) { - ProcessNode processNode = new ProcessNode(process.getId(), - process.getName()); - root.addChild(processNode); + ProcessNode processNode = new ProcessNode(process.getId(),process.getName()); + resourceNode.addChild(processNode); - List properties = propertyService - .queryPropertiesByProcessId(process.getId()); + List properties = propertyService.queryPropertiesByProcessId(process.getId()); if (properties != null && properties.size() > 0) { for (Property property : properties) { - PropertyNode propertyNode = new PropertyNode( - property.getId(), property.getName()); + PropertyNode propertyNode = new PropertyNode(property.getId(), property.getName()); processNode.addChild(propertyNode); - List courses = courseService - .queryCoursesByPropertyId(property.getId()); + List courses = courseService.queryCoursesByPropertyId(property.getId()); courses = courses.stream().filter(item->{ return specialtiesIds.contains(item.getSpecialtyId()); @@ -112,8 +109,7 @@ public class CourseRootNode extends Node { if (courses != null && courses.size() > 0) { for (Course course : courses) { - CourseNode courseNode = new CourseNode( - course.getId(), course.getName()); + CourseNode courseNode = new CourseNode(course.getId(), course.getName()); propertyNode.addChild(courseNode); } } @@ -122,7 +118,36 @@ public class CourseRootNode extends Node { } } + } + + private void initRootNode(int specialtieId) { + ResourceNode resourceNode = new ResourceNode(0,"教育资源"); + root.addChild(resourceNode); + + List processes = processService.queryAllProcess(); + if (processes != null && processes.size() > 0) { + for (Process process : processes) { + ProcessNode processNode = new ProcessNode(process.getId(),process.getName()); + resourceNode.addChild(processNode); + + List properties = propertyService.queryPropertiesByProcessId(process.getId()); + if (properties != null && properties.size() > 0) { + for (Property property : properties) { + PropertyNode propertyNode = new PropertyNode(property.getId(), property.getName()); + processNode.addChild(propertyNode); - System.out.println(universities); + List courses = courseService.queryCoursesBySpecialtyPropertyId(specialtieId, property.getId()); + + if (courses != null && courses.size() > 0) { + for (Course course : courses) { + CourseNode courseNode = new CourseNode(course.getId(), course.getName()); + propertyNode.addChild(courseNode); + } + } + } + } + + } + } } } diff --git a/src/cn/edu/hit/education/service/IProcessService.java b/src/cn/edu/hit/education/service/IProcessService.java index c3883ae..6b5a11e 100644 --- a/src/cn/edu/hit/education/service/IProcessService.java +++ b/src/cn/edu/hit/education/service/IProcessService.java @@ -1,29 +1,24 @@ /** -*

title IProcessService.java

-*

package cn.edu.hit.education.service

-*

description TODO

-*

copyright ҵѧ(C) 2019

-*

company ҵѧAS&MT

-*

author ѩ jinxuesong@163.com

-*

date 2021421 4:22:02

-*

version v1.0

+*

title �� IProcessService.java

+*

package �� cn.edu.hit.education.service

+*

description ��TODO

+*

copyright �� ��������ҵ��ѧ(C) 2019

+*

company �� ��������ҵ��ѧAS&MT

+*

author �� ��ѩ�� jinxuesong@163.com

+*

date �� 2021��4��21�� ����4:22:02

+*

version �� v1.0

* * Modification History: * Date Author Version Discription * ----------------------------------------------------------------------------------- -* 2021421 ѩ 1.0 1.0 -* Why & What is modified: <޸ԭ> +* 2021��4��21�� ��ѩ�� 1.0 1.0 +* Why & What is modified: <�޸�ԭ������> */ package cn.edu.hit.education.service; import java.util.List; import cn.edu.hit.education.pojo.Process; -/** - *

classname IProcessService

- *

description TODO

- *

author ѩ jinxuesong@163.com

- *

date 2021421 4:22:02

- */ + public interface IProcessService { int insert(Process process); @@ -32,6 +27,8 @@ public interface IProcessService { int update(Process process); + Process queryProcessByPrimaryKey(int id); + List queryAllProcess(); List queryProcessesByProcessName(String name); diff --git a/src/cn/edu/hit/education/service/IPropertyService.java b/src/cn/edu/hit/education/service/IPropertyService.java index 9fc0696..6a0b519 100644 --- a/src/cn/edu/hit/education/service/IPropertyService.java +++ b/src/cn/edu/hit/education/service/IPropertyService.java @@ -1,18 +1,18 @@ /** -*

title IPropertyService.java

-*

package cn.edu.hit.education.service

-*

description TODO

-*

copyright ҵѧ(C) 2019

-*

company ҵѧAS&MT

-*

author ѩ jinxuesong@163.com

-*

date 2021421 4:22:14

-*

version v1.0

+*

title �� IPropertyService.java

+*

package �� cn.edu.hit.education.service

+*

description ��TODO

+*

copyright �� ��������ҵ��ѧ(C) 2019

+*

company �� ��������ҵ��ѧAS&MT

+*

author �� ��ѩ�� jinxuesong@163.com

+*

date �� 2021��4��21�� ����4:22:14

+*

version �� v1.0

* * Modification History: * Date Author Version Discription * ----------------------------------------------------------------------------------- -* 2021421 ѩ 1.0 1.0 -* Why & What is modified: <޸ԭ> +* 2021��4��21�� ��ѩ�� 1.0 1.0 +* Why & What is modified: <�޸�ԭ������> */ package cn.edu.hit.education.service; @@ -20,12 +20,6 @@ import java.util.List; import cn.edu.hit.education.pojo.Property; -/** - *

classname IPropertyService

- *

description TODO

- *

author ѩ jinxuesong@163.com

- *

date 2021421 4:22:14

- */ public interface IPropertyService { int insert(Property property); @@ -34,6 +28,8 @@ public interface IPropertyService { int update(Property property); + Property queryPropertyByPrimaryKey(int id); + Property queryPropertyById(int id); List queryAllProperty(); diff --git a/src/cn/edu/hit/education/service/ProcessServiceImpl.java b/src/cn/edu/hit/education/service/ProcessServiceImpl.java index 17868d6..a046008 100644 --- a/src/cn/edu/hit/education/service/ProcessServiceImpl.java +++ b/src/cn/edu/hit/education/service/ProcessServiceImpl.java @@ -1,18 +1,18 @@ /** -*

title ProcessServiceImpl.java

-*

package cn.edu.hit.education.service

-*

description TODO

-*

copyright ҵѧ(C) 2019

-*

company ҵѧAS&MT

-*

author ѩ jinxuesong@163.com

-*

date 2021421 4:38:37

-*

version v1.0

+*

title �� ProcessServiceImpl.java

+*

package �� cn.edu.hit.education.service

+*

description ��TODO

+*

copyright �� ��������ҵ��ѧ(C) 2019

+*

company �� ��������ҵ��ѧAS&MT

+*

author �� ��ѩ�� jinxuesong@163.com

+*

date �� 2021��4��21�� ����4:38:37

+*

version �� v1.0

* * Modification History: * Date Author Version Discription * ----------------------------------------------------------------------------------- -* 2021421 ѩ 1.0 1.0 -* Why & What is modified: <޸ԭ> +* 2021��4��21�� ��ѩ�� 1.0 1.0 +* Why & What is modified: <�޸�ԭ������> */ package cn.edu.hit.education.service; @@ -25,12 +25,6 @@ import cn.edu.hit.education.dao.ProcessMapper; import cn.edu.hit.education.pojo.Process; import cn.edu.hit.education.pojo.ProcessExample; -/** - *

classname ProcessServiceImpl

- *

description TODO

- *

author ѩ jinxuesong@163.com

- *

date 2021421 4:38:37

- */ @Service public class ProcessServiceImpl implements IProcessService { @@ -39,25 +33,21 @@ public class ProcessServiceImpl implements IProcessService { @Override public int insert(Process process) { - // TODO Զɵķ return processMapper.insert(process); } @Override public int deleteByPrimaryKey(int id) { - // TODO Զɵķ return processMapper.deleteByPrimaryKey(id); } @Override public int update(Process process) { - // TODO Զɵķ return processMapper.updateByPrimaryKey(process); } @Override public List queryAllProcess() { - // TODO Զɵķ ProcessExample example = new ProcessExample(); ProcessExample.Criteria criteria = example.createCriteria(); criteria.andIdGreaterThan(0); @@ -67,7 +57,6 @@ public class ProcessServiceImpl implements IProcessService { @Override public List queryProcessesByProcessName(String name) { - // TODO Զɵķ ProcessExample example = new ProcessExample(); ProcessExample.Criteria criteria = example.createCriteria(); criteria.andNameEqualTo(name.trim()); @@ -75,4 +64,10 @@ public class ProcessServiceImpl implements IProcessService { return processMapper.selectByExample(example); } + @Override + public Process queryProcessByPrimaryKey(int id) { + // TODO 自动生成的方法存根 + return processMapper.selectByPrimaryKey(id); + } + } diff --git a/src/cn/edu/hit/education/service/PropertyServiceImpl.java b/src/cn/edu/hit/education/service/PropertyServiceImpl.java index 1b5ae0d..4c76e1b 100644 --- a/src/cn/edu/hit/education/service/PropertyServiceImpl.java +++ b/src/cn/edu/hit/education/service/PropertyServiceImpl.java @@ -1,18 +1,18 @@ /** -*

title PropertyServiceImpl.java

-*

package cn.edu.hit.education.service

-*

description TODO

-*

copyright ҵѧ(C) 2019

-*

company ҵѧAS&MT

-*

author ѩ jinxuesong@163.com

-*

date 2021421 4:39:13

-*

version v1.0

+*

title �� PropertyServiceImpl.java

+*

package �� cn.edu.hit.education.service

+*

description ��TODO

+*

copyright �� ��������ҵ��ѧ(C) 2019

+*

company �� ��������ҵ��ѧAS&MT

+*

author �� ��ѩ�� jinxuesong@163.com

+*

date �� 2021��4��21�� ����4:39:13

+*

version �� v1.0

* * Modification History: * Date Author Version Discription * ----------------------------------------------------------------------------------- -* 2021421 ѩ 1.0 1.0 -* Why & What is modified: <޸ԭ> +* 2021��4��21�� ��ѩ�� 1.0 1.0 +* Why & What is modified: <�޸�ԭ������> */ package cn.edu.hit.education.service; @@ -25,12 +25,6 @@ import cn.edu.hit.education.dao.PropertyMapper; import cn.edu.hit.education.pojo.Property; import cn.edu.hit.education.pojo.PropertyExample; -/** - *

classname PropertyServiceImpl

- *

description TODO

- *

author ѩ jinxuesong@163.com

- *

date 2021421 4:39:13

- */ @Service public class PropertyServiceImpl implements IPropertyService { @@ -39,25 +33,21 @@ public class PropertyServiceImpl implements IPropertyService { @Override public int insert(Property property) { - // TODO Զɵķ return propertyMapper.insert(property); } @Override public int deleteByPrimaryKey(int id) { - // TODO Զɵķ return propertyMapper.deleteByPrimaryKey(id); } @Override public int update(Property property) { - // TODO Զɵķ return propertyMapper.updateByPrimaryKey(property); } @Override public List queryAllProperty() { - // TODO Զɵķ PropertyExample example = new PropertyExample(); PropertyExample.Criteria criteria = example.createCriteria(); criteria.andIdGreaterThan(0); @@ -67,7 +57,6 @@ public class PropertyServiceImpl implements IPropertyService { @Override public List queryPropertiesByProcessId(int processId) { - // TODO Զɵķ PropertyExample example = new PropertyExample(); PropertyExample.Criteria criteria = example.createCriteria(); criteria.andProcessIdEqualTo(processId); @@ -77,7 +66,6 @@ public class PropertyServiceImpl implements IPropertyService { @Override public void clearPropertyNum() { - // TODO Զɵķ List properties = queryAllProperty(); if(properties != null && properties.size() > 0){ for (Property property : properties) { @@ -90,7 +78,12 @@ public class PropertyServiceImpl implements IPropertyService { @Override public Property queryPropertyById(int id) { - // TODO Զɵķ + return propertyMapper.selectByPrimaryKey(id); + } + + @Override + public Property queryPropertyByPrimaryKey(int id) { + // TODO 自动生成的方法存根 return propertyMapper.selectByPrimaryKey(id); } diff --git a/src/cn/edu/hit/education/view/CourseExploreView.java b/src/cn/edu/hit/education/view/CourseExploreView.java index 6c46e76..d4a6baa 100644 --- a/src/cn/edu/hit/education/view/CourseExploreView.java +++ b/src/cn/edu/hit/education/view/CourseExploreView.java @@ -1,7 +1,11 @@ package cn.edu.hit.education.view; +import org.eclipse.jface.action.IMenuListener; +import org.eclipse.jface.action.IMenuManager; +import org.eclipse.jface.action.MenuManager; import org.eclipse.jface.util.LocalSelectionTransfer; +import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.TreeViewer; import org.eclipse.swt.SWT; import org.eclipse.swt.dnd.DND; @@ -10,65 +14,56 @@ import org.eclipse.swt.dnd.Transfer; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Menu; import org.eclipse.swt.widgets.Tree; import org.eclipse.swt.widgets.TreeItem; import org.eclipse.ui.part.ViewPart; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import cn.edu.hit.education.action.AddCourseAction; +import cn.edu.hit.education.action.AddProcessAction; +import cn.edu.hit.education.action.AddPropertyAction; +import cn.edu.hit.education.action.UpdateCourseAction; +import cn.edu.hit.education.action.UpdateProcessAction; +import cn.edu.hit.education.action.UpdatePropertyAction; import cn.edu.hit.education.contentprovider.CourseContentProvider; import cn.edu.hit.education.labelprovider.CourseLabelProvider; import cn.edu.hit.education.listener.CourseDragSourceListener; import cn.edu.hit.education.model.CourseNode; import cn.edu.hit.education.model.CourseRootNode; import cn.edu.hit.education.model.Node; -import cn.edu.hit.education.pojo.Semester; -import cn.edu.hit.education.pojo.Specialty; +import cn.edu.hit.education.model.ProcessNode; +import cn.edu.hit.education.model.PropertyNode; +import cn.edu.hit.education.model.ResourceNode; +import cn.edu.hit.education.pojo.Course; +import cn.edu.hit.education.pojo.Process; +import cn.edu.hit.education.pojo.Property; import cn.edu.hit.education.service.ICourseService; +import cn.edu.hit.education.service.IProcessService; import cn.edu.hit.education.service.IScheduleService; import cn.edu.hit.education.service.ISemesterService; -import cn.edu.hit.education.service.ISpecialtyService; -import cn.edu.hit.education.service.IUniversityService; -/** -*@Title: CourseExploreView -*@Description:课程View -*@author:李朝辉 -*@data:2021年4月29日午夜11:54 -* -* -*/ - @Component public class CourseExploreView extends ViewPart { @Autowired - IUniversityService universityService; + IProcessService processService; @Autowired ICourseService courseService; @Autowired IScheduleService scheduleService; @Autowired ISemesterService semesterService; - @Autowired - ISpecialtyService specialtyService; - - public static final String ID = "cn.edu.hit.education.view.CourseExploreView"; final Transfer[] transfer=new Transfer[]{LocalSelectionTransfer.getTransfer()}; final Transfer[] transfer2=new Transfer[] {TextTransfer.getInstance()}; private TreeViewer treeViewer; private Tree tree; - private Semester semester; - private Specialty specialty; - private CourseNode courseNode ; - - - - + private Node currentNode; + public CourseExploreView() { - } public void createPartControl(Composite parent) { @@ -87,8 +82,7 @@ public class CourseExploreView extends ViewPart { TreeItem selections = (TreeItem)e.item; Node node = (Node)selections.getData(); if(node instanceof CourseNode){ - courseNode = (CourseNode)node; - System.out.println("所选课程ID: "+courseNode.getId()); + currentNode = (CourseNode)node; } } }); @@ -124,11 +118,43 @@ public class CourseExploreView extends ViewPart { } });*/ - //createContextMenu(parent); - - + makeContextMenu(); } + private void makeContextMenu() { + MenuManager menuMgr = new MenuManager(); + + Menu menu = menuMgr.createContextMenu(treeViewer.getControl()); + menuMgr.addMenuListener(new IMenuListener() { + @Override + public void menuAboutToShow(IMenuManager manager) { + if (treeViewer.getSelection().isEmpty()) { + return; + } + + if (treeViewer.getSelection() instanceof IStructuredSelection) { + IStructuredSelection selection = (IStructuredSelection) treeViewer.getSelection(); + currentNode = (Node)selection.getFirstElement(); + + if(currentNode instanceof ResourceNode){ + menuMgr.add(new AddProcessAction(CourseExploreView.this)); + }else if(currentNode instanceof ProcessNode){ + menuMgr.add(new AddPropertyAction(CourseExploreView.this,currentNode.getId())); + menuMgr.add(new UpdateProcessAction(CourseExploreView.this,currentNode.getId())); + }else if(currentNode instanceof PropertyNode){ + menuMgr.add(new AddCourseAction(CourseExploreView.this,currentNode.getId())); + menuMgr.add(new UpdatePropertyAction(CourseExploreView.this,currentNode.getId())); + }else{ + menuMgr.add(new UpdateCourseAction(CourseExploreView.this,currentNode.getId())); + } + } + } + }); + menuMgr.setRemoveAllWhenShown(true); + treeViewer.getControl().setMenu(menu); + + } + /** * Passing the focus request to the viewer's control. */ @@ -137,10 +163,41 @@ public class CourseExploreView extends ViewPart { } public void refreshNewData(Object obj){ + if(obj instanceof Process){ + Process process = (Process)obj; + ProcessNode processNode = new ProcessNode(process.getId(),process.getName()); + currentNode.addChild(processNode); + }else if(obj instanceof Property){ + Property property = (Property)obj; + PropertyNode propertyNode = new PropertyNode(property.getId(),property.getName()); + currentNode.addChild(propertyNode); + }else if(obj instanceof Course){ + Course course = (Course)obj; + CourseNode courseNode = new CourseNode(course.getId(),course.getName()); + currentNode.addChild(courseNode); + }else{ + + } + treeViewer.refresh(currentNode,true); + treeViewer.setExpandedState(currentNode, true); } public void refreshUpdateData(Object obj){ + if(obj instanceof Process){ + Process process = (Process)obj; + currentNode.setName(process.getName()); + }else if(obj instanceof Property){ + Property property = (Property)obj; + currentNode.setName(property.getName()); + }else if(obj instanceof Course){ + Course course = (Course)obj; + currentNode.setName(course.getName()); + }else{ + + } + treeViewer.refresh(currentNode,true); + treeViewer.setExpandedState(currentNode, true); } } -- Gitee From 1df10e7980b6ffb20f10fecc1c09ecd53ab4b157 Mon Sep 17 00:00:00 2001 From: jinxuesong Date: Wed, 12 May 2021 09:28:52 +0800 Subject: [PATCH 2/2] Update --- .../education/action/UpdateCourseAction.java | 46 +++++++++++++++++++ .../education/action/UpdateProcessAction.java | 46 +++++++++++++++++++ .../action/UpdatePropertyAction.java | 46 +++++++++++++++++++ .../edu/hit/education/model/ResourceNode.java | 10 ++++ 4 files changed, 148 insertions(+) create mode 100644 src/cn/edu/hit/education/action/UpdateCourseAction.java create mode 100644 src/cn/edu/hit/education/action/UpdateProcessAction.java create mode 100644 src/cn/edu/hit/education/action/UpdatePropertyAction.java create mode 100644 src/cn/edu/hit/education/model/ResourceNode.java diff --git a/src/cn/edu/hit/education/action/UpdateCourseAction.java b/src/cn/edu/hit/education/action/UpdateCourseAction.java new file mode 100644 index 0000000..645a65d --- /dev/null +++ b/src/cn/edu/hit/education/action/UpdateCourseAction.java @@ -0,0 +1,46 @@ +package cn.edu.hit.education.action; + +import org.eclipse.jface.action.Action; +import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.plugin.AbstractUIPlugin; + +import cn.edu.hit.education.dialog.CourseDialog; +import cn.edu.hit.education.pojo.Course; +import cn.edu.hit.education.service.ICourseService; +import cn.edu.hit.education.view.CourseExploreView; +import educationschedule.Activator; +import educationschedule.Application; + +public class UpdateCourseAction extends Action { + private CourseExploreView viewPart; + ICourseService courseService = (ICourseService)Application.applicationContext.getBean("courseServiceImpl"); + private int courseId; + + public UpdateCourseAction(CourseExploreView viewPart,int courseId){ + this.setImageDescriptor(AbstractUIPlugin.imageDescriptorFromPlugin(Activator.PLUGIN_ID, "icons/toolbar/course_code_16px.png")); + this.setToolTipText("修改课程"); + this.setText("修改课程"); + this.viewPart = viewPart; + this.courseId = courseId; + } + + @Override + public void run() { + Shell parentShell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); + CourseDialog courseDialog = new CourseDialog(parentShell); + Course course = courseService.queryCourseByPrimaryKey(courseId); + courseDialog.setCourse(course); + if(IDialogConstants.OK_ID == courseDialog.open()){ + int count = courseService.update(course); + if(count > 0){ + viewPart.refreshUpdateData(course); + } + } + super.run(); + } + + + +} diff --git a/src/cn/edu/hit/education/action/UpdateProcessAction.java b/src/cn/edu/hit/education/action/UpdateProcessAction.java new file mode 100644 index 0000000..9654d01 --- /dev/null +++ b/src/cn/edu/hit/education/action/UpdateProcessAction.java @@ -0,0 +1,46 @@ +package cn.edu.hit.education.action; + +import org.eclipse.jface.action.Action; +import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.plugin.AbstractUIPlugin; + +import cn.edu.hit.education.dialog.ProcessDialog; +import cn.edu.hit.education.pojo.Process; +import cn.edu.hit.education.service.IProcessService; +import cn.edu.hit.education.view.CourseExploreView; +import educationschedule.Activator; +import educationschedule.Application; + +public class UpdateProcessAction extends Action { + private CourseExploreView viewPart; + IProcessService processService = (IProcessService)Application.applicationContext.getBean("processServiceImpl"); + private int processId; + + public UpdateProcessAction(CourseExploreView viewPart,int processId){ + this.setImageDescriptor(AbstractUIPlugin.imageDescriptorFromPlugin(Activator.PLUGIN_ID, "icons/toolbar/course_code_16px.png")); + this.setToolTipText("修改过程"); + this.setText("修改过程"); + this.viewPart = viewPart; + this.processId = processId; + } + + @Override + public void run() { + Shell parentShell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); + ProcessDialog processDialog = new ProcessDialog(parentShell); + Process process = processService.queryProcessByPrimaryKey(processId); + processDialog.setProcess(process); + if(IDialogConstants.OK_ID == processDialog.open()){ + int count = processService.update(process); + if(count > 0){ + viewPart.refreshUpdateData(process); + } + } + super.run(); + } + + + +} diff --git a/src/cn/edu/hit/education/action/UpdatePropertyAction.java b/src/cn/edu/hit/education/action/UpdatePropertyAction.java new file mode 100644 index 0000000..faed264 --- /dev/null +++ b/src/cn/edu/hit/education/action/UpdatePropertyAction.java @@ -0,0 +1,46 @@ +package cn.edu.hit.education.action; + +import org.eclipse.jface.action.Action; +import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.plugin.AbstractUIPlugin; + +import cn.edu.hit.education.dialog.PropertyDialog; +import cn.edu.hit.education.pojo.Property; +import cn.edu.hit.education.service.IPropertyService; +import cn.edu.hit.education.view.CourseExploreView; +import educationschedule.Activator; +import educationschedule.Application; + +public class UpdatePropertyAction extends Action { + private CourseExploreView viewPart; + IPropertyService propertyService = (IPropertyService)Application.applicationContext.getBean("propertyServiceImpl"); + private int propertyId; + + public UpdatePropertyAction(CourseExploreView viewPart,int propertyId){ + this.setImageDescriptor(AbstractUIPlugin.imageDescriptorFromPlugin(Activator.PLUGIN_ID, "icons/toolbar/course_code_16px.png")); + this.setToolTipText("修改性质"); + this.setText("修改性质"); + this.viewPart = viewPart; + this.propertyId = propertyId; + } + + @Override + public void run() { + Shell parentShell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); + PropertyDialog propertyDialog = new PropertyDialog(parentShell); + Property property = propertyService.queryPropertyByPrimaryKey(propertyId); + propertyDialog.setProperty(property); + if(IDialogConstants.OK_ID == propertyDialog.open()){ + int count = propertyService.update(property); + if(count > 0){ + viewPart.refreshUpdateData(property); + } + } + super.run(); + } + + + +} diff --git a/src/cn/edu/hit/education/model/ResourceNode.java b/src/cn/edu/hit/education/model/ResourceNode.java new file mode 100644 index 0000000..ead0132 --- /dev/null +++ b/src/cn/edu/hit/education/model/ResourceNode.java @@ -0,0 +1,10 @@ +package cn.edu.hit.education.model; + +public class ResourceNode extends Node { + + public ResourceNode(int id, String name) { + super(id, name); + // TODO Auto-generated constructor stub + } + +} -- Gitee